Linux查看文件夹大小和文件大小的几种方法

您所在的位置:网站首页 linux快速查看文件夹大小 Linux查看文件夹大小和文件大小的几种方法

Linux查看文件夹大小和文件大小的几种方法

2024-06-16 14:54| 来源: 网络整理| 查看: 265

文章目录 查看文件夹大小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开发手册(华山版).pdf Size: 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 +0800 Birth: 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 counts,wc -c filename:统计文件的字节数量。

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

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

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



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3