Last updated on March 22nd, 2018 at 09:26 am
Find Files and Folders in Linux Command Line
If you are new to Linux so you might be wondering, How to Find Files and Folders in Linux Command Line. In this guide we will cover how to use find commands with examples. This will help you to find files and folders in Linux command line.
Using find command to search files and folders in Linux command line
find is a power Linux command which is used to search files and directories under Linux operating system. While searching your files in Linux using find command, you can specify criteria, like search into a specific directory, if path is not specified by default it will search in Present Working Directory. It supports also regex and other advanced options.
The most easiest way to find a file is to specify the exact name of required file.
find /path/of/directory/where/to/find/file -name "fileName"
Let’s Take a Real Example:
Suppose you remember only the file name which is backup.sh, but forget the location of file. In this condition you will use find command and search required file in whole system by giving the location “/”, This forward slash mean root of Linux Files System.
find / -name "backup.sh"
The result of above command is showing I have “backup.sh” file on more than one location, as command found this file on “/” (root) and other copy is in home directory of user “BroExperts” which is /home/BroExperts
Note:- This command dealing all the keywords as case sensitive, meaning a search for backup.sh is different than Backup.sh.
In case, you forget the name exactly if it was in capital words or not. Here is command to search files, but ignore the case of the filename.
find / -iname "backup.sh"
/home/BroExperts/backup.sh /Backup.sh /backup.sh
Now it found two files, the difference is only upper and lower character “B” in file name.
Common types are:
- d: directory
- f: regular file
- b: block device
- l: symbolic link
Using “d” as argument in find command we can search folder in Linux command line. For instance to search directory called “etc”, you will use following command.
find / -type d -iname “etc”
For example you want to search all files with “.conf”. To accomplished this we need to use following find command.
find /etc -type f -name “*.conf”
Find all files belongs to a specific user. Let’s search all files owned by BroExperts user.
find / -user BroExperts
Find a file with its name; owned by BroExperts user
find / -user BroExperts -name "backup.sh"
Hope this guide was easy to follow and helpful for you to understand how to find files and folders in Linux command line. If you have any question please leave comment
I am Hafiz Haider, co-founder of BroExperts.com. A Computer Geek and a certified Linux enthusiast (RHCE, RHCSA), who strongly believes in sharing knowledge.. You can reach me at firstname.lastname@example.org.