1

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

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-08_02-39-14.Z_2017-Feb-09_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-13_02-39-08.Z_2017-Feb-16_02-39-05.Z_2017-Feb-18_02-39-3.Z_2017-Feb-20_02-39-02.Z_2017-Mar-02_12-06-57

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-08_02-39-14.Z_2017-Feb-09_02-39-14.Z_2017-Feb-16_02-39-05.Z_2017-Feb-18_02-39-03.Z_2017-Feb-19_02-39-03.Z_2017-Feb-20_02-39-2.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-09_02-39-14.Z_2017-Feb-12_02-39-10.Z_2017-Feb-15_02-39-06.Z_2017-Feb-16_02-39-05.Z_2017-Feb-17_02-39-04.Z_2017-Feb-19_02-39-3.Z_2017-Feb-20_02-39-02.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-10_02-39-12.Z_2017-Feb-15_02-39-06.Z_2017-Feb-18_02-39-03.Z_2017-Feb-19_02-39-03.Z_2017-Feb-20_02-39-02.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-07_02-39-15.Z_2017-Feb-10_02-39-12.Z_2017-Feb-19_02-39-03.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-08_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-12_02-39-10.Z_2017-Feb-14_02-39-07.Z_2017-Feb-15_02-39-06.Z_2017-Feb-17_02-39-4.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

esymac_logEvents.log.6_2017-Feb-09_02-39-14.Z_2017-Feb-13_02-39-08.Z_2017-Feb-17_02-39-04.Z_2017-Feb-19_02-39-03.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-08_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-12_02-39-10.Z_2017-Feb-14_02-39-07.Z_2017-Feb-15_02-39-06.Z_2017-Feb-17_02-39-04.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

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)

Cheers.

2 Answers2

0
find /search/dir -name esymac*whatever*pattern* -exec rm \{\} \;
Philippos
  • 13,453
0

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

Raman Kathpalia
  • 549
  • 1
  • 7
  • 15