如何以不同方式显示Linux文件大小?

One of the most asked questions about files in Linux is how can I list file sizes in different formats? In this post, we will look at different commands to get file sizes.

关于Linux中文件的最常见问题之一是如何列出不同格式的文件大小? 在本文中,我们将介绍不同的命令来获取文件大小。

ls命令 (ls Command)

ls command is a primary command to list and get information about files and directories in Linux. ls command can be used with -l parameter to get the size of files.

ls命令是用于列出和获取有关Linux中文件和目录信息的主要命令。 ls命令可与-l参数一起使用以获取文件的大小。

$ ls -l nmap-7.31.tgz
ls Command
ls Command
ls命令

We listed file nmap-7.31.tgz file size in byte but we can make the size information more readable by using -h option.

我们以字节为单位列出了nmap-7.31.tgz文件大小,但我们可以使用-h选项使大小信息更易读。

$ ls -lh nmap-7.31.tgz
ls Command
ls Command
ls命令

杜司令部(du Command)

du command is used to get disk usage.

du命令用于获取磁盘使用情况。

$ du nmap-7.31.tgz
du Command
du Command
杜司令部

We have simply listed the file without providing any parameter. Provided size is in KB. If we want to get a human-friendly result we can use the following.

我们仅列出了文件而未提供任何参数。 提供的大小以KB为单位。 如果我们想获得人类友好的结果,可以使用以下方法。

$ du -h nmap-7.31.tgz
du Command
du Command
杜司令部

stat命令(stat Command)

Stat command is used to get file system-related information about files and directories. Using stat with filename parameter will provide size information in byte mode too.

Stat命令用于获取有关文件和目录的文件系统相关信息。 将stat与filename参数一起使用也会以字节模式提供大小信息。

$ stat nmap-7.31.tgz
stat Command
stat Command
stat命令
LEARN MORE  How To Find and List Large Files and Directories In Linux?
了解更多如何在Linux中查找和列出大文件和目录?

翻译自: https://www.poftut.com/show-linux-file-size/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值