paul.maddox
May 9th, 2006, 01:44 PM
I'm trying to write a quick bash script to delete all files in a directory under a certain filesize (say for example 1MB).
Has anyone got any good ways of getting that list of files?
I've checked the list of bash test operators and can't find anything about filesizes apart from one to check if it's bigger than 0bytes.
So far the best I can think of is looping through all files in the directory, then running ls -s on them to get the filesize, parse that and then compare to see if it's bigger/smaller than 1MB.
Is there a much nicer way of doing it? There must be!
Has anyone got any good ways of getting that list of files?
I've checked the list of bash test operators and can't find anything about filesizes apart from one to check if it's bigger than 0bytes.
So far the best I can think of is looping through all files in the directory, then running ls -s on them to get the filesize, parse that and then compare to see if it's bigger/smaller than 1MB.
Is there a much nicer way of doing it? There must be!