How to Find Files, Folders and Directories In Linux From Command Line?
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 how to find files, folders and directories from command line.
As stated previously there are a lot of tools those 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 following tutorial.
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.
$ find . -type f -name "*conf*"
Find Only Folders
We may need only find folder. We will specify the type like below as directory.
$ find . -type d -name "*conf*"
locate command can be used as a offline database of all files and folders.
locate will search a database which is created with
updatedb command. More detailed information can be get from following tutorial.
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 database to search file and folders. Updating this database is important before a search. 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 cna use it for to find files and folders. For more detail
We can use
ls command recursively and grep the files and folder we want to find.
In this example we will search files and folders those names contains
$ ls -R -l | grep backup
whichcommand is not a actual file and folder search.
which command simply search current environment executable files. This is generally useful if we are looking a command which is not included in
PATH variable and can not used 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