I need to delete all files with a .avi
expansion and whose size is below 100MB. I have a large collection of video files and I need to delete the short ones to free up some space. How do I accomplish this ?
Use the find
command:
find /path/to/ -name '*.avi' -type f -size -100M -delete
Details:
/path/to/
This tells find to look for files in the
/path/to/
directory and all its subdirectories. If you want to start from the current directory, use.
instead.-name '*.avi'
This tells
find
to only look for files whose names end in.avi
-type f
This tells
find
to only look for regular files. This excludes directories, pipes, sockets, etc.-size -100M
This tells
find
to only look for files smaller than 100MB. If you wanted to delete files larger than 100MB, then use+100M
instead.-delete
This tells
find
to delete the files matching the above criteria.
For safety, the first time you try this command, leave off the -delete
. This will return a list of files found:
find /path/to/ -name '*.avi' -type f -size -100M
If the files found are the ones that you want to delete, then add back -delete
.
Searching only the current directory and not its subdirectories
To limit recursion find into subdirectories, use the -maxdepth
option:
find /path/to/ -maxdepth 1 -name '*.avi' -type f -size -100M -delete
To perform the above on the current directory:
find . -maxdepth 1 -name '*.avi' -type f -size -100M -delete
-
How do I do if I want it to look only in the current directory and not look recursively into the subdirectories ? – Chintan Oct 29 '14 at 6:47
-
1
-