find Commands Cheat Sheet

• Updated November 24, 2016


find is an extremely powerful command. It not only finds your files and directories, it can be combined with other shell commands to perform actions on those found files and directories.

This post will be an ever growing list of find command one liners I have found useful.

Recursively find all files in current directory and chmod them to 644

find . -type f -exec chmod 644 {} \;

Recursively find all directories in current directory and chmod them to 755

find . -type d -exec chmod 755 {} \;

Recursively find all files in current directory modified in last minute

find . -type f -mmin -1

Recursively find all files in current directory accessed in the last 5 days and display the time accessed

find . -type f -atime -5 -exec ls -ltu {} \;

Recursively find all files in current directory and get the MD5 hash of each

find . -type f -print0 | xargs -0 md5

Recursively find the last 10 modified files in the current directory and display the time modified

Linux

find . -type f -printf '%T@ %p\n' | sort -n | tail -10

The command will return an elongated UNIX timestamp for each file. You can see the human readable time the file was last modified by running the following command:

date -r "<ABSOLUTE PATH OF FILE>"

BSD and OS X

find . -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -10

The command will return a UNIX timestamp for each file. It can be converted to human readable time by using the following command:

date -r <UNIXTIMESTAMP>

Recursively find all files in the current directory and rename them all in lower case

for i in `find . -type f -print`
do
lc=`echo "$i" | tr '[A-Z]' '[a-z]'`
if [ $lc != $i ]; then 
mv -i "$i" "$lc"
fi
done

Recursively find all directories in the current directory and rename them all in lower case

This command may have to be run multiple times to actually lower case all directories. The find command does not display the deepest directories first, so if the root directory is renamed before a child directory, the child directory rename will fail.

for i in `find . -type d -print`
do lc=`echo "$i" | tr '[A-Z]' '[a-z]'`
if [ $lc != $i ]; then
mv -i "$i" "$lc"
fi
done

References

If you found this post useful, you can help support this site and get something for yourself by signing up for any of the services listed below through the provided links.

The following links are part of affiliate programs, and I will receive a referral payment from any of the services you sign-up for.

  • Get Faster Shipping: Perhaps you're about to order some stuff on Amazon but want to get more value out of the money you would normally pay for shipping. Sign-up for a free, 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.
  • Start Investing Now: Are you looking to start investing some of your disposable saved income? Get started by opening an account with Webull, where upon sign-up and opening a brokerage account with an initial deposit of at least $100 you will receive 1 stock valued (subject to change based on normal market movement) between $8 and $1600.

Thanks for reading and take care.