如何显示LS格式的文件和文件夹的大小 [英] How to show file and folder size in ls format

查看:793
本文介绍了如何显示LS格式的文件和文件夹的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ls -l命令将显示详细信息的所有文件和文件夹。而文件夹的大小是不正确的(alwasy显示4.0k)。

因此​​,如何显示文件/文件夹为的ls -l <​​/ code>除了用正确的大小的文件夹格式。谢谢!

ls -l命令格式为:

  drwxr-XR-×9杰里杰里XXX.0K 3月3日14:34瓶-0.10.1
-rw-RW-R-- 1杰里杰里532K 3月3日14:25瓶-0.10.1.tar.gz
drwxrwxr-X 10杰里杰里XXX千2月8日15:41 leveldb1.15


解决方案

您可以使用 -printf 选项找到来获得大部分信息的 - 见更多的男人页面信息。最简单的方法,我知道找到的一切,包括一个目录的大小里面是杜-S ,所以你必须要打印/这些值粘贴在一起。例如:

 粘贴≤(。-maxdepth找到1 -printf%M%U%C%P \\ N)≤(找到-maxdepth 1 -exec杜-s {。 } \\; |切-f1)|列-t

示例输出:

  drwxrwxr-X哦周四4月3日7时07分45秒2014年12260
-rw-RW-R--哦周四4月3日7时07分41秒2014年./test.txt 5080
drwxrwxr-X哦周四4月3日7时07分54秒2014年./testdir 7140

所以:许可/老板/日期/名称/字节大小

ls -l will show all file and folder in detail information. but folder size is not correct(alwasy show 4.0k).

So how to show file/folder as ls -l format besides folder with correct size. Thanks!

ls -l format:

drwxr-xr-x  9 jerry jerry XXX.0K Mar  3 14:34 Flask-0.10.1  
-rw-rw-r--  1 jerry jerry 532K Mar  3 14:25 Flask-0.10.1.tar.gz  
drwxrwxr-x 10 jerry jerry XXXK Feb  8 15:41 leveldb1.15

解决方案

You can use the -printf option of find to get most of the info - see the man page for more info. The easiest way I know to find the size of a directory including everything inside it is with du -s, so you will have to print/paste these values together. eg:

paste <(find . -maxdepth 1 -printf "%M %u %c %p\n") <(find . -maxdepth 1 -exec du -s {} \; | cut -f1 ) | column -t

Sample output:

drwxrwxr-x  ooh Thu  Apr  3  07:07:45  2014  .           12260
-rw-rw-r--  ooh  Thu  Apr  3  07:07:41  2014  ./test.txt  5080
drwxrwxr-x  ooh  Thu  Apr  3  07:07:54  2014  ./testdir   7140

So: permission/owner/date/name/size in bytes

这篇关于如何显示LS格式的文件和文件夹的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆