有什么理由吗不是--sparse=always
每次调用时使用 use cp
?
info cp
说:
‘--sparse=WHEN’ A “sparse file” contains “holes”—a sequence of zero bytes that does not occupy any physical disk blocks; the ‘read’ system call reads these as zeros. This can both save considerable disk space and increase speed, since many binary files contain lots of consecutive zero bytes. By default, ‘cp’ detects holes in input source files via a crude heuristic and makes the corresponding output file sparse as well. Only regular files may be sparse. The WHEN value can be one of the following:
...
‘always’ For each sufficiently long sequence of zero bytes in the input file, attempt to create a corresponding hole in the output file, even if the input file does not appear to be sparse. This is useful when the input file resides on a file system that does not support sparse files (for example, ‘efs’ file systems in SGI IRIX 5.3 and earlier), but the output file is on a type of file system that does support them. Holes may be created only in regular files, so if the destination file is of some other type, ‘cp’ does not even try to make it sparse.
它还说:
[...] 使用以下别名,“cp”将使用文件系统支持的最小空间量。
alias cp='cp --reflink=auto --sparse=always'
为什么不是--sparse=always
默认的?
答案1
它不是默认的有几个原因,一是向后兼容性、性能,最后但并非最不重要的一点是最少惊喜原则。
我的理解是,当你启用这个选项时,会有CPU开销,这可能不一定是可以接受的,此外,向后兼容性也是关键。该cp
命令在没有情况下可靠地工作,它确实节省了一点空间,但现在,这确实可以忽略不计,至少在大多数情况下......
我认为您收到的评论还强调了其他原因。
最小惊喜原则意味着你不会不必要地改变某些东西,cp
已经存在了几十年,改变其默认行为会让许多退伍军人感到不安。