find & xargs
If you have a lot of files in a single folder or if your files are in various subfolders, then the usual usage of wildcards soon comes to its limit. Argumentlist too long is a common error then as well as accidentially deleted files when doing a rm -rf */x*/200*/0*/*.
This is the arena of find and xargs.
find searches the actual folder or all subfolders for files with specific names, creationdate, size ... whatever. Or just lists all files, no matter how much there are. There is no too long argument-list
xargs performs a certain command on each file that it gets as input. xargs is smart enough to optimize the usage of this command.
Together find & xargs are a very powerful swiss army-knife for filemanagment. Compareable to tools like formail and procmail for mail-processing. And even simpler to use.
find . -type f -maxdepth 1 | xargs rm -f .. delete all files in current folder
find . -type f | xargs ls -l ... list all files in current folder and all subfolders
find . -type f -print0 | xargs -0 ls -l ... das gleiche, aber leerzeichen im namen sind kein problem
find . -type f -print0 | xargs -0i mv "{}" /tmp/"{}".tmp ... move all files to /tmp and add the suffix tmp
und hier was ganz grosses : checke alle mails in einem cyrus-imapd auf spam:
find . -iname "*." -type f -print0 | xargs -P 500 -0ti bash -c "cat \"{}\" | spamc > /tmp/\$\$ ; mv -vf /tmp/\$\$ \"{}\"" &
Wir parallelisieren mit -P und verwenden die bash als container für unser doppelkommando mit der pipe und die variable $$ (PID der aktuell geforkten bash) als eindeutigen namen für unsere tempfiles.



