The find command is Linux is one of the most useful commands for searching files and directories. At first the find command syntax might look a bit daunting, but once we get a hang of it, the find command is a great asset.
How to print all files and directories in current directory?
find . -print
How to print all files with details?
find . -type f -ls
How to print only files in current directory, no directories?
find . -type f
How to print only directories in current directory, no files?
find . -type d
How to find all directories in the current directory and their disk usage?
find * -prune -type d -exec du -skh {} \;
How to find files whose names have the string “cmd”?
find . -type f -name “*cmd*”
How to find files whose names have the string “cmd” or “line”?
find . -type f -name “*cmd*” -or -name “*line*”
How to find files whose names have the string “cmd” and “line”?
find . -type f -name “*cmd*” -and -name “*line*”
How to add all files with “.py” at the end?
find . -type f -exec mv {} {}.py
How to find all files larger than 10M?
find . -size +10M -print
How to find all files that were changed within the last 60 minutes?
find . -ctime -60m