基本形 †# find / -name httpd.conf 検索方法の種類 †検索するための情報としては、タイムスタンプ、データの属性などがある。 タイムスタンプをもとにファイルを検索 †# find ./ -atime +3 # find ./ -mtime +3 # find ./ -ctime +3
検索日時の指定 †非常に分かりにくい。ので表にまとめてみた。 以下は一週間以内、以上前の例)
もし、一週間以上前に作られたファイルを探したいときは… # find ./ -ctime +7 -print ±がない場合はその日を限定するものになる。 # find ./ -ctime 7 -print データのタイプを指定して検索 †検索条件として、『ファイル』、『ディレクトリ』、『シンボリックリンク』を指定できる。 タイプがファイルの場合 †# find . -type f -ctime +7 -exec ls -la {} \; -rw-r--r-- 1 root root 0 3月 2 11:01 ./mcelog -rw------- 1 root root 47164 3月 2 10:24 ./anaconda.xlog -rw------- 1 root root 438707 3月 2 10:24 ./anaconda.log -rw------- 1 root root 0 3月 2 11:23 ./tallylog -rw------- 1 root root 25589 3月 2 10:24 ./anaconda.syslog -rw------- 1 root root 0 3月 2 10:23 ./pm/suspend.log もちろんls以外にもrmやmvが使用できるので、条件に合わせて変更させる。 タイプがディレクトリの場合 †# find . -type d -ctime +7 -exec ls -ld {} \; drwxr-x--- 2 root root 4096 3月 2 10:38 ./audit drwx------ 2 root root 4096 1月 21 2009 ./ppp drwxr-xr-x 2 root root 4096 3月 2 10:23 ./mail drwxr-xr-x 2 root root 4096 11月 12 2007 ./conman.old drwxr-xr-x 2 root root 4096 11月 12 2007 ./conman drwxr-xr-x 2 root root 4096 3月 2 12:24 ./prelink drwxr-xr-x 2 root root 4096 3月 2 10:23 ./pm drwxr-xr-x 2 root root 4096 9月 20 2009 ./vbox タイプがシンボリックリンクの場合 †# find . -type l -exec ls -l {} \; サイズを指定して検索する †データサイズを指定して検索する。 またサイズに+-をつけることで、以上、以下の指定ができる。 # dd if=/dev/zero of=/var/log/megazero.image count=1024000 bs=1 # dd if=/dev/zero of=/var/log/kilozero.image count=1024 bs=1 # dd if=/dev/zero of=/var/log/bytezero.image count=1 bs=1 # ls -lh *.image -rw-r--r-- 1 root root 1 3月 10 17:30 bytezero.image -rw-r--r-- 1 root root 1.0K 3月 10 17:30 kilozero.image -rw-r--r-- 1 root root 1000K 3月 10 17:29 megazero.image -rw-r--r-- 1 root root 977K 3月 10 17:28 zero.image
例)1バイトのファイルを検索 # find . -size 1c -exec ls -lh {} \; -rw-r--r-- 1 root root 1 3月 10 17:30 ./bytezero.image 例)1kb以上のファイルを検索(タイプはファイル、検索ディレクトリはカレント) # find . -maxdepth 1 -type f -size +1k -exec ls -lk {} \; -rw-r--r-- 1 root root 27 3月 10 10:57 ./rpmpkgs -rw-r----- 1 mysql mysql 3 3月 10 09:51 ./mysqld.log -rw------- 1 root root 11 3月 6 04:02 ./cron.1 -rw------- 1 root root 47 3月 2 10:24 ./anaconda.xlog -rw------- 1 root utmp 3 3月 10 15:06 ./btmp -rw------- 1 root root 259 3月 6 03:39 ./messages.1 -rw------- 1 root root 10 3月 10 18:01 ./cron findに引数を渡して実行させる †非常に便利 # find ./ -ctime +7 -exec ls -la {} \; -rw-r--r-- 1 root root 13139 8月 31 2010 ./magic -rw-r--r-- 1 root root 33726 8月 31 2010 ./httpd.conf.org http://d.hatena.ne.jp/yumatsumo/20070516 |