QA
Beginner LevelLinux Commands & SysAdmin

How do you search for files using find by name, size, type, and modification time?

❓ Interview Prompt: Explain find command syntax, -name, -type (f/d), -size, -mtime, and executing commands via -exec.

The 'find' command searches the directory tree for files matching specific attributes:

Parameters:

•
*'-name ".log"'**: Match filenames with glob wildcards.
•
'-type f / d': Filter by file ('f') or directory ('d').
•
'-size +100M': Files larger than 100 Megabytes.
•
'-mtime -7': Files modified within the last 7 days.
•
'-exec rm -f {} ;': Run command on every matching file!

Code Implementation Example

bash
# Find and delete log files older than 30 days
find /var/log/app -type f -name "*.log" -mtime +30 -exec rm -f {} ;

# Find all directories with 777 permissions
find /var/www -type d -perm 777
💡Searching filesystem tree and executing cleanup operations via find.
🎯 Interview Key Takeaway

Use find with -type, -mtime, and -exec to locate and process files based on metadata attributes.

#find#Filesystem Search#CLI#Beginner
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?