I have a very large number of files to delete, which go by the following format:









I want to delete them, but the rm() command gives me the 'Argument list too large' error. Couldn't formulate myself a command after checking similar posts, is there any way I could get a command that would:

  • first create argument list with all esymac_logEvents.log.* files,
  • remove the files one by one, with a loop or exec command (maybe not
    one at atime, it would be preferable to remove the max number of arguments rm() function can receive)


  • Are there files in this directory you need to keep ? What is the criteria for selecting the files to remove, or is this the whole list? – X Tian Mar 6 '17 at 16:42
  • Possibly a diuplicate: stackoverflow.com/questions/11289551/… – Valentin Bajrami Mar 6 '17 at 16:45
  • @Xtian I want to keep all files that differ from that format. – EXHALEXHALE Mar 6 '17 at 16:57
find /search/dir -name esymac*whatever*pattern* -exec rm \{\} \;
  • What is the difference between: -exec rm \{\} \; -exec rm {} \; – EXHALEXHALE Mar 6 '17 at 16:59
  • Depending on your shell you have to escape the braces. Now did the command work for you? – Philippos Mar 6 '17 at 17:08

Since you want to keep all files that differ from the format mentioned, do:

  1. Execute this. This will populate FilesToDelete.txt with files/dir to be deleted. Review this to make sure that files listed in are indeed the files you intend to delete.

    find /path/to/dir/esymac_logEvents.log* | xargs ls -l > FilesToDelete.txt

  2. Once you verify the Step-1, do

    find /path/to/dir/esymac_logEvents.log* -type f | xargs rm -f

  3. If directories are involved as well that needs to be deleted, Skip 2 and do this instead:

    find /dir/that/contains/esymac_logEvents.log* | xargs rm -rf

Not the answer you're looking for? Browse other questions tagged or ask your own question.