Archive for March 6th, 2014

find

Thursday, March 6th, 2014

Find files older than 15 days and list them:

[root@staff /root]# find /var/squid/logs/ -mtime +15 -execdir ls -lh {} \;
-rw-r-----  1 squid  squid    91k Feb 16 20:46 /var/squid/logs/cache.log.17
-rw-r-----  1 squid  squid   108M Feb 17 00:00 /var/squid/logs/access.log.17
-rw-r-----  1 squid  squid   122M Feb 16 00:00 /var/squid/logs/access.log.18
-rw-r-----  1 squid  squid   355M Feb 19 00:00 /var/squid/logs/access.log.15
-rw-r-----  1 squid  squid   137k Feb 18 23:55 /var/squid/logs/cache.log.15
-rw-r-----  1 squid  squid   275M Feb 18 00:00 /var/squid/logs/access.log.16
-rw-r-----  1 squid  squid   145k Feb 17 21:49 /var/squid/logs/cache.log.16

List files modified during last 5 minutes:

find /some/path/ -type f -mmin -5 -execdir ls -l {} \;

Find files bigger than 2 kilobytes in .mc/ directory:

find .mc/ -type f -size +2000c
.mc/ini

or:

find .mc/ -type f -size +2k
.mc/ini

Find files smaller than 80 bytes in .mc/ directory:

vn ~ # find .mc/ -type f -size -80c
.mc/Tree
.mc/cedit/cooledit.clip

Handy one-liner for searching a file with wildcard, case-insensitive, in 2 directories simultaneously (assuming the file contains ‘Yutong’):

srv ~ # find /storage/sounds/{cars,ru/cars} -iname yut\*
/storage/sounds/cars/Yutong.wav
/storage/sounds/ru/cars/Yutong.wav

Find files with “+380” in their name which were created on October 13, 2015 and copy them to /home/lexus/:

find /storage/cluster/ready/ -name "*+380*" -type f -newermt 2015-10-13 ! -newermt 2015-10-14 -execdir cp {} /home/lexus/ \;