为什么有些 GNU Coreutils 命令有-T/--no-target-directory选项?似乎它所做的一切都可以使用.传统 Unix 目录层次结构中的(自点)语义来实现。
考虑:
cp -rT /this/source dir
Run Code Online (Sandbox Code Playgroud)
该-T选项可防止副本创建dir/source子目录。而是/this/source被标识dir并相应地在树之间映射内容。因此,例如/this/source/foo.c转到dir/foo.c等等,而不是到dir/source/foo.c。
但这可以很容易地完成,而无需-T使用以下选项:
cp -r /this/source/. dir # Probably worked fine since dawn of Unix?
Run Code Online (Sandbox Code Playgroud)
从语义上讲,尾随点组件被复制为 的子级dir,但当然该“子级”已经存在(因此不必创建)并且实际上是dir它本身,因此效果是用/this/path标识的dir。
如果当前目录是目标,它工作正常:
cp -r /this/tree/node/. . # node's children go to current dir
Run Code Online (Sandbox Code Playgroud)
有什么东西你只能用-T它来合理化它的存在吗?(除了对未实现点目录的操作系统的支持,文档中未提及的基本原理。)
上面的点技巧是否不能解决 GNU 信息文档中提到的相同竞争条件-T?
我一直在考虑停止在我的 Linux 系统上使用 GNU Coreutils,但老实说,与许多其他 GNU 组件不同,我想不出任何替代品(在 Linux 上)。GNU coreutils 有哪些替代品?我需要不止一个包裹吗?该项目的链接是必须的,命名发行包的奖励积分。
另外请不要建议,除非你知道它们在 Linux 上工作,并且可以参考说明。我怀疑我很快就会切换内核,而且我太懒了,除了简单的./configure; make; make install. 我当然不会为了它而破解 C。
警告:如果您的发行版使用 coreutils,删除它们可能会破坏发行版的运行方式。然而,不让它们成为你$PATH不应该破坏的东西,因为大多数脚本应该使用绝对路径。
我刚刚切换到 Macbook Air。我安装的zsh使用自制的,但是当我在使用一些代码,我(原本).zshrc,我得到一个错误说.dircolors was not found。
下面是有问题的代码:
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current …Run Code Online (Sandbox Code Playgroud) 我正在浏览 coreutils 中包含的文件列表,并且我能够想出一个示例,说明我如何亲自使用除 ptx 之外提供的所有命令。你能举出一两个(或三个)使用 ptx 的例子吗?用例越多样化越好。
$ apropos ptx
ptx(1) - produce a permuted index of file contents
Run Code Online (Sandbox Code Playgroud) 来自man touch:
-f (ignored)
Run Code Online (Sandbox Code Playgroud)
但我不明白什么叫忽略。
我试过以下:
$ ls -l file
-rw-rw-r-- 1 pandya pandya 0 Mar 20 16:17 file
Run Code Online (Sandbox Code Playgroud)
$ touch -f file
$ ls -l file
-rw-rw-r-- 1 pandya pandya 0 Mar 20 16:18 file
Run Code Online (Sandbox Code Playgroud)
并注意到尽管 -f.
所以,我想知道-f它代表什么,或者它有什么作用。
查看GNU Coreutils,我发现了factor我以前从未注意到的命令。
阅读手册页:
打印每个指定整数 NUMBER 的质因数。如果在命令行上没有指定,则从标准输入中读取它们。
有实际用途factor,还是只是一个演示/玩具包?
所以我有一个包含我的一些配置文件的 repo,我正在尝试创建一个makefile将它们安装在 homedir 中。我遇到的问题是,当我直接在 bash 中运行以下命令时
install -m 755 -d ~/path/to/dotfilesDir/ ~/
Run Code Online (Sandbox Code Playgroud)
似乎什么也没有发生
install -m 755 ~/path/to/dotfilesDir/{file1,file2,...} ~/
Run Code Online (Sandbox Code Playgroud)
按预期工作。
为什么第一个(更简单和更清洁)的解决方案不起作用?
cp 是一个非常流行的 Linux 工具,由 GNU 基金会的 coreutils 团队维护。
默认情况下,具有相同名称的文件将被覆盖,如果用户想要更改此行为,他们可以添加--no-clobber到他们的复制命令中:
Run Code Online (Sandbox Code Playgroud)-n, --no-clobber do not overwrite an existing file (overrides a previous -i option)
为什么不是这样的--no-overwrite?
我编写了以下脚本来测试 Python 排序功能的速度:
from sys import stdin, stdout
lines = list(stdin)
lines.sort()
stdout.writelines(lines)
Run Code Online (Sandbox Code Playgroud)
然后,我将其与sort包含 1000 万行的文件上的 coreutils命令进行了比较:
$ time python sort.py <numbers.txt >s1.txt
real 0m16.707s
user 0m16.288s
sys 0m0.420s
$ time sort <numbers.txt >s2.txt
real 0m45.141s
user 2m28.304s
sys 0m0.380s
Run Code Online (Sandbox Code Playgroud)
内置命令使用了所有四个 CPU(Python 只使用了一个),但运行时间大约是其 3 倍!是什么赋予了?
我使用的是 Ubuntu 12.04.5(32 位)、Python 2.7.3 和sort8.13
在查找名称中带有“\”的文件的校验和时,为什么 md5sum 在校验和前面加上“\”?
$ md5sum /tmp/test\\test
\d41d8cd98f00b204e9800998ecf8427e /tmp/test\\test
Run Code Online (Sandbox Code Playgroud)
每个其他实用程序也是如此。