How to find a folder in Linux using the command line

I am a new Linux user. How do I find files and folders in Linux using the bash command line? What is the command to find a folder in Linux?

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.

ADVERTISEMENTS

Command to find a folder in Linux

  1. find command – Search for files and folder in a directory hierarchy
  2. 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"
OR
find ~ -type d -name "Documents"
OR
find /home/vivek/ -type d -name "Documents"

Find a folder in Linux using find bash command

find command in action on Linux

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"
OR
find ~ -type d -iname "Documents"
OR
find /home/vivek/ -type d -iname "Documents"
Sample outputs:

/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"
OR
$ sudo find / -type d -name "etc"
OR
$ sudo find / -type d -iname "etc"
Ways to Use find Command to Search Directories More Efficiently

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?

Try:
find / -type d -iname "python.projects" -ls
OR
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“.

Conclusion

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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS

Comments on this entry are closed.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.