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?
Navigate to the folder that you want to delete (with all its files and subfolders). Use cd *path*, for example, cd C:\Trash\Files\ to do so. Use cd .. to navigate to the parent folder and run the command RMDIR /Q/S *foldername* to delete the folder and all of its subfolders.
1. Empty or delete the contents of a large file using the truncate command in the Linux/Unix system. The truncate command is used to shrink or extend the size of a file to a specified size in the Linux system. It is also used to empty large file contents by using the -s option followed by 0 (zero) specified size.
Similar to the exec rm answer, but doesn't need a process for each found file:
find . -size +100k -delete
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 \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With