find directory in linux

How to Find Directory in Linux

Last updated on March 11th, 2021 at 09:33 am

There are various commands to find directory in Linux such as find, locate, where. Of these find is the most powerful as it allows you to search files and directories in live file system. Here’s how to find directory in Linux using Find command. You can use it to find directory in unix as well as find directory in Ubuntu, and other linux systems.

 

How to Find Directory in Linux

Here are the steps to find directory in Linux using FIND command.

Here is the syntax of Find command

$ find starting_point options [search_expression]

In the above command starting_point is the location where linux will start looking for your files & directory

search_expression is the search string that linux will look for while finding files & directories

Bonus Read : How to Find All Files in a Directory in Linux

 

Examples to find directory in Linux

Here’s the command to search directory containing the string “app” in current location

$ find . -name "app"
./Projects/app  ./Project1/app

The above command will output all directory paths in present working directory that match given pattern. It is a good way to find directory path in linux.

In the above command we mention dot (.) to find directory in present working directory. We further specify -name option to search directory name for our search pattern (“app”)

If you get a “Permission Denied” error, then use sudo along with find command.

$ sudo find . -name "app"

Bonus Read : How to List Files in Linux

 

Find Directory Only in Linux

Please note, the above command will search for both files and directories. Also, it will list files & directories whose names match exactly the given pattern “app”, including case. It won’t list files & directories with partial match.

If you want to list only directories and not any files, then use -type d option

$ sudo find . -type d -name "app"
./Projects/app

The above command will only list directories that match the given expression.

Bonus Read : How to Install Zip and Unzip in Linux

 

Find Directory using Case Insensitive Search

If you want to do a case insensitive search, use -iname option

$ sudo find . -type d -iname "app"
./Projects/app   ./Project1/App

 

If you want to get detailed list of files & directories use -ls option along with find

$ sudo find . -type d -name "app" -ls
280951  116 -rwxrwxr-x   1 ubuntu   ubuntu     115555 May 24  2018 ./Projects/app

 

For more information about FIND command, run man find command in terminal

$ man find

 

 

Hopefully, the above commands can help you find directory in Linux.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!