标签: coreutils

cp --no-target-directory 解释

问题:我需要一个简单的示例来说明如何使用cp --no-target-directory.

我确实在理解上遇到了一些困难cp --no-target-directory。我确实理解的解释mv --no-target-directory,但我真的无法想象将它用于 的方法cp

例如,当命令mv /tmp/source /tmp/dest成功时,不能保证/tmp/source已重命名为/tmp/dest/tmp/dest/source如果其他进程创建/tmp/dest为目录,则可以将其重命名为。但是,如果mv -T /tmp/source /tmp/dest成功,毫无疑问/tmp/source was renamed to/tmp/dest`。(来源

directory cp coreutils

13
推荐指数
2
解决办法
2万
查看次数

`du -s .` 和 `du -hs .` 给出不同的结果(在 OS X 上)

有和没有的区别-h应该只是人类可读的单位,对吧?

那么显然没有...

$ du -s .
74216696    .
$ du -hs .
 35G    .
Run Code Online (Sandbox Code Playgroud)

或者也许我错了,结果du -s .不在 KB 中?

osx coreutils

12
推荐指数
1
解决办法
4147
查看次数

`cp --sparse=always` 有什么缺点吗?

是否有任何理由不在--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 …
Run Code Online (Sandbox Code Playgroud)

cp coreutils sparse-files

12
推荐指数
1
解决办法
5592
查看次数

tac --before 的解释

-b, --before

分隔符附加到文件中它前面的记录的开头。

我无法理解以下输出:

$ echo -e "Hello\nNew\nWorld\n!" > file
$ tac file
!
World
New
Hello
$ tac -b file


!
World
NewHello
Run Code Online (Sandbox Code Playgroud)

为什么New和之间没有换行符Hello

coreutils tac

12
推荐指数
2
解决办法
979
查看次数

gnu coreutils 排序坏了吗?

考虑以下输入进行排序:

cat > foo <<EOM
D,,5014978
DD,,25
D,I,1972765530
D,Y,4223624
-,Y,71285059
YA,I,2
EOM
Run Code Online (Sandbox Code Playgroud)

现在尝试运行 sort foo

在我的任何 linux 机器(gnu coreutils 版本 6.9-7.4)上尝试此操作时,输出未排序。在 cygwin (gnu coretuils 8.5) 下运行时,输出已排序。注释?

bash coreutils sort

11
推荐指数
1
解决办法
1191
查看次数

有没有办法表达:`--link` 或回退到 cp 中的普通副本(来自 GNU coreutils)?

有没有办法告诉cp--link(即创建硬链接),但回落的情况下,我试图设备间的硬链接?设备间链接是不可能的,并且会导致cp失败。

我问的原因是因为我想在 a 中使用它,GNUmakefile并且更喜欢可读的命令行而不是一些复杂而冗长的命令行(或函数,就此而言)。

问题是针对 GNU coreutils(7.4 和 8.13)。

注意:现在的解决方法类似于(GNU make recipe 语法):

cp -fl $^ $@ || cp -f $^ $@
Run Code Online (Sandbox Code Playgroud)

这当然会在设备间链接的情况下给出虚假的错误消息,尽管在第二次cp调用时成功。此外,然后它会被扩展(毕竟源表单看起来可读)它不会再可读了。

hard-link cp coreutils

11
推荐指数
1
解决办法
270
查看次数

转置(交换行和列)文本文件的命令

当前是否有一个通用命令可以“旋转”输入。

例如

#labeled.file
name: bob
title: code monkey

name: joe
title: pointy haired
Run Code Online (Sandbox Code Playgroud)

转换为:

name title
bob  code monkey
joe  pointy haired
Run Code Online (Sandbox Code Playgroud)

反之亦然

linux command-line coreutils text-processing

11
推荐指数
1
解决办法
6万
查看次数

为什么 mv 不能处理目标中存在的同名目录?

mv 无法将目录移动到具有同名目录的目标:

$ mv fortran/ imperative_PLs/
mv: cannot move ‘fortran/’ to ‘imperative_PLs/fortran’: Directory not empty
Run Code Online (Sandbox Code Playgroud)
  1. 为什么mv在这种情况下不起作用?这可以从系统调用中解释mv吗?(比较rsync哪个可以)

  2. 为什么mv设计在这种情况下不起作用?理由或要点是什么?

linux coreutils mv

11
推荐指数
3
解决办法
3万
查看次数

哪个版本的 X 引入了特性 Y?

A big part of my daily job is developing software for use on machines with different versions of the same software, like bash, find, and grep. When encountering a feature which would be useful for example to simplify code, it is important to know whether this feature is available in the oldest installed tools. For critical stuff, it would also be useful to know whether this feature was new or has existed for years in the oldest …

coreutils

10
推荐指数
1
解决办法
903
查看次数

如果目标存在,则使 cp 返回错误值

cp如果目标文件已经存在,有没有办法让(来自 Linux 上的 GNU coreutils)返回一个非零值?
或者是否有任何其他常用的小实用程序并提供此功能?

这在 shell 脚本中很有用,可以自动复制文件而不会意外丢失任何内容,也无需用户交互。通过将副本与原件进行比较可以获得类似的结果,但我希望有一个更简单的解决方案。

cp shell-script coreutils

10
推荐指数
2
解决办法
8565
查看次数