To find a directory by name on Linux, start with find /path -type d -name "directory_name"; use -iname for case-insensitive matching. Replace /path with the smallest sensible starting point, add 2>/dev/null when permission warnings are noise, and use find /path -type f when you are searching for files rather than folders.
How to Find a Directory on Linux: 5 Easy Commands
Lost a folder? Learn how to find a directory on Linux using find, locate, and grep commands. Simple examples for Ubuntu, CentOS, and Arch.
// The short answer
In this guide · 6 sections
Losing track of a directory in Linux is a common frustration. You know you created that config folder or downloaded that backup, but now it seems to have vanished into the file system abyss. Unlike graphical interfaces where you might click around aimlessly, the Linux terminal offers precise and powerful tools to locate exactly what you need in seconds. Whether you are a system administrator auditing a server or a developer looking for project files, mastering these search commands is essential for your workflow.
Quick Answer: To find a directory by name, use the following command structure. This tells Linux to look only for directories (type d) and ignore standard files. If you are hunting for a specific file rather than a folder, finding files in Linux follows a slightly different approach and is worth knowing alongside this one.
find /path -type d -name "foldername"Using the find Command (The Most Powerful Method)
The find command is the Swiss Army knife of Linux search tools. It searches through the directory tree in real-time, meaning it will always give you the most up-to-date results, even if a file was created just seconds ago. However, because it scans the disk, it can be slower on very large file systems compared to indexed search methods.
Basic Syntax to Search by Name
To find a specific directory, you need to tell the command where to start looking and what name to look for. If you are not sure where the directory is, start from the root (/) or your home directory (~).
find /home/user -name "downloads"This command searches for anything named downloads inside the /home/user folder. However, this returns both files and directories, which can clutter your output.
Finding Directories Only (Excluding Files)
When you are specifically looking for a folder, you should filter out standard files to clean up your results. We use the -type d flag for this purpose. This is particularly useful when you have files and folders with similar names.
find . -type d -name "config"This command searches the current directory (.) and all subdirectories for a directory named config.
Case-Insensitive Search
Linux is case-sensitive by default, meaning Backup and backup are treated as two different names. If you are not sure how you capitalized the directory name, use the -iname option instead of -name.
find /var -type d -iname "log"This will match Log, log, LOG, and even LoG.
Handling Permission Denied Errors
When you run search commands on the entire system (starting from /), you will likely encounter Permission denied error messages for directories your user does not have access to. These messages can flood your terminal and hide the actual search results.
You have two practical ways to handle this. First, you can run the command with sudo if you have administrative privileges, which allows you to search everywhere.
sudo find / -type d -name "secret_folder"If you do not have sudo access or just want to ignore the errors, you can redirect the error output to /dev/null, which effectively silences the error messages.
find / -type d -name "ssh" 2>/dev/nullThis keeps your output clean and shows only the directories you are allowed to see.
Using the locate Command (The Fastest Method)
If speed is your priority and you are searching for a directory that has existed for a while, the locate command is significantly faster than find. Instead of scanning the hard drive in real-time, it queries a pre-built database (mlocate.db).
Before using it, you may need to ensure it is installed and the database is updated. On many modern distributions, you can install it via your package manager.
sudo apt install mlocateSince locate relies on a database, it might not find a directory you created five minutes ago. To fix this, you can manually update the database before searching.
sudo updatedb
locate -b "\MyFolder"The -b option tells locate to match only the basename (the last part of the path), which helps avoid partial matches in long paths.
Finding Directories by Time or Size
Sometimes you do not remember the name of the directory, but you remember when you worked on it. The find command allows you to search based on timestamps.
To find directories modified in the last 24 hours:
find . -type d -mtime -1This is incredibly useful for troubleshooting. For example, if a software installation created a new directory somewhere and you need to track it down, this command will reveal it.
Once you locate the target directories, you might realize some of them are old backups or empty folders cluttering your system. If you identify a directory that is no longer needed, you can proceed to remove the directory safely using the correct commands to free up disk space.
How to Find the Path of a Command
Sometimes the directory you are looking for is the installation path of a specific program. In this case, commands like which and whereis are more efficient than a full system search.
which python3This returns the path to the executable. If you need more details, including source and manual page directories, use:
whereis nginxThis will show you the binary, the configuration directory, and the documentation location in one line.
GUI Methods (For Desktop Users)
If you are using a Linux desktop environment like GNOME, KDE Plasma, or XFCE, you do not always need the terminal.
GNOME (Ubuntu default): Press the Super (Windows) key and start typing the folder name. The search bar aggregates results from your files and settings.
KDE Plasma (Dolphin): Open the Dolphin file manager and press
Ctrl + F. This opens a powerful search bar where you can filter by content type, effectively mimicking the-type dfunction of the terminal.
These graphical tools often use the same underlying indexing services (like baloo or tracker) to provide instant results.
Quick answers
Frequently asked questions
How do I find a specific directory in Linux?
To find a specific directory, use the command find / -type d -name "directoryname". This command scans your file system starting from the root directory and filters the results to show only folders, excluding standard files.
How do I list all directories in the current folder?
You can list only the directories in your current location by running ls -d */. This filters out regular files from the output, giving you a clean list of subfolders immediately available to you.
How do I search for a folder if I don't know the exact name?
Use wildcards with the find command, such as find . -type d -name "*partialname*". The asterisks act as placeholders for unknown characters, allowing you to locate any folder that contains that specific phrase in its name.
Why does the find command say "Permission denied"?
This error occurs because the command is trying to access system directories that your current user account does not have permission to view. To fix this, run the command with sudo or add 2>/dev/null at the end to automatically hide these error messages.
What is the difference between locate and find commands?
find searches the live file system in real-time, which is slower but always accurate, while locate searches a pre-built database for instant results. Because locate relies on a database, it may not find files created very recently unless you run sudo updatedb first.
How can I find a directory that was recently modified?
You can find directories modified within the last 24 hours by using find . -type d -mtime -1. This is particularly useful for troubleshooting or finding where a recent installation placed its configuration files.
How do I find hidden directories in Linux?
Run the command find . -type d -name ".*" to specifically search for directories that start with a dot. Hidden directories usually store user configurations and are invisible to standard listing commands unless specifically targeted.
Can I find a directory by its size in Linux?
Yes, you can search for directories based on their content size, for example, find . -type d -size +100M. However, note that find checks the size of the directory file itself (usually 4KB), so for disk usage analysis, the du -h command is often a better tool.
Something wrong or out of date?
Tools change fast. Tell the editor what no longer works.