Find Tips
Jump to navigation
Jump to search
find
is the Unix utility to find files based on various criteria. Read the man page it's quite useful.
This command will quickly remove any files from the current folder and below that have not be modified in the last 14 days.
find . -mtime +14 -exec rm -f {} \;
This incantation can be used to discover & cleanup .rpmnew files that RPM installs.
find /etc -name "*.rpmnew" -print find /etc -name "*.rpmnew" -exec rm {} \;
Find files that are larger than 1G (one gigabyte)
sudo find / -size +1G -print
Some examples used in maintenance of Rsnapshot
Sum the size of files ending in .tmp in folder daily.1
find daily.1 -type f -name "*.tmp" -ls | awk '{ sum += $7 } END { print sum }'
Sum the size of singly-linked files in folder daily.1 (In rsnapshot, singly-linked files are safe to compress)
find daily.1 -links 1 -type f -ls | awk '{ sum += $7 } END { print sum }'
Compress files using find
find daily.1 -links 1 -size +1M ! -name "*.bz2" -print | grep -v \.svn | xargs bzip2 -v