Find files or directories from the command-line with find
find is a programme to search for files and directories (commonly called folders).
Find a file you know the name of
For example, if you are looking for a file named report.txt in your home directory run:
$ find /home/user/ -name report.txt
where:
$
is the prompt of your terminal.
/home/user/
the starting-point in the directory hierarchy.
-name
an option that tells find the name of the file.
If the files report.txt exists, the path of the file will be printed in the terminal, for example:
/home/user/Document/report.txt
Still in the terminal, you can preview report.txt by running $ less report.txt
.
If many directories including the word report
exist, you can tell find to exclude directories from the search results by adding the option -type f
such as:
$ find /home/user/ -name report.txt -type f
Find a directory
Conversely, -type d
will only list directories.
Find a file or directory you don’t know the exact name of
What if you don’t know the exact name of the file?
Use regular expressions.
For example if you know that the word report
is in the name of the file you are looking for, run:
$ find /home/user/ -name *report*
If you don’t know whether report
is written small cap or large cap, run:
$ find /home/user/ -iname *report*
The option -iname is like -name, but the match is case insensitive.
For more information about find run $ man find
.
find is copyleft-licensed and was published in 1971.
personal computing command-line interface (cli) gnu linux trisquel office applications text processing find wiki shell literacy