Finding the right file on a Linux server can be challenging at first. However, once you understand the structure of the file system and a few commands, it becomes much easier. In this guide, you will learn how to find files within Linux using simple, practical examples.
Understanding the Linux File System
In Linux, everything starts at the root directory, written as just /. From there, folders branch out like a tree.
Here are some of the most important directories:
/home– here you find user files and home folders
/etc– this directory stores system configuration files
/var – this contains logs and changing application data
/tmp– this holds temporary files
/binand/sbin– these contain core system tools and binaries
Once you know where things usually lie, you can narrow down your searches. Therefore, always consider the likely directory before running any command.
Finding Files with the find Command
The most powerful tool for locating files in Linux is the find command. You can search entire file systems or just specific folders.
If you want to search your whole system for a file named backup.sh, run:
find / -name "backup.sh" This command starts at / and looks through all subdirectories. It prints full paths for every file named backup.sh.
If you only want to search your own home directory, you can shorten the path. Use ~ to refer to your current user’s home folder:
find ~/ -name "backup.sh" This search runs faster and avoids scanning system directories.
Case-Insensitive Searches with -iname
Sometimes you do not remember the exact capitalization of a file. In that case, you can use a case-insensitive search.
The -iname option ignores upper- and lower-case differences:
find /etc -iname "config.cfg" This matches config.cfg, Config.cfg, or even CONFIG.CFG. Which is why it is helpful when you only know part of the name.
Finding Large Files to Free Desk Space
When disk space runs low, you may want to find large files first. The find command can help you identify them quickly.
To list all files larger than 100 megabytes, use:
find / -type f -size +100M This command searches for regular files (-type f) bigger than +100M. You can then review the output and decide what to clean up.
Searching for Directions Instead of Files
Sometimes you are looking for directories rather than individual files. For example, you might want to explore log folders in /var.
You can search specifically for directories with:
find /var -type d This shows all directories under /var and is very helpful for exploring nested folder structures.
Deleting Matches with -find – Use Carefully
The find command can also delete files automatically. However, you should use this feature with great care.
For example, to delete all .log files in /tmp, you could run:
find /tmp -type f -name "*.log" -delete This command removes all matching log files immediately. Always double-check the command and path before pressing Enter. If you are unsure, remove -delete first and review the listed files.
Browsing Folder Contents with ls -lah
Sometimes you do not need to search if you just want to inspect what is inside a directory.
For that, use the ls command with a few useful options:
ls -lah This shows file sizes, permissions, and owners. It also displays hidden files, which start with a dot. Together, these details give you a clear overview of the current folder.
Watch Our YouTube Video on Finding Files in Linux
If you prefer a visual walkthrough, you can follow the connected YouTube video on How to Find Files in Linux. In the tutorial, the same commands are demonstrated step by step on a live Linux system, so you can see exactly how the searches work in practice.
Conclusion
You now know the basics of the Linux file system and how its main directories are structured. With the find command, you can search files by name, size, or type, and even locate large files that fill your storage. You can browse folders comfortably with ls -lah and investigate what is happening on your server.
With these tools, you can locate almost any file on your Linux server quickly and reliably.