Introduction
Searching for files and directories is a daily task for Linux users. Whether you’re cleaning up disk space, tracking down an old project, or exploring a new system, knowing how to find folders efficiently—and stop a command when needed—is essential.
In this post, we’ll walk through:
- How to find directories by name
- How to limit searches to avoid long waits
- How to safely stop a command that’s taking too long
Finding Directories by Name
The most common tool for searching in Linux is find.
To search for directories whose name contains projectX:
1 | find ~ -type d -iname "*projectX*" |
What this does:
~searches only in your home directory (faster and safer)-type dlimits results to directories-inamemakes the search case-insensitive*projectX*matches any directory containing that word
Searching the Entire System (Use with Care)
If you really need to search everywhere:
1 | find / -type d -iname "*projectX*" 2>/dev/null |
The 2>/dev/null part hides permission errors, but be warned: this can take a long time on large systems.
Faster Searches with locate
If available, locate is much faster because it uses an index:
1 | locate -i projectX |
If it returns nothing, update the database:
1 | sudo updatedb |
How to Stop a Running Command
If a search is taking too long or producing too much output:
The universal solution
1 | Ctrl + C |
This immediately stops the command.
If the Command Won’t Stop
Suspend it:
1 | Ctrl + Z |
Then terminate it:
1 | kill %1 |
Avoid Flooding Your Terminal
Pipe results to a pager:
1 | find ~ -type d -iname "*projectX*" | less |
Navigate with arrow keys and exit with:
1 | q
|
Limit Search Depth
To prevent find from scanning endlessly:
1 | find ~ -maxdepth 4 -type d -iname "*projectX*" |
This limits how deep find will go into subdirectories.
References
| Links | Site |
|---|---|
| https://man7.org/linux/man-pages/man1/find.1.html | Linux find manual |
| https://man7.org/linux/man-pages/man1/locate.1.html | Linux locate manual |
| https://www.gnu.org/software/grep/manual/grep.html | GNU grep documentation |
