csh/tcshで利用できる内部コマンド.
which だと実行されるコマンドだけが表示されるが,where だとパスの通った同名のコマンドが全て表示される.
> which [ /usr/bin/[ > where [ /usr/bin/[ /bin/[
sh/bash 等の場合は type -a
を使う.これも内部コマンド.
$ type -a [ [ is a shell builtin [ is /usr/bin/[ [ is /bin/[
zsh は where
, type
両方使えるよう.
% where where where: shell built-in command % type type type is a shell builtin
whereis -b
コマンド (Debian sidではutil-linux package内)
これはバイナリ以外のマニュアルやソースも探せる.
ここではGNU findutilsのfind
/usr
以下から [
を探す
$ find /usr -name [ -print /usr/bin/[
/usr
以下から [
を探し,ファイルの詳細を表示する
$ find /usr -name [ -ls 232803 60 -rwxr-xr-x 1 root root 60064 Aug 7 03:45 /usr/bin/[
.
から hoge
を含むファイル,ディレクトリ等を探す
$ find , -name "*hoge*" -print
.
から大文字小文字を区別しない hoge
を含むファイルを探す
$ find , -iname "*hoge*" -type f -print
typeの種類
-type c File is of type c: b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype. s socket D door (Solaris)
/
以下から nobody
ユーザのファイルを探す(username/uidどちらでもok)
$ sudo find / -user nobody -print
/
以下から nogroup
グループのファイルを探す(group/gidどちらでもok)
$ sudo find / -group nogroup -print
1GB以上のサイズのファイルを探す +
sizeに数値を指定すると =
のサイズ, +
で超えるサイズ, -
で未満のサイズがマッチする +
cでバイトサイズ,k/M/Gなども利用できる.数値のみだとブロックサイズ.
$ find ~/Downloads/ -size +1000000000c -ls $ find ~/Downloads/ -size +1000000k -ls $ find ~/Downloads/ -size +1000M -ls $ find ~/Downloads/ -size +1G -ls
~
以下の空ファイル,ディレクトリを探す.
$ find ~ -empty
アクセス時間も元にする場合 atime
(日単位) / amin
(分単位) +
ファイルステータス変更時間を元にする場合 ctime
/ cmin
+
ファイル変更時間を元にする場合 mtime
/ mmin
+
10分以内にアクセスされたファイルを探す
$ find . -amin -10 -print
10分以内にファイルステータスの変更されたファイルを探す
$ find . -cmin -10 -print
10分以内に編集されたファイルを探す
$ find . -mmin -10 -print
今日編集されたファイルを探す(minと同様atime/ctime/mtimeがある)
$ find . -mtime 0 -print
<!– 1日より前に編集されたファイルを探す
$ find . -mtime -1 -print
1日より後に編集されたファイルを探す
$ find . -mtime +1 -print
–
>
-newer
オプションでファイルのタイムスタンプと比較してそれより新しいファイルをGoogle Photosにアップロードする
D=`date +\%m\%d\%H\%M.\%S` ; find ~/Pictures -newer ${HOME}/Pictures/.gphoto_time \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.webm" -o -iname "*.mp4" \) -type f -print0 | xargs -0 -r -n1 ~/go/bin/gpup -a 'Instant Upload' && touch -t ${D} ${HOME}/Pictures/.gphoto_time
こいつはインデックスを作っておいて探すのでfindコマンドに比べて高速.
updatedb
コマンドでインデックスを作成する.
$ sudo updatedb
Debianだと/etc/cron.daily/locate
で毎日アップデートされる.
$ locate -r '/\[$' /usr/bin/[
コメント