Last updated on May 30th, 2018 at 09:55 am
For beginners who dealings first time with a Linux machine face one problem, how to find files and folders they looking for.
In this guide we will cover how to use find command with examples. This will help you to find files and folders on your Linux using bash shell.
Finding files by Name:
Easiest way to find files is by name:
# find /path/to/target/directory -name "fileName"
Let’s take one example:
Suppose you remember only the file name which is “backup.sh”, but forget the location of file. In this condition I will use find command and search required file in whole system by giving the location â€œ/â€ (mean root of file system).
See the command in action:
# find / -name "backup.sh"
The result of above command is showing I have this file on multiple location, command found this file on “/” (root) and other copy is in home directory of user haider which is /home/haider
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/haider/backup.sh /Backup.sh /backup.sh
Now it found two files, the difference is only upper and lower character “B” in file name.
Find something by specifying type
Common types are:
- d: directory
- f: regular file
- b: block device
- l: symbolic link
< class="post-text">For example if you want to find directory called haider. you will use following command:
# find / -type d -iname "haider"
For instance, you want to search all files ending with .conf from /etc/ directory.
# find /etc -type f -name "*.conf"
/etc/yum.conf /etc/systemd/user.conf /etc/systemd/journald.conf /etc/systemd/system.conf /etc/systemd/bootchart.conf /etc/systemd/logind.conf /etc/rsyslog.conf /etc/tmpfiles.d/tuned.conf /etc/httpd/conf.modules.d/00-mpm.conf /etc/httpd/conf.modules.d/00-dav.conf /etc/httpd/conf.modules.d/01-cgi.conf /etc/httpd/conf.modules.d/00-lua.conf /etc/httpd/conf.modules.d/00-systemd.conf /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/00-proxy.conf /etc/httpd/conf.modules.d/00-base.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/userdir.conf /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/autoindex.conf /etc/host.conf /etc/NetworkManager/NetworkManager.conf
If you like this Post, please give us your valuable feedback by pressing Vote Up / Vote Down Button. Thanks.