March 7, 2026

PBX Science

VoIP & PBX, Networking, DIY, Computers.

What Are the Best Ways to Find Files in Linux?

What Are the Best Ways to Find Files in Linux? A Complete Guide to 50 Search Commands



What Are the Best Ways to Find Files in Linux? A Complete Guide to 50 Search Commands

Linux follows a simple principle: “everything is a file.” When you’re working on servers that rely heavily on command-line interfaces, finding the right file can seem like an impossible task.

But here’s the good news: once you learn the proper search techniques, what seemed difficult becomes remarkably simple.

This comprehensive guide shares powerful Linux file search commands that will help you quickly locate any file on your system.

What Are the Best Ways to Find Files in Linux? A Complete Guide to 50 Search Commands

 

 

 


 

1. Searching by File Name

The most common way to find files is by their name. The find command is your primary tool:

Basic name search:

find / -name filename.c

This searches the entire system (/) for a file named exactly “filename.c”.

Using wildcards:

find / -name "*.c"

This finds all files ending with the .c extension, perfect for locating all C source files.

Combining type and name:

find / -type f -name "*.c"

This specifically searches for files (not directories) with a .c extension, making your search more precise.

Finding directories:

find / -type d -name "filename*"

This locates directories whose names start with “filename”.

Case-insensitive search:

find / -iname "filename.c"

The -iname flag ignores case, finding “filename.c”, “FILENAMEC”, or “filename.C”.

2. Searching by File Type

Linux recognizes various file types beyond regular files and directories:

Regular files:

find /home -type f

Directories:

find /var -type d -name "log*"

Symbolic links:

find /usr -type l

Block devices:

find /dev -type b

Socket files:

find /tmp -type s

3. Searching by Permissions and Ownership

Finding files based on permissions is crucial for security audits and system management:

Specific permissions:

find / -type f -perm 755

Excluding specific permissions:

find / -type f ! -perm 755

Finding and modifying permissions:

find / -type f -perm 777 -exec chmod 755 {} \;

This powerful command finds all files with 777 permissions and changes them to 755.

By owner or group:

find /home -user john
find /var -group admin
find . -uid 1000
find /etc -gid 0

4. Searching by Time

Time-based searches help locate recently modified files or clean up old data:

Modified within 30 days:

find /tmp -mtime -30

Modified more than 30 days ago:

find /tmp -mtime +30

Modified within 24 hours:

find /tmp -mtime 0

Accessed within 1 day:

find /tmp -atime -1

Status changed within 24 hours:

find /etc -ctime -1

Modified within the last hour:

find / -mmin -60

Accessed within the last hour:

find / -amin -60

Time range search:

find / -mtime +10 -mtime -30

This finds files modified between 10 and 30 days ago.

Finding and deleting old files:

find /tmp -mtime +7 -name "*.c" | xargs rm -rf {};

5. Searching by File Size

Size-based searches help identify large files consuming disk space:

Exact size:

find /tmp -size 10M

Larger than:

find /var -size +100M

Smaller than:

find /var -size -1G

Different units:

find . -size +500c      # Greater than 500 bytes
find . -size 1024b      # Exactly 1024 bytes

Empty files and directories:

find . -empty           # Both files and directories
find . -type f -empty   # Empty files only
find . -type d -empty   # Empty directories only

Size range:

find /tmp -type f -size +100M -size -1G

Finding and sorting large files:

find /home -type f -size +100M -exec ls -lh {} \; | sort -k5 -hr

Moving large files:

find . -size +1000M -exec mv {} /root/home ;

Complex cleanup:

find /tmp -name "*.c" -mtime +30 -type f -size +1000M | xargs rm -rf {};

6. Controlling Search Depth

Limit how deep the search goes into directory structures:

Maximum depth:

find . -maxdepth 2 -name "*.txt"
find /var -maxdepth 3 -type f

Minimum depth:

find /home -mindepth 2 -name "*.conf"
find . -mindepth 1 -maxdepth 3 -name "*.log"

7. Excluding Directories and Files

Sometimes you need to exclude certain paths from your search:

Exclude single directory:

find . -name "*.c" ! -path "*/.git/*"

Exclude multiple directories:

find . -name "*.c" ! -path "*/.git/*" ! -path "*/node_modules/*"

Exclude all hidden directories:

find . -name "*.c" ! -path "*/.*/*"

8. Controlling Output Format

Customize how search results are displayed:

Detailed listing:

find . -name "*.conf" -ls

File names only:

find . -name "*.py" -print

Custom format with printf:

find . -name "*.txt" -printf "%p - %s bytes - %t\n"

Output to file:

find /var -name "*.log" -fprint logfiles.txt

9. High-Efficiency Search Commands

Here are the most powerful combinations for real-world tasks:

Finding and deleting files (three methods):

find /tmp -name "*.c" -exec rm -rf {} \;
find /tmp -name "*.c" | xargs rm -rf {};
rm -rf $(find /tmp -name "*.c")

Complex cleanup operation:

find /tmp -name "*.c" -mtime +30 -type f -size +1000M | xargs rm -rf {};

Bulk permission changes:

find . -type f -perm 777 -exec chmod 755 {} \;

Top 10 largest files:

find . -type f -exec du -h {} + | sort -hr | head -10

Finding duplicate filenames:

find /tmp -type f -printf "%f\n" | sort | uniq -d

File type statistics:

find /tmp -type f | sed 's/.*\.//' | sort | uniq -c

Moving large files:

find . -size +1000M -exec mv {} /tmp ;

Conclusion

With these 50+ commands at your fingertips, file searching in Linux becomes not just manageable but efficient.

Whether you’re managing servers, auditing security, cleaning up disk space, or developing applications, these commands will help you locate files quickly and accurately.

The key is understanding which combination of search criteria best fits your needs—by name, type, size, time, permissions, or any combination thereof.

Master these commands, and you’ll always be one step ahead in navigating the Linux filesystem.


Windows Software Alternatives in Linux


Disclaimer of pbxscience.com

PBXscience.com © All Copyrights Reserved. | Newsphere by AF themes.