In a previous post, I discuss a couple of approaches to dealing with the "Argument list too long" error when transferring large numbers of files. The solution to this problem is to archive the files, using the "-T" option of the "tar" command to pass in a list files generated by a "find" command:
- Create a list of the files to be archived using the "
find" command:
$ find . -name="*.tre" > filelist.txt
- Use the "
-T" option of the "tar" command to pass in this list of filenames:
$ tar cvjf archive.tbz -T filelist.txt
If you want to delete a long list of files, however, this approach will not work, as "rm" does not support the very convenient "-T"/"--files-from" flag or the equivalent (so convenient, in fact, that I have started adding this to virtually every file-processing script or program that I write).
Luckily, however, "find" does support a "-delete" flag, so to recursively delete all files and directories: