Linux Commands

How to Find a Directory in Linux

In Linux, the directories are used to store and organize the files. You can create directories, modify their name and permissions, delete them, build a hierarchy of directories, and more. However, many Linux beginners sometimes forget a directory’s location and cannot find it in the system.

In this situation, Linux offers an inbuilt command line utility to get this job done. So, in this quick tutorial, we will explain the simple ways and their examples to find a directory in Linux.

How to Find a Directory in Linux

The “find” command helps you to locate the files and directories. Here is the simple command for it:

find /parent_directory -type d -name "target_directory"

 
The “-type d” option instructs the “find” command to search only for directories. The “-name” option tells it to search the files by the provided name which is “targeted_directory”.

This is how the previous command searches the parent directory for subdirectories named “target_directory”. For example, to search for a subdirectory named “My_File” in the home directory, you should run the following:

find ~ -type d -name My_File

 

The tilde sign (~) in Linux represents the home directory. However, if you are unsure whether the name of the directory is in uppercase or lowercase, run the following command:

find /parent_directory -type d -iname "target_directory"

 

The only change that is made in the command is by replacing the “-name” option with the “iname” option. Here, an extra “i” stands for insensitive.

In case there are multiple directories that exist with the same name, the system will display the list of all the directories.

find ~ -type d -iname Documents

 

Conclusion

Since users often forget the directory locations, finding those directories has become crucial. Considering this issue, we explained how to find a directory in Linux in a straightforward method that doesn’t require installing any packages. It involves using the “find” command with certain options, such as type and name, to specifically get to the targeted directory.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.