日々之迷歩

世の中わからんことだらけ

ITが複雑で難しくなっていく様に翻弄される日々です。微力ながら共著させていただいた「シェル・ワンライナー160本ノック」をよろしくお願い申し上げます。

inode番号が重複するファイルを表示

突然だがinode番号というのはご存知?OSがファイルの実体を管理する番号で、ファイル名が違ってもinode番号が同じなら同じファイルということ。実際どんなのがあるのか?有名なのがgrep兄弟。

fgrepは正規表現を使わず指定された文字列そのもので検索。grep -Fと同等。egrepは(Nikon|Canon)のような拡張正規表現が使える。grep -Eと同等。

$ \ls -il /usr/bin/grep /usr/bin/?grep
8486486 -rwxr-xr-x  3 root  wheel  29760  9 10  2014 /usr/bin/egrep
8486486 -rwxr-xr-x  3 root  wheel  29760  9 10  2014 /usr/bin/fgrep
8486486 -rwxr-xr-x  3 root  wheel  29760  9 10  2014 /usr/bin/grep
8551346 -rwxr-xr-x  2 root  wheel  26064  9 10  2014 /usr/bin/pgrep
8551790 -rwxr-xr-x  6 root  wheel  29760  9 10  2014 /usr/bin/zgrep

一番左がinode番号。grep、egrep、fgrepについては、inode番号が同じだということが分かる。つまり、コマンドとして呼び出される場合、コマンドファイル名によって動作を変える同じプログラムファイルだということ。

じゃあ、他にもinode番号が重複するコマンドファイルはどんなのがあるのか?リストアップするシェル芸をば。ほら、怖くない!!(ちなみにkshbashzsh限定)

$ \ls -i /usr/bin | sort -k1,1 | awk '{print $1}' | uniq -d | ggrep -f - <( \ls -i /usr/bin ) | sort -k1,1

・・・やっぱり怖い・・・という方へ・・・後日解説を書きますゆえ・・・ 結果はこちら。動作環境はMacYosemite。左側のカラムがinode番号。へえ〜思ったよりもたくさんあるのが面白い。

 8214826 less
 8214826 more
 8486486 egrep
 8486486 fgrep
 8486486 grep
 8541772 groups
 8541772 id
 8541772 whoami
 8546497 binhex.pl
 8546497 crc32
 8546497 dbicadmin
 8546497 dbilogstrip
 8546497 dbiprof
 8546497 dbiproxy
 8546497 debinhex.pl
 8546497 eyapp
 8546497 findrule
 8546497 format-sql
 8546497 htmltree
 8546497 ip2cc
 8546497 ipcount
 8546497 iptab
 8546497 lwp-download
 8546497 lwp-dump
 8546497 lwp-mirror
 8546497 lwp-request
 8546497 macerror
 8546497 moo-outdated
 8546497 moose-outdated
 8546497 net-server
 8546497 package-stash-conflicts
 8546497 par.pl
 8546497 pod2readme
 8546497 pp
 8546497 pwhich
 8546497 scandeps.pl
 8546497 spfd
 8546497 spfquery
 8546497 stty.pl
 8546497 tkpp
 8546497 treereg
 8546497 xgettext.pl
 8546497 xpath
 8551346 pgrep
 8551346 pkill
 8551790 bzegrep
 8551790 bzfgrep
 8551790 bzgrep
 8551790 zegrep
 8551790 zfgrep
 8551790 zgrep
 8555174 compress
 8555174 uncompress
 8555191 zcmp
 8555191 zdiff
 8555195 zless
 8555195 zmore
 8557011 mail
 8557011 mailx
 8557661 c2ph
 8557661 config_data
 8557661 corelist
 8557661 cpan
 8557661 cpan2dist
 8557661 cpanp
 8557661 cpanp-run-perl
 8557661 enc2xs
 8557661 find2perl
 8557661 h2ph
 8557661 h2xs
 8557661 instmodsh
 8557661 json_pp
 8557661 libnetcfg
 8557661 perlbug
 8557661 perldoc
 8557661 perlivp
 8557661 perlthanks
 8557661 piconv
 8557661 pl2pm
 8557661 pod2html
 8557661 pod2latex
 8557661 pod2man
 8557661 pod2text
 8557661 pod2usage
 8557661 podchecker
 8557661 podselect
 8557661 prove
 8557661 psed
 8557661 pstruct
 8557661 ptar
 8557661 ptardiff
 8557661 ptargrep
 8557661 s2p
 8557661 shasum
 8557661 splain
 8557661 xsubpp
 8557661 zipdetails
 8569390 2to3
 8569390 2to3-
 8569390 idle
 8569390 pydoc
 8569390 python-config
 8569401 python
 8569401 pythonw
 8578482 easy_install
 8578482 xattr
 8578607 alias
 8578607 bg
 8578607 cd
 8578607 command
 8578607 fc
 8578607 fg
 8578607 getopts
 8578607 hash
 8578607 jobs
 8578607 read
 8578607 type
 8578607 ulimit
 8578607 umask
 8578607 unalias
 8578607 wait
 8578620 hexdump
 8578620 od
 8578644 uptime
 8578644 w
 8581309 unzip
 8581309 zipinfo
15236764 at
15236764 atq
15236764 atrm
15236764 batch
15236777 bunzip2
15236777 bzcat
15236777 bzip2
15236789 cksum
15236789 sum
15236915 readlink
15236915 stat
18655118 parl
18655118 parldyn
18730932 gunzip
18730932 gzcat
18730932 zcat
18734004 arch
18734004 machine
18734005 chfn
18734005 chpass
18734005 chsh