我已经测试了该cp
命令,它只会复制单个文件。例如,我输入cp
了确切的文件名,然后输入了目录并复制了文件。但是,当我输入目录和目标目录时,计算机上没有任何变化。我以为cp
应该复制目录中的内容。
我已经多次尝试过这个。
Zuk*_*uko 15
当你不带任何参数使用cp 时,它默认复制文件如下
cp sourcefile destinationLocation
#will copy sourcefile to the specified destinationLocation
Run Code Online (Sandbox Code Playgroud)
但是如果你想复制一个目录,你需要像这样指定递归参数
cp -R dir1 dir2 #copies dir1 to dir2
cp -R dir dir2 dir3 #copies dir1 & dir2 to dir3
Run Code Online (Sandbox Code Playgroud)
理想情况下,您可以将任意数量的文件指定到一个目的地,所有文件都用空格分隔。然而,这在下面复制了一个目录及其权限
sudo cp -rp /home/me /media/backup/me
-p same as --preserve=mode,ownership,timestamps
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用 rsync
sudo rsync -a /home/me/ /media/backup/me/
-a, --archive
Note that -a does not preserve hardlinks, because finding multiply-linked
files is expensive. You must separately specify -H.
Run Code Online (Sandbox Code Playgroud)
并且在使用 rsync 复制时请不要忘记尾部斜杠。通过键入man cp或man rsync查看每个命令的手册页,了解在终端上使用它们的选项