[英]Executing a shell script in the current directory
我正在編寫一個Shell腳本來列出五個占用最大空間的文件夾。 這是我所擁有的:
$ du -m --max-depth 1 | sort -rn 5
這可以正常工作,但是如何獲取此代碼來檢查調用它的目錄?
檢查這是否回答了您的問題:
$dir=`pwd`
if [ $dir = "some_directory_you_are_expecting" ]
then
du -m --max-depth 1 | sort -rn 5
else
do_some_other_thing
fi
您將“ 5”作為要排序的文件,但您想對du的輸出進行排序。 也許您的排序有所不同。 我的來自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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.