Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:linux:find_command [2014/12/04 06:45]
tech:linux:find_command [2014/12/04 06:45] (current)
Line 1: Line 1:
 +====== find command ======
 +Common uses
 +
 +===== Deleting old files with find command =====
 +Below is an example of deleting MySQL backups older than 7 days
 +<code bash>
 +BACKUPLOC="/​path/​to/​backups"​
 +MYSQLBACKUPLOC="​$BACKUPLOC/​mysql"​
 +find $MYSQLBACKUPLOC/​backup*.sql.gz -mtime +7 -exec rm {} \;
 +</​code>​
 +
 +Better syntax
 +<code bash>
 +JOBLOG="/​path/​to/​job/​log"​
 +find $JOBLOG/ -type f -name "​rem_20*.log"​ -mtime +7 -delete
 +</​code>​
 +
 +===== Deleting files with a certain extension across directories =====
 +This will delete all *.txt.gzip files
 +<code bash>
 +find . -name "​*.txt.gz"​ -exec rm -rf "​{}"​ \;
 +</​code>​
 +
 +===== Created/​Modified/​Accessed within the last hour =====
 +<code bash>
 +FILELOC="/​path/​to/​loc"​
 +# 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
 +</​code>​
  

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