Find a directory in Linux

If you need to find a certain directory on your Linux system, we’ve got just the guide for you. In this tutorial, we’ll be going through the step by step instructions to locate a folder on Linux via both the command line and GUI.

In this tutorial you will learn:

  • Find a directory via command line
  • Find a directory via GUI

Find a directory in Linux

Find a directory in Linux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Find a directory via command line



Finding a directory or folder with the command line should work identically across any Linux distribution of your choice. All you need to do is open a terminal on your system and use the following find command syntax to see the location of a specified directory:

$ find /path/to/search -type d -name "name-of-directory"

Using that syntax, here’s how to search for a directory named “test” inside the home directory.

$ find $HOME -type d -name "test"
Search for a directory via find command

Search for a directory via find command

The -d option is what causes find to display directories (or folders) only. The -f option can be used for files, or the options can be omitted entirely to find both directories and files with the specified name.

Use wildcards in your search if you’re only specifying part of the directory name, like so:

$ find $HOME -type d -name "test*"


Search for a directory by specifying only part of a name

Search for a directory by specifying only part of a name

Use the iname option in place of name if you’d like to perform a case insensitive search. Example:

$ find $HOME -type d -iname "test"

The find command is probably going to be your best bet for finding a directory, but the locate command deserves a brief mention as well. The find command searches the file system in real time, whereas locate has a database of the file/directory names and locations on a system.

This allows locate to be a lot faster, but possibly less accurate as the database isn’t constantly refreshed. The find command is also more flexible, offers more options, and is certain to be installed by default.

Find a directory with locate command:

$ locate name-of-directory
Using the locate command to search for a directory

Using the locate command to search for a directory



Find a directory via GUI

To find a directory/folder with GUI, you can use your system’s file browser. We’ll show you what that looks like on our test system running the GNOME desktop environment, but your system may look different, depending on what desktop environment you’re running.

The instructions should be similar, as it can be assumed that any file browser you have will certainly offer a search function.

  1. Start by opening your file browser.
    Open the file browser

    Open the file browser



  2. Click the search icon to access the search bar, and type the directory you’re looking for in there. The file browser should then search for the folder and display its location.
    Finding a directory in GNOMEs built in file browser

    Finding a directory in GNOME’s built in file browser

Conclusion

Finding directories on Linux is simple. Between the find and locate commands as well as the built in file browser, there are a variety of good methods to quickly find a directory or folder in Linux.



Comments and Discussions
Linux Forum