You can use find and locate commands in Linux to find folders and files from the command line. This page shows how to search for folders in Linux using various command line utilities.
Command to find a folder in Linux
- find command – Search for files and folder in a directory hierarchy
- locate command – Find files and folders by name using prebuilt database/index
How to find folder on Linux using find command
The syntax is:
find /where/to/look/up/ criteria action
find /folder/path/to/look/up/ criteria action
find /folder/path/ -name "folder-name-here"
find /search/path/ -name "folder-name-here" -print
find /search/path/ -name "folder-name-here" -ls
find /folder/ -name "pattern"
Finding a folder named Documents
To find a folder named “Documents” in your home directory ($HOME i.e. /home/vivek/ home directory), run:
find $HOME -type d -name "Documents"
find ~ -type d -name "Documents"
find /home/vivek/ -type d -name "Documents"
How to search for case incentive folder names
You can force find command interpret upper and lowercase letters as being the same. For example match Documents, DOCUMENTS, DocuMEnts and so on by passing the -iname option:
find $HOME -type d -iname "Documents"
find ~ -type d -iname "Documents"
find /home/vivek/ -type d -iname "Documents"
/home/vivek/Documents /home/vivek/backups/Bills-PDF/Documents /home/vivek/backups/Documents /home/vivek/documents
How to search a folder named /etc/ in the root (/) file system
When searching / (root) file system, you need to run the find command as root user:
# find / -type d -name "etc"
$ sudo find / -type d -name "etc"
$ sudo find / -type d -iname "etc"
How to hide “Permission denied error messages” when using find command
The find will show an error message for each directory/file on which you don’t have read permission. To avoid those messages, append 2>/dev/null at the end of each find command:
$ find /where/to/look/ criteria action 2>/dev/null
$ sudo find / -type d -iname "etc" 2>/dev/null
How do I find a directory called python.projects?
find / -type d -iname "python.projects" -ls
find / -type d -name "python.projects" -ls
It is also possible to use the bash shell wild cards, run:
find / -type d -name "python.*"
sudo find / -type d -name "?ython.*"
Understanding find command options
- -name : Base of file name (the path with the leading directories removed) matches shell pattern.
- -iname : Perform a case insensitive search for given pattern
- -print : Print the full file name on the standard output (usually screen), followed by a newline.
- -ls : Display current file in ls -dils format on standard output i.e. your screen.
- -type d : Only list folders or directories.
- -type f : Only list files.
Search folder in Linux using locate command
To search for a folder named exactly dir1 (not *dir1*), type:
$ locate -b '\dir1'
$ locate -b '\folder2'
Just search for file name matching Pictures, type:
$ locate Pictures
For more info see “UNIX Find A File Command“.
In this tutorial, you learned how to find a folder on the Linux system using find and locate commands. For more info see gnu find command help page here.