首页 技术 正文
技术 2022年11月19日
0 收藏 642 点赞 4,263 浏览 2555 个字

在Linux中显示文件大小的时候,通常的做法是使用“ls -l”,显示的大小是文件的字节大小。

但是,如果文件比较大的话,显示起来不是特别易读,这个时候,可以使用“ls -lh”,就可以使用比较接近文件大小的单位显示文件的大小,如下:

[www.linuxidc.com@linux bin]$ ls -lh
total 565M
-rwxr-xr-x 1 billing_dx BILLING 1.1M Mar 10 18:56 AcctMgrService
-rw-r–r– 1 billing_dx BILLING  364 Mar 10 18:59 AcctMgrService.conf
-rw——- 1 billing_dx BILLING  11G Mar 13 18:37 core.22836
-rw-r–r– 1 billing_dx BILLING  410 Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING  39 Mar 10 18:57 go

使用“-h”参数时,会根据文件的大小选择显示的单位是“K”、“M”还是“G”。如果希望指定显示的单位,可以使用“–block-size”参数,如下:

[www.linuxidc.com@linux bin]$ ls -l
total 577724
-rwxr-xr-x 1 billing_dx BILLING    1103862 Mar 10 18:56 AcctMgrService
-rw-r–r– 1 billing_dx BILLING        364 Mar 10 18:59 AcctMgrService.conf
-rw——- 1 billing_dx BILLING 10947788800 Mar 13 18:37 core.22836
-rw-r–r– 1 billing_dx BILLING        410 Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING          39 Mar 10 18:57 go

[www.linuxidc.com@linux bin]$ ls -l –block-size=k 
total 577724K
-rwxr-xr-x 1 billing_dx BILLING    1078K Mar 10 18:56 AcctMgrService
-rw-r–r– 1 billing_dx BILLING        1K Mar 10 18:59 AcctMgrService.conf
-rw——- 1 billing_dx BILLING 10691200K Mar 13 18:37 core.22836
-rw-r–r– 1 billing_dx BILLING        1K Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING        1K Mar 10 18:57 go

[www.linuxidc.com@linux bin]$ ls -l –block-size=m
total 565M
-rwxr-xr-x 1 billing_dx BILLING    2M Mar 10 18:56 AcctMgrService
-rw-r–r– 1 billing_dx BILLING    1M Mar 10 18:59 AcctMgrService.conf
-rw——- 1 billing_dx BILLING 10441M Mar 13 18:37 core.22836
-rw-r–r– 1 billing_dx BILLING    1M Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING    1M Mar 10 18:57 go

[www.linuxidc.com@linux bin]$ ls -l –block-size=g
total 1G
-rwxr-xr-x 1 billing_dx BILLING  1G Mar 10 18:56 AcctMgrService
-rw-r–r– 1 billing_dx BILLING  1G Mar 10 18:59 AcctMgrService.conf
-rw——- 1 billing_dx BILLING 11G Mar 13 18:37 core.22836
-rw-r–r– 1 billing_dx BILLING  1G Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING  1G Mar 10 18:57 go

同哦过对比可以看到,使用  不同的单位显示的时候,使用的是进一法,所以一个1k的东西,使用G为单位显示的是,会显示为“1G”。所以,还是使用“-h”显示起来,更符合人的习惯。

下面是ls显示的相关描述:

[www.linuxidc.com@linux bin]$ man ls
LS(1)                            User Commands                          LS(1)

NAME
  ls – list directory contents

SYNOPSIS
  ls [OPTION]… [FILE]…

DESCRIPTION
  List  information  about the FILEs (the current directory by default).  Sort entries alphabetically if
  none of -cftuvSUX nor –sort.

Mandatory arguments to long options are mandatory for short options too.

-h, –human-readable
          with -l, print sizes in human readable format (e.g., 1K 234M 2G)

-k    like –block-size=1K

-l    use a long listing format

–block-size=SIZE
          use SIZE-byte blocks.  See SIZE format below

SIZE  may  be  (or  may  be  an  integer optionally followed by) one of following: KB 1000, K 1024, MB
  1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,102
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,578
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,426
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,198
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,833
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,916