This find command guide is a follow-up to my previous 90 Linux Commands Frequently Used by Linux Sysadmins article. Every week, or as time permits, I will publish articles on ~90 commands geared to Linux sysadmins and Linux power users. let’s continue this series
The find command is part of findutils which includes the directory searching utilities required for Linux and Unix-like operating systems. It allows various search criteria, formatted output, and custom commands to be run on the search results. I’ve also included some cheat sheets and other useful reads at the end of this article.
find command example
To find directories matching a given name, in case-insensitive mode, use:
find path/ -type d -iname '*Dir_name*'
To find files by extension, use:
find path/ -name '*.ext'
To find files matching a path pattern, use:
find path/ -path '**/lib/**/*.ext'
To find files matching multiple patterns, use:
find path/ -name '*pattern1*' -or -name '*pattern2*'
To find files matching a given pattern, except in a specific directory, use:
find path/ -name '*.py' -not -path '*/exclude_dir/*'
To find file larger than 500k use:
find path/ -size +500k
To find files in size between 500K and 10M, use:
find path/ -size +500k -size -10M
To find and delete files modified in the last 7 days, use:
find path/ -mtime -7 -delete
Find Linux Commands – Useful Reading
- Grape – A disk utility for Unix systems.
- To find out – also part of findutils.
- where is – Find the correct path to the executable file.
We have covered the find command used to find files in a directory hierarchy. However, findutils also includes
locate command, which scans one or more databases of filenames and displays any matches,
updatedb command, which updates the filename database
locate order, and finally
xargs command, which builds and executes the command line by assembling together the arguments read on standard input. Often, these arguments are lists of filenames generated using
find, Note, if no file is specified to search, the current directory (,) is used.