フォルダ内で最大のファイルを見つける必要があります。
フォルダを再帰的にスキャンし、コンテンツをサイズで並べ替えるにはどうすればよいですか?
ls -R -S
を使ってみました 、ただし、これにはディレクトリもリストされます。
find
も使用してみました 。
承認された回答:
du
だけでこれを行うこともできます 。念のため、このバージョンのdu
を使用しています。 :
$ du --version
du (GNU coreutils) 8.5
アプローチ:
$ du -ah ..DIR.. | grep -v "/$" | sort -rh
アプローチの内訳
コマンドdu -ah DIR
指定されたディレクトリDIR
内のすべてのファイルとディレクトリのリストを生成します 。 -h
私が好む人間が読めるサイズを生成します。それらが必要ない場合は、そのスイッチをドロップします。 head -6
を使用しています 出力量を制限するだけです!
$ du -ah ~/Downloads/ | head -6
4.4M //eadn-wc01-5196795.nxedge.io/home/saml/Downloads/kodak_W820_wireless_frame/W820_W1020_WirelessFrames_exUG_GLB_en.pdf
624K //eadn-wc01-5196795.nxedge.io/home/saml/Downloads/kodak_W820_wireless_frame/easyshare_w820.pdf
4.9M //eadn-wc01-5196795.nxedge.io/home/saml/Downloads/kodak_W820_wireless_frame/W820_W1020WirelessFrameExUG_GLB_en.pdf
9.8M /home/saml/Downloads/kodak_W820_wireless_frame
8.0K /home/saml/Downloads/bugs.xls
604K //eadn-wc01-5196795.nxedge.io/home/saml/Downloads/netgear_gs724t/GS7xxT_HIG_5Jan10.pdf
最小から最大に並べ替えるのに十分簡単:
$ du -ah ~/Downloads/ | sort -h | head -6
0 /home/saml/Downloads/apps_archive/monitoring/nagios/nagios-check_sip-1.3/usr/lib64/nagios/plugins/check_ldaps
0 /home/saml/Downloads/data/elasticsearch/nodes/0/indices/logstash-2013.04.06/0/index/write.lock
0 /home/saml/Downloads/data/elasticsearch/nodes/0/indices/logstash-2013.04.06/0/translog/translog-1365292480753
0 /home/saml/Downloads/data/elasticsearch/nodes/0/indices/logstash-2013.04.06/1/index/write.lock
0 /home/saml/Downloads/data/elasticsearch/nodes/0/indices/logstash-2013.04.06/1/translog/translog-1365292480946
0 /home/saml/Downloads/data/elasticsearch/nodes/0/indices/logstash-2013.04.06/2/index/write.lock
逆に、最大から最小へ:
$ du -ah ~/Downloads/ | sort -rh | head -6
10G /home/saml/Downloads/
3.8G /home/saml/Downloads/audible/audio_books
3.8G /home/saml/Downloads/audible
2.3G /home/saml/Downloads/apps_archive
1.5G /home/saml/Downloads/digital_blasphemy/db1440ppng.zip
1.5G /home/saml/Downloads/digital_blasphemy
ディレクトリを表示せず、ファイルのみを表示します:
$ du -ah ~/Downloads/ | grep -v "/$" | sort -rh | head -6
3.8G /home/saml/Downloads/audible/audio_books
3.8G /home/saml/Downloads/audible
2.3G /home/saml/Downloads/apps_archive
1.5G /home/saml/Downloads/digital_blasphemy/db1440ppng.zip
1.5G /home/saml/Downloads/digital_blasphemy
835M /home/saml/Downloads/apps_archive/cad_cam_cae/salome/Salome-V6_5_0-LGPL-x86_64.run
すべてのディレクトリを除外する場合 出力から、ドット文字が存在するトリックを使用できます。これは、ディレクトリ名にドットが含まれておらず、探しているファイルにドットが含まれていることを前提としています。次に、grep -v '\s/[^.]*$'
を使用してディレクトリを除外できます。 :
$ du -ah ~/Downloads/ | grep -v '\s/[^.]*$' | sort -rh | head -2
1.5G /home/saml/Downloads/digital_blasphemy/db1440ppng.zip
835M /home/saml/Downloads/apps_archive/cad_cam_cae/salome/Salome-V6_5_0-LGPL-x86_64.run
最小から最大のリストが必要で、問題のある上位6つのファイルが必要な場合は、並べ替えスイッチを元に戻すことができます(-r
)、tail -6
を使用します head -6
の代わりに 。
$ du -ah ~/Downloads/ | grep -v "/$" | sort -h | tail -6
835M /home/saml/Downloads/apps_archive/cad_cam_cae/salome/Salome-V6_5_0-LGPL-x86_64.run
1.5G /home/saml/Downloads/digital_blasphemy
1.5G /home/saml/Downloads/digital_blasphemy/db1440ppng.zip
2.3G /home/saml/Downloads/apps_archive
3.8G /home/saml/Downloads/audible
3.8G /home/saml/Downloads/audible/audio_books