find command

Common uses

Deleting old files with find command

Below is an example of deleting MySQL backups older than 7 days

find $MYSQLBACKUPLOC/backup*.sql.gz -mtime +7 -exec rm {} \;

Better syntax

find $JOBLOG/ -type f -name "rem_20*.log" -mtime +7 -delete

Deleting files with a certain extension across directories

This will delete all *.txt.gzip files

find . -name "*.txt.gz" -exec rm -rf "{}" \;

Created/Modified/Accessed within the last hour

# Created in the last 60 minutes
find $FILELOC -cmin -60
# Modified in the last 60 minutes
find $FILELOC -mmin -60
# Accessed in the last 60 minutes
find $FILELOC -amin -60

QR Code
QR Code tech:linux:find_command (generated for current page)