Bash kezdő

Sziasztok,

Van az alábbi scriptem:
https://pastebin.com/C19QWMEc

Úgy ahogy működik is, viszont van egy idegesitő hibája.

Ha a nemet választom, akkor nincs semmi gond:
neut@preshaz:/var/spool/MailScanner/quarantine/test# ./test.sh
I found 112 spams
Size of spams: 1.1M total
Do you want to delete ALL spams? [Yes/No] n
We didn't delete anything

neut@preshaz:/var/spool/MailScanner/quarantine/test# ./test.sh
I found 112 spams
Size of spams: 1.1M total
Do you want to delete ALL spams? [Yes/No] y
find: `./20170101/spam/7C2FCAC131.AAA20': No such file or directory
find: `./20170101/spam/C2320AC131.AA724': No such file or directory
find: `./20170101/spam/F1D18AC130.A9D80': No such file or directory
find: `./20170101/spam/968BCABFFB.A3419': No such file or directory
find: `./20170101/spam/7E0BAAC131.AFA06': No such file or directory
find: `./20170101/spam/1EFDBAC131.AFE16': No such file or directory
find: `./20170101/spam/8F6C3ABFFB.A2A7D': No such file or directory
find: `./20170101/spam/4756AAC131.AABF0': No such file or directory
find: `./20170101/spam/CCD4DAC131.A9992': No such file or directory
find: `./20170101/spam/A2EE9AC135.A9692': No such file or directory
find: `./20170101/spam/539B9AC131.AB474': No such file or directory
find: `./20170101/spam/2607DAC131.A8FA3': No such file or directory
find: `./20170101/spam/94448AC131.AD8F1': No such file or directory
find: `./20170101/spam/D2823AC131.AE86E': No such file or directory
Spams executed

A törlés lefut csak dobja a find az error-t.... A furcsasága hogy csak az első mappa összes elemére dobja ezt a hibát. Mit rontottam el?

Köszi.

Hozzászólások

Nem jobb így?

find ./*/spam/* -type f -exec rm -rf {} +

--

"After successfully ignoring Google, FAQ's, the board search and leaving a undecipherable post in the wrong sub-forum don't expect an intelligent reply."

Eredeti sorod vs enyém
find ./*/spam/ -type f -exec rm -rf ./*/spam/* {} \;

find ./*/spam/* -type f -exec rm -rf {} +

Egyrészt ugye vagy egy csillag az első útvonal végén, ez mondjuk lehet nem számít ebben az esetben.

Másrészt mivel kapsz egy filelistát találatnak, ezért nem kell külön megadni az rm-nek az útvonalat.

Te arra utasítottad a te verzióddal, hogy törölje a "./*/spam/*" fileokat ÉS a find találatait {}.
Ezért az rm először letörölte a ./*/spam/* fileokat, majd mivel a find paraméterként ugyanezt megkapta, megpróbálta mégegyszer letörölni, erre jött a No such file...

Harmadrészt a + miatt egy rm van az összes talált file-lal paraméternek, de ez itt nem nagyon számít csak én így szoktam :) a különbséget lásd lent:

-exec command ;
Execute command; true if 0 status is returned. All following arguments
to find are taken to be arguments to the command until an argument
consisting of ‘;’ is encountered. The string ‘{}’ is replaced by the
current file name being processed everywhere it occurs in the arguments
to the command, not just in arguments where it is alone, as in
some versions of find. Both of these constructions might need to be escaped
(with a ‘\’) or quoted to protect them from expansion by the shell.
See the EXAMPLES section for examples of the use of the -exec option.
The specified command is run once for each matched file. The
command is executed in the starting directory. There are unavoidable security
problems surrounding use of the -exec action; you should use the -execdir
option instead.

-exec command {} +
This variant of the -exec action runs the specified command on the
selected files, but the command line is built by appending each selected
file name at the end; the total number of invocations of the command
will be much less than the number of matched files. The command line is
built in much the same way that xargs builds its command lines.
Only one instance of ‘{}’ is allowed within the command. The command is
executed in the starting directory

--

"After successfully ignoring Google, FAQ's, the board search and leaving a undecipherable post in the wrong sub-forum don't expect an intelligent reply."

Nem annyira ismerem a find-ot, de olyasmire tippelek, hogy a find amikor először hívja az rm-et, az abban lévő globbing miatt törlődik az összes file. Aztán, mivel a find megtalálta még törlés előtt a második, harmadik, stb. file-okat is, azzal is hívja az rm-et, de az első alkalommal már törölve lettek, így nincs file, amit lehetne törölni, illetve amit paraméterül át lehetne adni az rm-nek. Szerintem a find argumentumában lévő rm-ben a csillag globbing nincs rendben, hiszen a find majd tételesen hívja az általa megtalált file-ok listájával az rm-et.

tr '[:lower:]' '[:upper:]' <<<locsemege
LOCSEMEGE

A find-os hibat mar megfejtettek elottem, ugyhogy en az elso ket soron tisztogatnek egy kicsit. Ezeken:


find ./*/spam/ -type f | echo "I found " `wc -l` "spams" \;
du -shc ./*/spam/* | echo "Size of spams:" `grep total`

A pipe-ot az echo ele kivinni teljesen felesleges es bar mukodik eleg zagyvava teszi a kepet, igy kicsit szebb:


echo "I found " `find ./*/spam/ -type f | wc -l` "spams" \;
echo "Size of spams:" `du -shc ./*/spam/* | grep total`

De en meg jobban szeretem a zarojelezest a backtick helyett, beszedesebb is, meg meg egymasba is agyazhato (szukseg eseten). Es az idezojel ki/becsukas is szuksegtelen, dupla idezojelen belul megtortennek a kiertekelesek:


echo "I found $(find ./*/spam/ -type f | wc -l) spams"
echo "Size of spams: $(du -shc ./*/spam/* | grep total)"

Az "if [[ $response..." meg talan igy egyszerubb:


if echo $response | grep -qxi "yes"

(a "q" tol nem lesz kimenete, az "i" tol nem lesz case sensitive, az x meg teljes sort illeszt, bar szerintem az nem is fontos ide)

Elővettem a bibliát: DMOS (*) Operátori kézikönyv I. kötet 1. kiadás 1987 március. És mit ad isten ezt találom benne a grep oldalán:

-x Csak azokat a sorokat írja ki, amelyek teljes egészükben megegyeznek a mintával (csak fgrep-nél)

Kiemelés tőlem. Szóval megjegyzésemet visszavonom, hamut szórok a fejemre, hogy még ezt az ezer éves alapvető opciót se tudtam, de ebben az esetben tessen javítni a grep-et fgrep-re :-)

Mondjuk a neten található HP-UX man szerint az is ismeri és nem korlátozza fix sztringre, mert még szerepel is a leírásban, hogy "fixed string or regexp". Hasonlóan a Solaris és AIX manualok is ismerik, szóval visszavonok mindent.

(*) A DMOS a Videoton VT-32 családra készült UNIX-klónja.

=====
tl;dr
Egy-két mondatban leírnátok, hogy lehet ellopni egy bitcoin-t?