【问题标题】:What is the deference between 'ls -lh' and 'ls -si'? [closed]“ls -lt”和“ls -is”有什么区别? [关闭]
【发布时间】:2015-09-30 14:59:53
【问题描述】:

我已经执行了两个 cmets,但是两个输出的大小似乎不同。

ls -lh
total 147M
-rw------- 1 root root 3.4K Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root  247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root   54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 147M Sep 30 14:58 jdk-7u79-linux-x64.gz

ls -l --si
total 154M
-rw------- 1 root root 3.5k Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root  247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root   54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 154M Sep 30 14:58 jdk-7u79-linux-x64.gz

【问题讨论】:

  • 检查man ls怎么样?
  • StackOverflow 的权限是关于编程的问题。 ls 是一个不应在编程上下文中使用的工具(请参阅mywiki.wooledge.org/ParsingLs)。因此,这里不是主题。
  • 我投票结束这个问题,因为它不是关于编程的问题。

标签: linux shell


【解决方案1】:

如果您使用命令 man ls 检查 ls 的联机帮助页,您会看到以下内容:

   -l     use a long listing format
   -h, --human-readable
          with -l and/or -s, print human readable sizes (e.g., 1K 234M
          2G)
   -i, --inode
          print the index number of each file
   -s, --size
          print the allocated size of each file, in blocks

如您所见,每个参数只是定义了信息将显示在屏幕上的内容和方式。您看到的(大小差异)是-h--human-readable 命令,它将输出更多可读的文件大小,而不是总是打印字节。使用-s 将在您的硬盘上打印blocks 中的文件大小,这取决于文件系统的块大小。根据提供的信息,我会说您的文件系统具有1kb 块大小。所以文件的真实内容是3.4kb,但必须填满块,所以在你的磁盘上文件需要4kb4 blocks的空间。

【讨论】:

  • OP 询问 -h 和 --si 之间的区别。区别在于 -h 使用 base-2 大小计算而使用 base-10 前缀,而 --si 使用 base-10 计算和显示大小,这样更正确。
猜你喜欢
  • 1970-01-01
  • 2015-01-05
  • 2021-11-08
  • 1970-01-01
  • 2021-01-26
  • 2016-12-04
  • 2023-02-07
  • 1970-01-01
相关资源
最近更新 更多