Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux ';ls-lh和x27;和';ls-si';?_Linux_Shell - Fatal编程技术网

Linux ';ls-lh和x27;和';ls-si';?

Linux ';ls-lh和x27;和';ls-si';?,linux,shell,Linux,Shell,我已经执行了这两个注释,但两个输出中的大小似乎不同 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 14

我已经执行了这两个注释,但两个输出中的大小似乎不同

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

如果您使用命令
manls
检查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
将打印硬盘上
块中的文件大小,这取决于文件系统的块大小。根据提供的信息,我想说您的文件系统具有
1kb
块大小。因此,文件的实际内容将是
3.4kb
,但必须填满块,因此在您的磁盘上,文件需要
4kb
4块空间。

手册页说
-s
意味着“以块为单位打印每个文件的分配大小”。假设块大小为1KB,文件大小为3.4K。该文件将需要4个块,而任何小于1KB的文件仍然需要一个1KB的块

但假设您的块大小是4KB……在这种情况下,任何小于4KB的块都需要一个4KB的块。这可能就是你在这里看到的

您可以使用
tune2fs
工具进行检查。例如:

# tune2fs -l /dev/tank/root | grep -i 'block size'
Block size:               4096

这显示了4096字节(例如4KB)的块大小,这可能是默认值,因为我在创建文件系统时没有指定任何自定义参数。

检查
man ls
怎么样?StackOverflow的权限是关于编程的问题
ls
是一种不应在编程环境中使用的工具(请参阅)。因此,这不是一个热门话题。我投票将这个问题作为离题来结束,因为这不是一个关于编程的问题。