Linux Find Cheat Sheet

in Linux

Find is a very handy tool in Linux when looking for specific files and folders with required conditions. The following are some examples of how you can use find to get the job done.

Find all folders named pipot in the current folder.

find . -type d -name "pipot"

Find all files with names starting with linux in the /home folder.

find /home -type f -name "linux*"

Find all files owned by user ween in the /home folder.

find /home -user ween

Find all files belonging to group ween in the /home folder.

find /home -group ween

Find all files belonging to user ween and chmod to 644 in the /home folder.

find /home -user ween -type f -exec chmod 644 {} \;

Find all files *.tmp in /tmp and remove them

find /tmp -name "*.tmp" -delete

See result of find syntax first before doing anything else

find /tmp -name "*.tmp" -ls

Find all files newer than March 15, 2016

find -newermt "mar 15, 2016" -ls

Find all files older than March 15, 2016

find -not -newermt "mar 15, 2016" -ls

Find all files between Jan 1, 2016 and Jan 30, 2016.

find -newermt "jan 01, 2016" -not -newermt "jan 30, 2016" -name "*.php" -ls

To find out more about using find and its features check out this man page from man7.org or this man page from gnu.org.

 

Leave a Comment

Previous post:

Next post: