Home > Net >  bash: removing many files of the same extension
bash: removing many files of the same extension

Time:04-20

I am dealing with the folder consisted of many log filles. I have to remove all of them using bash. My version using rm does not work:

rm "${results}"/*.log 

that gives me:

./dolche_vita.sh: line 273: /usr/bin/rm: Argument list too long

CodePudding user response:

This means, there are so many .log files in that directory, that the argument list for the rm call gets too long. (The *.log gets expanded to file1.log, file2.log, file3.log, ... during the "real" rm call and there's a limit for the length of this argument line.)

A quick solution could be using find, like this:

find ${results}/ -type f -name '.log' -delete

Here, the find command will list all files (-type f) in your ${results} dir, ending with .log (because of -name '.log') and delete them because you issue -delete as last parameter.

  • Related