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→