问题:我需要一个简单的示例来说明如何使用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`。(来源)
有和没有的区别-h应该只是人类可读的单位,对吧?
那么显然没有...
$ du -s .
74216696 .
$ du -hs .
35G .
Run Code Online (Sandbox Code Playgroud)
或者也许我错了,结果du -s .不在 KB 中?
是否有任何理由不在--sparse=always每次调用时使用 use cp?
info cp 说:
Run Code Online (Sandbox Code Playgroud)‘--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 …
-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?
考虑以下输入进行排序:
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) 下运行时,输出已排序。注释?
有没有办法告诉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调用时成功。此外,然后它会被扩展(毕竟源表单看起来可读)它不会再可读了。
当前是否有一个通用命令可以“旋转”输入。
例如
#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)
反之亦然
mv 无法将目录移动到具有同名目录的目标:
$ mv fortran/ imperative_PLs/
mv: cannot move ‘fortran/’ to ‘imperative_PLs/fortran’: Directory not empty
Run Code Online (Sandbox Code Playgroud)
为什么mv在这种情况下不起作用?这可以从系统调用中解释mv吗?(比较rsync哪个可以)
为什么mv设计在这种情况下不起作用?理由或要点是什么?
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 …
cp如果目标文件已经存在,有没有办法让(来自 Linux 上的 GNU coreutils)返回一个非零值?
或者是否有任何其他常用的小实用程序并提供此功能?
这在 shell 脚本中很有用,可以自动复制文件而不会意外丢失任何内容,也无需用户交互。通过将副本与原件进行比较可以获得类似的结果,但我希望有一个更简单的解决方案。
coreutils ×10
cp ×4
linux ×2
bash ×1
command-line ×1
directory ×1
hard-link ×1
mv ×1
osx ×1
shell-script ×1
sort ×1
sparse-files ×1
tac ×1