Show Menu
Cheatography

find Cheat Sheet (DRAFT) by

Linux find command searches the directory tree for each given file name by evaluating the expression according to the rules of precedence. Find command usage will be helpful for Linux/Unix System Administrators.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic commands

How to find files containing a specific word in its name?
find /etc -name "mail"
How to find all the files greater than certain size?
find / -type f -size +100M
How to find files that are not modified in the last x number of days?
find . -mtime +60
How to find files that are modified in the last x number of days?
find . –mtime -2
How to delete all the archive files with extension *.tar.gz and greater than 100MB?
find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
 
find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;
How to archive all the files that are not modified in the last x number of days?
find /home/­jsmith -type f -mtime +60 | xargs tar -cvf /tmp/
date '+%d%m­%Y'­_ar­chi­ve.tar
Find files larger than 10MB in the current directory downwards…
find . -size +10000000c -ls
Find files larger than 100MB…
find . -size +10000­0000c -ls
Find files last modified over 30days ago…
find . -type f -mtime 30 -ls
Find files last modified over 365days ago…
find . -type f -mtime 365 -ls
 

Search by date/time

How to find files that are not modified in the last x number of days?
find . -mtime +60
How to find files that are modified in the last x number of days?
find . –mtime -2
How to archive all the files that are not modified in the last x number of days?
find /home/­jsmith -type f -mtime +60 | xargs tar -cvf /tmp/
date '+%d%m­%Y'­_ar­chi­ve.tar
Find files last modified over 30days ago…
find . -type f -mtime 30 -ls
Find files last accessed over 30days ago…
find . -type f -atime 30 -ls
If the file is being updated at the current time then we can use find to find files modified in the last day…
find . -type f -mtime -1 -ls
#Find files whose content got updated within last 1 hour
find . -mmin -60
finds all the files (under root file system /) that got updated within the last 24 hours (1 day).
find / -mtime -1
Find files which got accessed before 1 hour
find -amin -60
Find files which got changed exactly before 1 hour
find . -cmin -60

Find by size

Find files bigger than the given size
find / -type f -size +100M
Find files larger than 10MB in the current directory downwards…
find . -type f -size +10M -ls
, in order, the largest sub-di­rec­tories (units are in Kb)…
du -sk * | sort -n
How to find all the files greater than certain size?
find / -type f -size +100M
Find files smaller than the given size
find / -type f -size -100M
Find files that matches the exact given size
find / -type f -size 100M
How to delete all the archive files with extension *.tar.gz and greater than 100MB?
find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
 
find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;
The following command will display the top 5 largest file in the current directory and its subdir­ectory. This may take a while to execute depending on the total number of files the command has to process.
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Technique is same as finding the bigger files, but the only difference the sort is ascending order.
find . -type f -exec ls -s {} \; | sort -n | head -5
List the smaller files other than the ZERO byte files.
find . -not -empty -type f -exec ls -s {} \; | sort -n | head -5

Find by permis­sions