0

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
James Starlight
  • 317
  • 1
  • 6
  • BTW: You're not even asking a question but asking the right question is key to solving your problems! Please, as a new user here, read [ask] and take the [tour]. – Ulrich Eckhardt Apr 19 '22 at 08:29

1 Answers1

3

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.

ahuemmer
  • 1,653
  • 9
  • 22
  • 29
  • Thanks! I guess it should be find folder -type f -name '*.log' -delete – James Starlight Apr 19 '22 at 08:31
  • 1
    Note to the OP: run `find` *without* `-delete` and check the output before you add the switch in. It's too easy to construct `find` calls which pull in more than you thought they did (prob not relevant with an invocation this simply, but there's still the possibility of a typo). – 2e0byo Apr 19 '22 at 08:49