Linux provides different ways to find and locate files and folders. We can use GUI tools like GNOME and KDE file managers or other 3’rd party applications designed for finding files. In this tutorial, we will look at how to find files, folders, and directories from the command line.
Tools To Find Files and Folder In Linux
As stated previously there are a lot of tools that can be used to find files and folders. We will look in detail all of them. Here list of these tools.
findcommand is very featureful command used with a lot of different options. More details about
find command can be found from the following tutorial.
Linux Find Command With Examples
Find Only Files
We can search only files by providing file type as
-type f. We will search files those named
conf in this example. We will use the glob start and end of the search term in order to accept any prefix or postfix for the search term. So this will match
$ find . -type f -name "*conf*"
Alternatively, we can specify the path we want to search for the given file name. We will provide the path according to
.. In this example, we will search in the
$ find /etc -type f -name "*conf*"
Find Only Folders
We may need only to find the folder. We will specify the type like below a directory.
$ find . -type d -name "*conf*"
locate command can be used as an offline database of all files and folders.
locate will search a database which is created with
updatedb command. More detailed information can get from the following tutorial.
locate Command Tutorial With Examples For Linux To Find Files
locate database only holds file and folder names we can not search in detail. But this database provides us very fast search option then
find command because it works offline.
As stated previously
locate uses a database to search files and folders. Updating this database is important before a search. The update will take very little time.
Search For File or Folders
We will use
locate command and the file and folder name to search.
$ locate /home/ismail/*back*
grep command mainly filters given text and files contents but we can use it to find files and folders. For more detail
Introduction to Linux Grep Command With Examples
We can use
ls command recursively and grep the files and folder we want to find. In this example, we will search for files and folders whose names contain
$ ls -R -l | grep backup
whichcommand is not an actual file and folder search.
which command simply search current environment executable files. This is generally useful if we are looking for a command which is not included in
PATH variable and can not use automatically.
$ which ls
whereis command is used to list given search term related binary, source, or man page files. In this example, we will search for
ls binary and related man page files.
$ whereis ls