Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.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-l加起来,列出的文件总大小是多少?_Linux_Shell_Unix_Command_Prompt - Fatal编程技术网

Linux 为什么';";总数;从ls-l加起来,列出的文件总大小是多少?

Linux 为什么';";总数;从ls-l加起来,列出的文件总大小是多少?,linux,shell,unix,command,prompt,Linux,Shell,Unix,Command,Prompt,为什么ls-l输出中的total打印为64,而不是26078,这是列出的所有文件的总和 $ ls -l ~/test/ls total 64 -rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg -rw-r--r-- 1 root root 2562 Oct 5 2004 a2ps-site.cfg drwxr-xr-x 4 root root 4096 Feb 2 200

为什么
ls-l
输出中的total打印为
64
,而不是
26078
,这是列出的所有文件的总和

    $ ls -l ~/test/ls
    total 64
    -rw-r--r--   1 root root   15276 Oct  5  2004 a2ps.cfg
    -rw-r--r--   1 root root    2562 Oct  5  2004 a2ps-site.cfg
    drwxr-xr-x   4 root root    4096 Feb  2  2007 acpi
    -rw-r--r--   1 root root      48 Feb  8  2008 adjtime
    drwxr-xr-x   4 root root    4096 Feb  2  2007 alchemist

您可以在平台的
ls
文档中找到该行的定义。对于
coreutils
ls
(在许多Linux系统上都可以找到),可以通过
info coreutils-ls
找到信息:

对于列出的每个目录,在文件前面加一行 `total BLOCKS',其中BLOCKS是所有磁盘的总磁盘分配 该目录中的文件


即列出的文件使用的文件系统块(包括间接块)的总数。如果您在相同的文件上运行ls-s,并对报告的数字求和,您将得到相同的数字。

仅提一下-您可以使用-h(ls-lh)将其转换为人类可读的格式。

公式:该数字是多少? 总int=每个文件的(物理块使用中)*物理块大小/ls块大小之和)

其中:

  • ls\u block\u size
    是一个任意环境变量(通常为512或1024字节),可通过
    --block size=
    标志在
    ls
    上,
    POSIXLY\u CORRECT=1
    GNU 环境变量(获取512字节单位),或使用
    -k
    标志强制 1kB单位
  • physical_block_size
    是内部块接口的操作系统相关值,该接口可能连接到底层硬件,也可能不连接到底层硬件。该值通常为512b或1k,但完全取决于操作系统。它可以通过
    stat
    fstat
    上的
    %B
    值显示请注意,此值(几乎总是)与现代存储设备上的物理块数无关。
为什么这么困惑? 这个数字与任何物理或有意义的指标都是完全分离的。许多初级程序员没有使用或的经验。此外,关于这一特定主题的现有文件几乎不存在

术语“块大小”的不连续性和模糊性是由于许多不同的度量容易混淆,以及围绕磁盘访问的相对深入的抽象层次造成的

冲突信息的示例:
du
(或
ls-s
)与
stat
在项目文件夹中运行
du*
会产生以下结果:(注意:
ls-s
返回相同的结果。)

总计:2+2+1+3+3+5+26+4+2+14=62个区块

然而,当运行
stat
时,我们会看到一组不同的值。在同一目录中运行
stat
,将产生:

dactyl:~/p% stat * --printf="%b\t(%B)\t%n: %s bytes\n"
3       (512)   check.cc: 221 bytes
3       (512)   check.h: 221 bytes
1       (512)   DONE: 0 bytes
5       (512)   Makefile: 980 bytes
6       (512)   memory.cc: 2069 bytes
10      (512)   memory.h: 4219 bytes
51      (512)   p2: 24884 bytes
8       (512)   p2.cc: 2586 bytes
3       (512)   stack.cc: 334 bytes
28      (512)   stack.h: 13028 bytes
总计:3+3+1+5+6+10+51+8+3+28=118个区块

注意:您可以使用命令
stat*--printf=“%b\t(%b)\t%n:%s bytes\n”
>输出(按顺序)块的数量(以帕伦为单位)这些块的大小 块、文件名和大小(以字节为单位),如上所示

外卖有两件重要的事情:

  • stat
    报告上述公式中使用的
    物理块
    物理块
    大小。请注意,这些值基于操作系统接口
  • du
    提供了一个公认的相当准确的物理磁盘利用率估计值

以下是上面目录的
ls-l
,仅供参考:

dactyl:~/p% ls -l
**total 59**
-rw-r--r--. 1 dhs217 grad   221 Oct 16  2013 check.cc
-rw-r--r--. 1 dhs217 grad   221 Oct 16  2013 check.h
-rw-r--r--. 1 dhs217 grad     0 Oct 16  2013 DONE
-rw-r--r--. 1 dhs217 grad   980 Oct 16  2013 Makefile
-rw-r--r--. 1 dhs217 grad  2069 Oct 16  2013 memory.cc
-rw-r--r--. 1 dhs217 grad  4219 Oct 16  2013 memory.h
-rwxr-xr-x. 1 dhs217 grad 24884 Oct 18  2013 p2
-rw-r--r--. 1 dhs217 grad  2586 Oct 16  2013 p2.cc
-rw-r--r--. 1 dhs217 grad   334 Oct 16  2013 stack.cc
-rw-r--r--. 1 dhs217 grad 13028 Oct 16  2013 stack.h

这根本不是事实。示例:
/bin/ls-s
->
总计15 2文件名3文件名2 3文件名3文件名4 2文件名5 2文件名6 2文件名8 2文件名9
我不知道你在哪个系统上,但对我来说,这是真的。示例:@Jakob发布了一个完整的答案,看一看,让我知道这是否能澄清问题。这在Git bash for Windows中是不正确的。我修改了这个问题,希望它能重新打开。希望你能投赞成票……有趣的是,我的系统上的
manls
没有提到这一行,但是
info coreutils
提到了这一行。为什么
man ls
info coreutils ls
对同一命令有不同的信息?为什么
ls
不记录一次?为同一个命令提供两个不同的文档似乎是为失败而设置的。
info
coreutils文档通常比手册页更详细。这就是为什么他们在每个手册页的末尾都有一个便条,让你参考信息部分了解更多细节。啊。我执行了
info-ls
,它给出了与
info-coreutils-ls
相同的输出。参数
coreutils
有什么作用?@Mat我修改了这个问题,希望能重新打开。希望你能投赞成票…为什么这个问题是封闭的?我不认为这是“离题”,多么武断的决定啊。@刘清远,因为这是典型的人类问题。这一新的SO规则正在惩罚人类的思维。将当前的SO规则与有多少平面人类问题以及这些年来他们产生了多少次投票进行比较。如果人类的问题得到了人类的答案,任何人都可以联系起来并从中学习。这个问题有138票,答案有97票,47票,27票,19票。显然很有帮助@刘庆元第二,这个q显示了接口中的多个故障。1)
-l
设置为以几乎没有人需要的神秘方式显示总计。但是你99.9%的时间都需要lh。那么为什么不在MB中设置
-l
,在块中设置
-lalmostnevereded
?2)
--help
3)man4)不要浪费时间:查看
--help
,转到
man
,记住
信息,阅读更多信息。(如果您使用的是windows portable bash,则不包括人员和信息,
dactyl:~/p% ls -l
**total 59**
-rw-r--r--. 1 dhs217 grad   221 Oct 16  2013 check.cc
-rw-r--r--. 1 dhs217 grad   221 Oct 16  2013 check.h
-rw-r--r--. 1 dhs217 grad     0 Oct 16  2013 DONE
-rw-r--r--. 1 dhs217 grad   980 Oct 16  2013 Makefile
-rw-r--r--. 1 dhs217 grad  2069 Oct 16  2013 memory.cc
-rw-r--r--. 1 dhs217 grad  4219 Oct 16  2013 memory.h
-rwxr-xr-x. 1 dhs217 grad 24884 Oct 18  2013 p2
-rw-r--r--. 1 dhs217 grad  2586 Oct 16  2013 p2.cc
-rw-r--r--. 1 dhs217 grad   334 Oct 16  2013 stack.cc
-rw-r--r--. 1 dhs217 grad 13028 Oct 16  2013 stack.h