是否有可能在Unix中使用ls列出子目录的总大小及其所有内容,而不是通常的4K(我假设)只是目录文件本身?
total 12K
drwxrwxr-x 6 *** *** 4.0K 2009-06-19 10:10 branches
drwxrwxr-x 13 *** *** 4.0K 2009-06-19 10:52 tags
drwxrwxr-x 16 *** *** 4.0K 2009-06-19 10:02 trunk
在翻遍了手册之后,我一无所获。
是否有可能在Unix中使用ls列出子目录的总大小及其所有内容,而不是通常的4K(我假设)只是目录文件本身?
total 12K
drwxrwxr-x 6 *** *** 4.0K 2009-06-19 10:10 branches
drwxrwxr-x 13 *** *** 4.0K 2009-06-19 10:52 tags
drwxrwxr-x 16 *** *** 4.0K 2009-06-19 10:02 trunk
在翻遍了手册之后,我一无所获。
当前回答
只是一个警告,如果你想比较文件的大小。Du根据文件系统、块大小、... .产生不同的结果
可能会发生文件大小不同的情况,例如比较您的本地硬盘和USB大容量存储设备上的相同目录。我使用以下脚本,包括ls来计算目录大小。结果以字节为单位,将所有子目录都考虑在内。
echo "[GetFileSize.sh] target directory: \"$1\""
iRetValue=0
uiLength=$(expr length "$1")
if [ $uiLength -lt 2 ]; then
echo "[GetFileSize.sh] invalid target directory: \"$1\" - exiting!"
iRetValue=-1
else
echo "[GetFileSize.sh] computing size of files..."
# use ls to compute total size of all files - skip directories as they may
# show different sizes, depending on block size of target disk / file system
uiTotalSize=$(ls -l -R $1 | grep -v ^d | awk '{total+=$5;} END {print total;}')
uiLength=$(expr length "$uiTotalSize")
if [ $uiLength -lt 1 ]; then
uiTotalSize=0
fi
echo -e "[GetFileSize.sh] total target file size: \"$uiTotalSize\""
fi
exit "$iRetValue"
其他回答
Du -sk * | sort -n将按大小对文件夹排序。当你想要清理空间时很有帮助。
或du -sh * | sort -h用于人类可读模式
看一下du命令
Du -sch *在同一目录下。
输入“ls -ltrh /path_to_directory”
嗯,最好的方法是使用这个命令:
du -h -x / | sort -hr >> /home/log_size.txt
然后你就可以在你的服务器上获得所有大小的文件夹。轻松帮助您找到最大的尺寸。