How to Search for a File in Linux
Searching for files efficiently is an essential skill for Linux users, developers, and system administrators. Linux provides multiple tools and commands to locate files, directories, and even search inside their contents.
The “find” command is one of the most versatile tools for locating files based on names, types, sizes, modification times, and even permissions.
Basic Syntax
find [path] [options] [expression]a) Search by Filename
find /home -name "report.pdf"/home → Search path.
-name → Match exact filename (case-sensitive).

🔹 Case-insensitive search:
find /home -iname "report.pdf"b) Search by Extension
find /var/log -type f -name "*.log"- -type f → Search files only.
- Use -type d for directories.
c) Search by Size
find / -size +500M- +500M → Files larger than 500 MB.
- -100k → Files smaller than 100 KB.
d) Search by Modification Time
find /etc -type f -mtime -7- -mtime -7 → Files modified within the last 7 days.
- Use +7 to find files older than 7 days.
e) Execute Commands on Found Files
find /var/log -name "*.log" -exec gzip {} \;Compresses all .log files inside /var/log.
f) Combine Multiple Conditions
find /home -type f \( -name "*.pdf" -o -name "*.docx" \) -size +1MSearches for PDF or DOCX files larger than 1 MB.
Faster Searching with the “locate” Command ⚡ (High Performance)
Unlike “find“, “locate” uses a prebuilt database for near-instant searches.
Install and Update Database
sudo apt install mlocate # Debian/Ubuntusudo yum install mlocate # CentOS/RHELsudo updatedb # Update locate databaseUsage
locate report.pdf
🔹 Case-insensitive search:



