find Command: Tutorial & Examples
Search for files and directories
The find
command is a Unix utility that searches a directory tree for files that match a certain set of criteria. It
is a powerful tool that can be used to locate files based on
their name, size, type, and other attributes.
To use the find
command, you specify the directory where you want to start the search and the criteria for the files
you want to find. For example, to find all the files in the
current directory and its subdirectories that have the .txt
extension, you can use the following command:
find . -name "*.txt"
This will search the current directory and all its subdirectories for files that have the .txt
extension, and it will
display the names of the files it finds.
You can also do more complicated things, for example, this command will calculate the md5sum
of all files including subdirectories:
find -type f -exec md5sum '{}' \; > md5sum.txt
The find
command has many options that allow you to customize its behavior, such as specifying the type of files you
want to find (e.g., regular files, directories, symbolic
links), specifying the size of the files you want to find, and specifying the time when the files were last modified. It
is a powerful and versatile tool for locating files on a
Unix system.