2012-02-04 16 views
0

ほとんどのスペースを消費する5つのフォルダを一覧表示するシェルスクリプトを作成しています。ここで私が持っているものです。現在のディレクトリでシェルスクリプトを実行

$ du -m --max-depth 1 | sort -rn 5 

これは正常に動作しますが、どのようにこのコードは、それが呼び出されているディレクトリをチェックするのですか?これは、あなたの質問に答えるかどうか

+5

。このようにして 'du'を(コマンドライン経由で、あるいはシェルスクリプト経由で、あるいはシェル関数経由で)実行すると、現在の作業ディレクトリで_only_実行できます。何を見ていますか?あなたは何を見ますか? – sarnold

答えて

0

チェック:

$dir=`pwd` 

if [ $dir = "some_directory_you_are_expecting" ] 
then 
    du -m --max-depth 1 | sort -rn 5 
else 
    do_some_other_thing 
fi 
0

ファイルをソートするとあなたは「5」を与えているが、あなたはデュからの出力をソートしたいです。おそらくあなたの並べ替えは異なっているでしょう。鉱山は、ここにhttp://www.gnu.org/software/coreutils/

からである:私は質問へのよりがあることを感じている

$ echo 'du -sm * | sort -rn | head -n5 ' > ~/bin/top5.sh 
raptor: ~ 
$ chmod 755 ~/bin/top5.sh 
raptor: ~ 
$ top 
top  top5.sh 
raptor: ~ 
$ top5.sh 
606  src 
532  svn 
407  tmp 
349  images 
45  workspace 
raptor: ~ 
$ cd /usr/ 
raptor: /usr 
$ top5.sh 
du: cannot read directory `lib64/mozilla/extensions': Permission denied 
du: cannot read directory `lost+found': Permission denied 
du: cannot read directory `share/ggz/modules': Permission denied 
1928 lib64 
1842 share 
1779 src 
492  bin 
457  lib32 
関連する問題