“find” command can be very useful when it comes to locating files to remove when a filesystem is full. There are various options in find command to locate as well as remove the files consuming more space on the filesystem. Below are some of the find command examples, to locate files in various scenarios.
1. Here is the syntax to find files that are greater in size than 1 MB in the current directory:
# find . -size +1000000c -exec ls -l {} +
The -mount option to the find command can be used to restrict the search to the filesystem containing the directory specified. For example, it is not recommended to run find on /proc. Instead use:
# find / -mount
2. To find files generated by NFS and remove them if they are older than seven days:
# find / -name .nfs\* -mtime +7 -exec rm -f {} + -o -fstype nfs -prune
3. To search for core files starting at the root directory and delete them:
# find / -name core -exec rm {} +
4. To search for core files that have not been accessed in seven days and display them to the screen:
# find / -name core -atime +7 -print
5. To identify all files owned by a particular user and send a long listing of these files to the superuser:
# find / -user -ls | mailx -s "users files" root@hostname
6. Look for files that have not been modified in 90 days in the /home directory:
# find /home -mtime +90 -print
7. To find files that are greater than 400 blocks (512-byte blocks) and display the matching path names:
# find /home -size +400 -print