查找服务器中占用空间最大的目录及文件 原

2019-04-03 10:36:32 浏览数 (1)

代码语言:javascript复制
#!/bin/bash
#Written by adai  2017-11-07
#Finding largest dir && file in pc。
dir1=`du -m /* |sort -n |tail -1 |awk '{print $2}'`
cd $dir1
while :
do
  dir2=`du -m ./* |sort -n |tail -1 |awk '{print $2}'`
  if [ -d $dir2 ]
  then
      cd $dir2
  else
      dir3=`pwd`
      break
  fi
done
file=`du -m ./* |sort -n |tail -1 |awk '{print $2}'`
echo "The max_size_dir is :  $dir3"
echo "The size is : `du -m $dir3 | awk '{print $1}'`M"
echo "The max_size_file is: `which $file`"
echo "The size is : `du -m $dir2 | awk '{print $1}'`M”

(adsbygoogle = window.adsbygoogle || []).push({});

0 人点赞