0
我正在编写一个shell脚本来列出占用最多空间的五个文件夹。这是我有:在当前目录中执行shell脚本
$ du -m --max-depth 1 | sort -rn 5
这工作正常,但如何获取此代码来检查它从目录调用?
我正在编写一个shell脚本来列出占用最多空间的五个文件夹。这是我有:在当前目录中执行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”作为文件进行排序,但你想从杜输出排序。也许你的排序是不同的。我的是从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
我有一种感觉,还有更多的问题;以这种方式执行'du'(直接通过命令行或通过shell脚本或通过shell函数)只能在当前工作目录中执行。你在看什么?你想看什么? – sarnold 2012-02-04 01:43:05