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.

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/css/ home directory), run:
find $HOME -type d -name "Documents"
OR
find ~ -type d -name "Documents"
OR
find /home/css/ -type d -name "Documents"

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/css/ -type d -iname "Documents"
Sample outputs:

/home/css/Documents

/home/css/backups/Bills-PDF/Documents

/home/css/backups/Documents

/home/css/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"

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

 

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing Fail2ban

  Installing Fail2ban Installing Fail2ban on Ubuntu Server 16.04 is simple. Run the following...

How to display sockets summary and all open network ports with ss command

How to display sockets summary with ss command # ss -s How to display all open network ports...

How to scan for viruses with ClamAV on Ubuntu

ClamAV There aren't many viruses made for Linux distributions and as such, most people who use...

How to setup a UFW firewall on Ubuntu 18.04 LTS server

How do I setup a firewall with UFW (uncomplicated firewall) on an Ubuntu Linux 18.04 LTS server...

How to tar a file in Linux using command line

How to tar a file in Linux using command line I am a new Linux user. How can I create a tar file...