How To Find a Directory On Linux Based System

I just switched from MS-Windows server admin to Debian Linux server system administration roles. I need to find a directory called project.images. I was also told that the locate command is the simplest and quickest way to find the locations of files and directories on Linux. But the locate command is not working out for me. How do I find project.images directory using command-line options only?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements find command on Linux or macOS/Unix
Est. reading time 5m
You need to use find command. It is used to locate files on Linux or Unix-like system. The locate command will search through a prebuilt database of files generated by updatedb.
How to find a directory on Unix/linux?
The find command will search live file-system for files that match the search criteria.

How to find a directory on Linux

The find command syntax is:
find /where/to/look/up criteria action
find /dir/path/look/up criteria action
find /dir/path/look/up -name "dir-name-here"
find /dir/path/look/up -name "pattern"
find /dir/path/look/up -name "dir-name-here" -print
find /dir/path/look/up -name "dir-name-here"
find / -name "dir-name-here"
find / -type d -name "dir-name-here"
find / -type d -name "dir-name-here" 2>/dev/null

Linux find directory command

The following example will show all files in the current directory and all subdirectories:

find .
find . -print

Finding a directory

To find a directory called apt in / (root) file system, enter:

Alert: When searching / (root) file system, you need to run the find command as root user.

find / -type d -name "apt" 
sudo find / -type d -name "apt"

Sample outputs:


Dealing with “Permission denied error messages” on Linux

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 command:
find /where/to/look/ criteria action 2>/dev/null
sudo find / -type d -name "apt" 2>/dev/null

How to find a directory named Documents on Linux?

Type the following command to search for Documents directory in your $HOME dir:
$ find $HOME -type d -name Documents
Sample outputs:


Getting a detailed list of files/dirs

Pass the -ls to list current file in ls command output format:

find  / -name "apt" -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt
4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt
4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt
917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt
917721    4 -rw-r--r--   1 root     root          173 Apr 15  2011 /etc/logrotate.d/apt
918762   16 -rwxr-xr-x   1 root     root        14985 Mar 14 12:48 /etc/cron.daily/apt

How do I list only directories?

Just find directories and skip file names pass the -type d option as follows:

find  / -type d -name "apt" -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt
4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt
4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt
917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt

How do I perform a case insensitive search?

Replace -name option with -iname as follows:

find  / -type d -iname "apt" -ls


find  / -type d -iname "apt"

The patterns ‘apt’ match the directory names ‘apt’, ‘APT’, ‘Apt’, ‘apT’, etc.

How do I find a directory called project.images?

Type any one of the following command:

find  / -type d -iname "project.images" -ls


find  / -type d -name "project.images" -ls


find  / -type d -name "project.images"

It is also possible to use the wild cards as follows:

find  / -type d -name "project.*"
find  /dir/to/search/ -type d -name "project.image??"

A note about locate command

To search for a file/dir named exactly project.images (not *project.images*), type:

locate -b '\project.images'
See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig 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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Slaven Tomac Aug 26, 2013 @ 7:25

    Why don’t you run updatedb and then locate and again you’ll have “simplest and quickest way to find the locations of files and directories on Linux”.

    updatedb will update your database.

    • Dan Lund Aug 27, 2013 @ 15:05

      That only helps for semi-permanent files since it only checks periodically to update the updatedb database. For files that were created recently it will not be found.

  • omgwtfbbq Sep 2, 2013 @ 9:57

    Find is a great tool that i use a lot.
    You could have talk about the -exec switch wich allows you to process the outpout. ie : find and delete all file in ./ that haven’t been modified since 90 day:

    find ./ -mtime 90 -exec rm -Rf {} \; 

    Anyway, great job on this website, keep it on!

  • Bob Sep 4, 2013 @ 5:43

    I have to second that updatedb is the way to go for a novice linux user. No worries about syntax and whatnot. Its also very useful for when you need to do multiple scans since you only traverse the filesystem once.

    In regards to -exec, you should be using -execdir when available due to some security implications… and the above rm -rf is somewhat dangerous since find by default traverses from the top down. Delete would be a much safer (and faster!!) operation than-exec rm.

  • omgwtfbbq Sep 4, 2013 @ 9:01

    Hi Bob,

    I have to agree with your update, rm -Rf is maybe too dangerons to use for novice users.

    I did not know -execdir wich seems to be very usefull.

    Thank you for that update =)

  • Tiff Oct 15, 2013 @ 15:14

    Great article!!! so useful!!! since I don’t have root, I get very verbose “no permission” output that is useless and I have to find the actual location through all the muck. Is there a way to only print found paths? Thanks so much for this article!

  • dan Oct 27, 2013 @ 12:33

    All those “no permission” messages should be on stderr while the information you want is on stdout. Both stderr and stdout default to printing on the controlling terminal. Tacking “> stdoutfile” on the end of the command would separate them, leaving all the unwanted noise on the terminal and putting the good stuff in stdoutfile. It would make more sense to redirect stderr to /dev/null (throwing it away) and leaving the useful output on the controlling terminal, but that would require finding the instructions for redirecting stderr in the shell docs (again).

  • Zeb Nov 12, 2013 @ 16:46

    To avoid seeing stderr messages, just use something like this:

    find / -iname "*filename*" 2> /dev/null

  • Craig R Morton Feb 3, 2014 @ 16:26

    Awesome, thanks!

  • dwb Aug 4, 2017 @ 14:27

    I always add -print 2>/dev/null to the end of find statement:
    find / -type d -name "apt" -print 2>/dev/null

    It will send all those permission errors to the bit-bucket, even when searching as a non-root user for both -type d or -type f

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum