完成
gist.github.com
実践
- /usr/で実践
- リンクファイルがあると末尾に@がつくためFile not foundになったり、空白をファイル名に含む場合にうまくソートできなかったり、ファイルが無いディレクトリだとディレクトリを表示してしまったり、等を修正。
user:[~]$ for dir in $(find /usr/ -type d | grep -vxF .); do echo "$(ls -1 $dir | wc -l) $dir"; done | sort -rn | head -n 10
3295 /usr/share/app-install/desktop
2103 /usr/share/app-install/icons
1973 /usr/share/man/man3
1910 /usr/lib/x86_64-linux-gnu
1890 /usr/share/doc
1723 /usr/bin
1682 /usr/share/man/man1
1568 /usr/src/linux-headers-4.8.0-52-generic/include/config
1568 /usr/src/linux-headers-4.8.0-36-generic/include/config
1180 /usr/src/linux-headers-4.8.0-52/include/linux
user:[~]$ for dir in $(find /usr/ -type d | grep -vxF .); do stat "$dir/$(ls -S --file-type $dir | egrep -v "[/@]$" | head -n1)" --format="%s %n"; done | grep -v "/$" | sort -rn | head -n 10
103581280 /usr/lib/x86_64-linux-gnu/libOxideQtCore.so.0
75839136 /usr/lib/thunderbird/libxul.so
72949536 /usr/lib/firefox/libxul.so
58131384 /usr/lib/libreoffice/program/libmergedlo.so
39688256 /usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitPluginProcess2
26068668 /usr/share/tegaki/models/zinnia/handwriting-ja.model
23701384 /usr/lib/mozc/mozc_server
22427896 /usr/lib/gcc/x86_64-linux-gnu/5/cc1plus
19319840 /usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc
18597793 /usr/share/mythes/th_en_US_v2.dat
user:[~]$ for dir in $(find /usr/ -type d | grep -vxF .); do stat "$dir/$(ls -t --file-type $dir | egrep -v "[/@]$" | head -n1)" --format="%Y %n"; done | grep -v "/$" | sort -rn | head -n 10
1495553004 /usr/lib/python3.5/xml/dom/__pycache__/NodeFilter.cpython-35.pyc
1495553004 /usr/lib/python3.5/json/__pycache__/encoder.cpython-35.pyc
1495553004 /usr/lib/python3.5/email/mime/__pycache__/nonmultipart.cpython-35.pyc
1495542287 /usr/lib/python2.7/dist-packages/pygtkcompat/pygtkcompat.pyc
1495542287 /usr/lib/python2.7/dist-packages/gtweak/tweaks/tweak_group_interface.pyc
1495542287 /usr/lib/python2.7/dist-packages/gtweak/__init__.pyc
1495542287 /usr/lib/python2.7/dist-packages/gi/repository/__init__.pyc
1495542287 /usr/lib/python2.7/dist-packages/gi/overrides/GIMarshallingTests.pyc
1495542287 /usr/lib/python2.7/dist-packages/gi/_gobject/__init__.pyc
1495542287 /usr/lib/python2.7/dist-packages/gi/_error.pyc
user:[~]$ du -sh /usr/
3.4G /usr/
user:[~]$ du -s --inode /usr/
200085 /usr/
user:[~]$ find /usr/ -type f | wc -l
116407
user:[~]$ find /usr/ -type d | wc -l
20743
user:[~]$ find /usr/ -type l | wc -l
62938
user:[~]$ find /usr/ -mmin -1440 | wc -l
18
練習
- テスト環境作成
- 100ディレクトリ * ( 100ファイル + ( 10サブディレクトリ * 100ファイル ) )
[~/Work]$ for dir in $(seq 1 100);do mkdir dir_$dir; cd dir_$dir; for file in $(seq 1 100);do touch file_$file; done; for sub in $(seq 1 10); do mkdir sub_$sub; cd sub_$sub; for file in $(seq 1 100); do touch sub_file_$file; done; cd ..; done; cd ..; done
[~/Work]$ touch dir_100/file_101
[~/Work]$ cat dir_100/file_101
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
[~/Work]$ for dir in $(find . -type d | grep -vxF .); do echo "$dir $(ls -1 $dir | wc -l)"; done | sort -r -k 2 | head -n 10
./dir_100 111
./dir_99 110
./dir_98 110
./dir_97 110
./dir_96 110
./dir_95 110
./dir_94 110
./dir_93 110
./dir_92 110
./dir_91 110
[~/Work]$ for dir in $(find . -type d | grep -vxF .); do echo "$(stat $dir/$(ls -Ft $dir | grep -v "/$" | head -n1) --format='%n %Y')"; done | sort -r -k 2 | head -n 10
./dir_100/file_101 1495551073
./dir_100/sub_10/sub_file_100 1495551019
./dir_100/sub_9/sub_file_100 1495551018
./dir_100/sub_8/sub_file_100 1495551018
./dir_100/sub_7/sub_file_100 1495551017
./dir_100/sub_6/sub_file_100 1495551016
./dir_100/sub_5/sub_file_100 1495551016
./dir_100/sub_4/sub_file_100 1495551015
./dir_100/sub_3/sub_file_100 1495551014
./dir_100/sub_2/sub_file_100 1495551014
[~/Work]$ du -s --inode .
111102 .
[~/Work]$ du -sh .
4.4M .
[~/Work]$ for dir in $(find . -type d | grep -vxF .); do echo "$(stat $dir/$(ls -Ft $dir | grep -v "/$" | head -n1) --format='%n %s')"; done | sort -r -k 2 | head -n 10
./dir_100/file_101 121
./dir_99/sub_9/sub_file_100 0
./dir_99/sub_8/sub_file_100 0
./dir_99/sub_7/sub_file_100 0
./dir_99/sub_6/sub_file_100 0
./dir_99/sub_5/sub_file_100 0
./dir_99/sub_4/sub_file_100 0
./dir_99/sub_3/sub_file_100 0
./dir_99/sub_2/sub_file_100 0
./dir_99/sub_10/sub_file_100 0
[~/Work]$ find . -type f | wc -l
110001
[~/Work]$ find . -type d | wc -l
1101
[~/Work]$ find . -mmin -10
./dir_100
./dir_100/file_101