*ARGS.TECH | BLOG | Master the "find" command in Linux: A practical cheatsheet
Loading...
BLOG
Master the "find" command in Linux: A practical cheatsheet
Terminal: ~

# Go beyond simple file search. Learn how to use the Linux "find" command to locate

# files by name, time, and size, and perform actions like `delete` or `chmod`.


# ----- The Power of `find`: Finding Files -----


# Find files by name (case-sensitive):

xinit@localhost:~$ find /path/to/search -type f -name "myfile.txt"


# Find files by name (case-insensitive):

xinit@localhost:~$ find /path/to/search -type f -iname "myfile.txt"


# Find all directories named 'logs':

xinit@localhost:~$ find / -type d -name "logs"


# Find files by extension (e.g., all .conf files):

xinit@localhost:~$ find /etc -type f -name "*.conf"


# ----- Finding by Time & Size -----


# Find files modified in the last 24 hours:

xinit@localhost:~$ find /var/log -type f -mtime -1


# Find files modified MORE than 7 days ago:

xinit@localhost:~$ find /home/user/Downloads -type f -mtime +7


# Find files larger than 100MB:

xinit@localhost:~$ find / -type f -size +100M


# Find empty files or directories:

xinit@localhost:~$ find /path/to/search -empty


# ----- Taking Action with `-exec` and `-delete` -----


# Execute a command on each found file (e.g., change permissions):

xinit@localhost:~$ find /path/to/app -type f -name "*.sh" -exec chmod +x {} \;


# Periodically delete old backup files (older than 3 days):

# WARNING: The `-delete` action is final. Use with caution!

xinit@localhost:~$ find /var/backups -name "*.zip" -type f -mtime +3 -delete


# Find all cache files and ask for confirmation before deleting (y/n):

xinit@localhost:~$ find / -type f -name "*.cache" -ok rm {} \;

www.args.tech
Top button
© *ARGS.TECH
2025
v 2.6.19