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â€
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”
If you have any question please leave comment and donâ€™t forget to say thanks, as itâ€™s free.:)