Linux comes with lots of tools to manage files and folders.
For a computer user who shifted from windows to Linux, he might find file management a little dauntingIn this article we are going to learn how to find a directory in Ubuntu (A popular distribution of Linux).
Using ‘find’ command
The easiest way to find a directory is using the find command. The general syntax of find command is as following:
“/directory/to/search/in” is the starting directory for the search, options is the criteria for search
expression is used to find files that match the given expression.
If you want to search a folder for a certain file or directory, we can do it in the following manner.
we have a folder named ‘docs’ in our users home directory. We want to find the ‘notes’ directory present in ‘docs’ directory.
The docs folder contains three more directories; therefore, it can be tedious to search all directories for a certain folder we need. The ‘find’ command can help us here.
We give the starting directory and the name of the directory of file we need to find and the ‘find’
command will provide us with the exact directory location.
We can also search a file using find command.
If we want to only find directory, we can specify it by using the ‘type’ parameter.
‘-type d ‘ specifies that the ‘find’ command will only return locations of the directories matching the name provided. If a file also has the same name as the directory we are trying to find,
‘type -d’ will remove that file from the results provided.
If we want to use the root directory as the starting location for the search, we need it to run the command as root user.
If we want detailed info about the results or our search we can use the -ls parameter.
We can also perform a case insensitive search by using the ‘-iname’ parameter instead of ‘-name’.
By using ‘iname’ the pattern ‘apt’ matches directory names such as ‘Apt’, ‘aPT’, ‘APT’ etc.
Using ‘locate’ command
Linux provides as with another command to search directories. The general syntax of locate command is as follows:
We can use locate to find the ‘notes’ directory as we did before.
The ‘find’ and ‘locate’ commands are the most accessible and easy to use commands. There are also several other third-party utilities available that can be used for searching. This versatility is what makes Linux so popular.