I am looking for a linux command to get all the files exceeding a certain size from the current directory and its sub-directories.
Whats the easiest way to delete all these files?

- 5,753
- 72
- 57
- 129

- 3,455
- 12
- 47
- 60
-
Also see [How can I find files that are bigger/smaller than x bytes?](http://superuser.com/q/204564/173513) on Super User. – jww Feb 07 '17 at 22:53
4 Answers
Similar to the exec rm answer, but doesn't need a process for each found file:
find . -size +100k -delete

- 88,732
- 13
- 198
- 189
One-liner:
find . -size +100k -exec rm {} \;
The first part (find . -size +100k
) looks for all the files starting from current directory (.
) exceeding (+
) 100 kBytes (100k
).
The second part (-exec rm {} \;
) invoked given command on every found file. {}
is a placeholder for current file name, including path. \;
just marks end of the command.
Remember to always check whether your filtering criteria are proper by running raw find
:
find . -size +100k
Or, you might even make a backup copy before deleting:
find . -size +100k -exec cp --parents {} ~/backup \;

- 334,321
- 69
- 703
- 674
-
"Remember to always check whether your filtering criteria are proper by running raw find" was very useful (can't be too careful with the unforgiving `rm` in Linux!), so I'm upvoting this. – warship Jul 31 '17 at 23:03
python is installed on all unix based OS, so why not use it instead of bash ?
I always find python more readable than awk
and sed
magic.
This is the python code I would have written:
import os
Kb = 1024 # Kilo byte is 1024 bytes
Mb = Kb*Kb
Gb = Kb*Kb*Kb
for f in os.listdir("."):
if os.stat(f).st_size>100*Kb:
os.remove(f)
And this is the one-liner version with python -c
python -c "import os; [os.remove(f) for f in os.listdir('.') if os.stat(f).st_size>100*1024]"
And if you want to apply the search recursively, see this
In zsh:
ls -l *(Lk+100) # list file size greater than 100kb
so:
rm *(Lk+100)
More zsh goodness here.

- 268,207
- 37
- 334
- 440
-
This is not recursive. Use `**/*(.Lk+100)` #The dot exclude directories, whose size is irrelevant (and spurious when seeking for small files). – YvesgereY Jan 07 '14 at 19:23