GNU/Linux >> Linux の 問題 >  >> Linux

サイズに従ってファイルを再帰的にソートしますか?

フォルダ内で最大のファイルを見つける必要があります。
フォルダを再帰的にスキャンし、コンテンツをサイズで並べ替えるにはどうすればよいですか?

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

Linux
  1. Linuxで特定のサイズのファイルを作成する方法

  2. 安全にファイルを再帰的に削除します:シュレッダー

  3. PNG ファイルを再帰的に最適化する

  1. Linux ディレクトリ内のファイルを再帰的にカウントする

  2. 特定の拡張子を持つファイルを再帰的に見つける

  3. 隠しファイルを再帰的にコピーする - Linux

  1. LinuxでXサイズよりも大きいまたは小さいファイルを見つける方法

  2. サイズと拡張子でファイルを検索する方法は?

  3. サイズ制限のあるファイルを圧縮するには?