文章目录

  • 查看文件夹大小
    • du命令(推荐使用)
    • ls命令
  • 查看文件大小
    • du命令(推荐使用)
    • ls命令
    • stat命令
    • wc命令
  • 总结

查看文件夹大小

du命令(推荐使用)

Summarize disk usage of the set of FILEs, recursively for directories.
默认情况下查看当前目录的文件夹的大小,但是可以通过选项灵活使用。
du filepath:查看指定文件夹的大小(不指定默认为当前文件夹,且不递归显示子目录)。

# 默认:显示单位为kb
$ du
204     ./CollectHomework
252     ./hello-word
1844    .# -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
# 形象的显示单位,使其更加易读。
$ du -h
204K    ./CollectHomework
252K    ./hello-word
1.9M    .# -a, --all             write counts for all files, not just directories
# 显示所有文件的大小,而不仅仅是文件夹
$ du -ah
1.4M    ./1.5.0-阿里巴巴Java开发手册(华山版).pdf
76K     ./CollectHomework/CollectHomework-1.jpg
128K    ./CollectHomework/CollectHomework-2.jpg
204K    ./CollectHomework
56K     ./hello-word/github-bootstrap语言识别情况.jpg
20K     ./hello-word/github-hello-world1语言识别情况.jpg
28K     ./hello-word/github-hello-world2语言识别情况.jpg
12K     ./hello-word/github-hello-world语言识别情况.jpg
64K     ./hello-word/github语言识别情况.jpg
52K     ./hello-word/hello-world-github.png
16K     ./hello-word/hello-world-github1.png
252K    ./hello-word
1.9M    .# -d, --max-depth=N     print the total for a directory (or file, with --all)
# only if it is N or fewer levels below the command line argument;
# --max-depth=0 is the same as --summarize
# 指定遍历深度,如果不指定表示遍历到底;如果是0,同-s / --summarize只显示总大小;如果是1,表示只遍历当前目录,不递归遍历子目录(如果有的话)。
$ du -h --max-depth=1
204K    ./CollectHomework
252K    ./hello-word
1.9M    .

ls命令

List information about the FILEs (the current directory by default).
使用-l 选项,显示文件的长格式的信息(包含了文件的大小)。
ls -l filepath:如果filepath是文件夹,第一行显示的即为指定文件夹的大小(不指定默认为当前文件夹,且不递归显示子目录)。

$ ls -l
total 1392
-rw-r--r-- 1 yansheng 197121 1420182 7月   4  2019 1.5.0-阿里巴巴Java开发手册(华山版).pdf
drwxr-xr-x 1 yansheng 197121       0 9月  23  2019 CollectHomework/
drwxr-xr-x 1 yansheng 197121       0 9月  23  2019 hello-word/# 人性化
$ ls -lh
total 1.4M
-rw-r--r-- 1 yansheng 197121 1.4M 7月   4  2019 1.5.0-阿里巴巴Java开发手册(华山版).pdf
drwxr-xr-x 1 yansheng 197121    0 9月  23  2019 CollectHomework/
drwxr-xr-x 1 yansheng 197121    0 9月  23  2019 hello-word/# 递归显示目录和文件
$ ls -Rlh
.:
total 1.4M
-rw-r--r-- 1 yansheng 197121 1.4M 7月   4  2019 1.5.0-阿里巴巴Java开发手册(华山版).pdf
drwxr-xr-x 1 yansheng 197121    0 9月  23  2019 CollectHomework/
drwxr-xr-x 1 yansheng 197121    0 9月  23  2019 hello-word/./CollectHomework:
total 204K
-rw-r--r-- 1 yansheng 197121  73K 9月  20  2019 CollectHomework-1.jpg
-rw-r--r-- 1 yansheng 197121 128K 9月  20  2019 CollectHomework-2.jpg./hello-word:
total 248K
-rw-r--r-- 1 yansheng 197121  54K 9月   6  2019 github-bootstrap语言识别情况.jpg
-rw-r--r-- 1 yansheng 197121  18K 9月   6  2019 github-hello-world1语言识别情况.jpg
-rw-r--r-- 1 yansheng 197121  27K 9月   6  2019 github-hello-world2语言识别情况.jpg
-rw-r--r-- 1 yansheng 197121 9.5K 9月   6  2019 github-hello-world语言识别情况.jpg
-rw-r--r-- 1 yansheng 197121  61K 9月   6  2019 github语言识别情况.jpg
-rw-r--r-- 1 yansheng 197121  51K 9月   2  2019 hello-world-github.png
-rw-r--r-- 1 yansheng 197121  13K 9月   2  2019 hello-world-github1.png

查看文件大小

du命令(推荐使用)

指定文件名即可:du -h filepath

$ du -h '1.5.0-阿里巴巴Java开发手册(华山版).pdf'
1.4M    1.5.0-阿里巴巴Java开发手册(华山版).pdf

ls命令

ls -l filepath:如果filepath是文件,显示的即为指定文件的大小。

$ ls -lh '1.5.0-阿里巴巴Java开发手册(华山版).pdf'
-rw-r--r-- 1 yansheng 197121 1.4M 7月   4  2019 1.5.0-阿里巴巴Java开发手册(华山版).pdf

stat命令

Display file or file system status.
显示文件或者文件系统的状态。(stat filepath:对文件夹无效)

# 默认:显示单位为b
$ stat '1.5.0-阿里巴巴Java开发手册(华山版).pdf'File: 1.5.0-阿里巴巴Java开发手册(华山版).pdfSize: 1420182         Blocks: 1388       IO Block: 65536  regular file
Device: 401a47b0h/1075464112d   Inode: 2814749767110487  Links: 1
Access: (0644/-rw-r--r--)  Uid: (197609/yansheng)   Gid: (197121/ UNKNOWN)
Access: 2020-04-02 22:58:23.764561800 +0800
Modify: 2019-07-04 16:34:18.386372100 +0800
Change: 2019-10-31 00:10:47.515478600 +0800Birth: 2020-04-02 22:58:23.730710200 +0800

wc命令

Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. A word is a non-zero-length sequence of characters delimited by white space.
显示文件的行、字、字节的数量。
-c, --bytes print the byte countswc -c filename:统计文件的字节数量。

$ wc -c '1.5.0-阿里巴巴Java开发手册(华山版).pdf'
1420182 1.5.0-阿里巴巴Java开发手册(华山版).pdf

总结

推荐使用du命令,因为显示的容量可以很直观,方便。


参考:https://blog.csdn.net/xiongyangg/article/details/54809810

Linux查看文件夹大小和文件大小的几种方法相关推荐

  1. linux 查看文件夹大小及文件大小

    一.查询文件夹大小 1.最简单的查看方法可以使用ls -ll.ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB.MB等为单位进行显示,这样比较直观一些. 2.通过命 ...

  2. linux 查看文件夹大小 du命令

    日志原文:http://blog.sohu.com/people/!a2VmYW5sb3ZleXVuaW5nQHNvaHUuY29t/159962486.html du -sh *   查看当前目录下 ...

  3. linux查看文件夹大小,ls-l显示不正确

    在linux中经常使用ls-l 或者ls -lht查看文件大小,但是文件列表中有目录的时候就会发现显示的文件夹大小和实际文件大小不对应,文件夹的大小很多都是相等的,其实这是因为ls-l命令显示的是文件 ...

  4. Linux查看文件夹大小du

    du命令参数详解见: http://baike.baidu.com/view/43913.htm 下面我们只对其做简单介绍: 查看linux文件目录的大小和文件夹包含的文件数   统计总数大小   d ...

  5. Linux查看文件夹大小的命令

    2019独角兽企业重金招聘Python工程师标准>>> 统计总数大小 du -sh xmldb/ du -sm * | sort -n //统计当前目录大小 并安大小 排序 du - ...

  6. linux查看文件夹下每个文件大小,linux查看当前文件夹下每个文件大小

    lua闭合函数 function count( ... ) return function( ... ) i = i+ return i end end local func = count(...) ...

  7. Linux查看文件夹大小的相关命令

    2019独角兽企业重金招聘Python工程师标准>>> http://hi.baidu.com/zwfec/blog/item/9b8b30f3471b5a47342acc5b.ht ...

  8. Linux查看文件夹的大小

    以此图为例,进行说明: Linux 查看文件夹的大小,不包含子目录和文件: du -sh 路径 例: du -sh test 结果: Linux 查看文件夹的大小,包含子目录,不包含文件: du -S ...

  9. linux 查看目录下文件、查看文件具体内容、查看文件夹大小

    linux 查看目录下文件.查看文件具体内容 查看目录下文件 查看文件具体内容 查看文件夹大小 查看文件夹下各文件大小 查看目录下文件 ls 查看目录下所有文件(不包含隐藏文件) ls -a 查看目录 ...

最新文章

  1. 搜索引擎利用机器学习排序
  2. Docker部署微服务详解
  3. 崂山白花蛇草水:旧款变爆款老字号“有预谋”
  4. java冗余_Java使用lombok消除冗余代码的方法步骤
  5. Linux配置ssh无密码验证,rsync
  6. GRE tunnel源码分析之发送流程
  7. gb2312编码在线转换_python基础学习—04字符串与编码
  8. 【Jetson-Nano】2.Tensorflow object API和Pytorch的安装
  9. [开源]430驱动的12864图形点阵LCD
  10. 『Material Design 入门学习笔记』前言
  11. extjs_10_自己定义combotree组件
  12. socket,ioctl获取ip
  13. ElasticSearch中Transient与Persistent的区别
  14. 【DB笔试面试755】在Oracle的DG中,RFS、LNSn、MRP、LSP进程的作用分别是什么?
  15. Mysql笔试+面试题积累(实时更新)
  16. 连接服务器显示凭据,连接云服务器时的凭据是什么意思
  17. 小程序接入h5页面_小程序与H5如何互相跳转
  18. 输出直角三角形图案-c++
  19. 数位 dp 相邻位数字差值的绝对值不能超过 2_维懂百科——绝对值编码器的“绝对式”的定义...
  20. 钉钉视频会议中的屏幕共享

热门文章

  1. 【数据结构之排序】-详解希尔排序
  2. bmp转mif c语言,【原创】bmp转mif、coe或hex软件发布及使用介绍
  3. 值得一看,阿里又杀疯了开源内部“M9”级别全彩版分布式实战笔记
  4. java国际化韩文_java国际化介绍+Demo
  5. svn服务器备份、还原、迁移一条龙教程
  6. 信息学奥赛一本通----1997:梦想
  7. 数据挖掘期末知识点总结
  8. Android面试:一个三非渣本的Android校招秋招之路,附答案
  9. 区块链真能成供应链金融的百世良医?
  10. Quartz所使用的表的说明