如何在Linux中查看文件和目录的大小?如果使用df -m,那么它会显示所有目录在顶层的大小,但是,对于目录内的目录和文件,我如何检查大小?


当前回答

您所需要的只是-l和——block-size标志

工作目录下所有文件和目录的大小(以mb为单位)

ls -l --block-size=M

工作目录下所有文件和目录的大小(单位:gb)

ls -l --block-size=G

指定文件或目录的大小

ls -l --block-size=M my_file.txt
ls -l --block-size=M my_dir/

ls——帮助 -l使用长列表格式 ——block-size=SIZE:在打印之前按SIZE缩放大小;例如, '——block-size=M'以。为单位打印大小 1048576个字节;参见下面的SIZE格式 “SIZE”为可选单位,取值为整型。例如:10M为10*1024*1024。 单位为K, M, G, T, P, E, Z, Y(1024的幂)或KB, MB,… (1000的幂)。


其他回答

ls -sh video.mp4 | sed s/video.mp4//g

输出, 5.6米

进入所选目录并执行:

$ du -d 1 -h

地点:

-d 1 is the depth of the directories

-h is the human-readable option

你会看到:

0   ./proc
8.5M    ./run
0   ./sys
56M ./etc
12G ./root
33G ./var
23M ./tmp
3.2G    ./usr
154M    ./boot
26G ./home
0   ./media
0   ./mnt
421M    ./opt
0   ./srv
2.6G    ./backups
80G .

你可以在Linux中使用ls -sh,也可以进行排序 你需要去目录,在那里你想检查文件的大小

您所需要的只是-l和——block-size标志

工作目录下所有文件和目录的大小(以mb为单位)

ls -l --block-size=M

工作目录下所有文件和目录的大小(单位:gb)

ls -l --block-size=G

指定文件或目录的大小

ls -l --block-size=M my_file.txt
ls -l --block-size=M my_dir/

ls——帮助 -l使用长列表格式 ——block-size=SIZE:在打印之前按SIZE缩放大小;例如, '——block-size=M'以。为单位打印大小 1048576个字节;参见下面的SIZE格式 “SIZE”为可选单位,取值为整型。例如:10M为10*1024*1024。 单位为K, M, G, T, P, E, Z, Y(1024的幂)或KB, MB,… (1000的幂)。


使用ls命令带-h参数:[root@hots19 etc]# ls -lh H:供人阅读。

Exemple: 
    [root@CIEYY1Z3 etc]# ls -lh
    total 1.4M
    -rw-r--r--.  1 root   root      44M Sep 15  2015 adjtime
    -rw-r--r--.  1 root   root     1.5K Jun  7  2013 aliases
    -rw-r--r--   1 root   root      12K Nov 25  2015 aliases.db
    drwxr-xr-x.  2 root   root     4.0K Jan 11  2018 alternatives
    -rw-------.  1 root   root      541 Jul  8  2014 anacrontab
    -rw-r--r--.  1 root   root      55M Sep 16  2014 asound.conf
    -rw-r--r--.  1 root   root       1G Oct  6  2014 at.deny