如何将包含文件的文件夹复制到 Unix/Linux 中的另一个文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14922562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I copy folder with files to another folder in Unix/Linux?
提问by user2080656
I am having some issues to copy a folder with files in that folder into another folder. Command cp -r
doesn't copy files in the folder.
我在将包含该文件夹中文件的文件夹复制到另一个文件夹时遇到了一些问题。命令cp -r
不会复制文件夹中的文件。
采纳答案by Pierre Salagnac
The option you're looking for is -R
.
您正在寻找的选项是-R
。
cp -R path_to_source path_to_destination/
- If
destination
doesn't exist, it will be created. -R
meanscopy directories recursively
. You can also use-r
since it's case-insensitive.- Note the nuances with adding the trailing
/
as per @muni764's comment.
- 如果
destination
不存在,它将被创建。 -R
是指copy directories recursively
。您也可以使用,-r
因为它不区分大小写。- 请注意
/
根据@muni764 的评论添加尾随的细微差别。
回答by cIph3r
Use:
用:
$ cp -R SRCFOLDER DESTFOLDER/
回答by Alex W
You are looking for the cp
command. You need to change directories so that you are outside of the directory you are trying to copy.
您正在寻找cp
命令。您需要更改目录,以便您位于要复制的目录之外。
If the directory you're copying is called dir1
and you want to copy it to your /home/Pictures
folder:
如果您正在复制的目录被调用dir1
并且您想将其复制到您的/home/Pictures
文件夹:
cp -r dir1/ ~/Pictures/
Linux is case-sensitive and also needs the /
after each directory to know that it isn't a file. ~
is a special character in the terminal that automatically evaluates to the current user's home directory. If you need to know what directory you are in, use the command pwd
.
Linux 区分大小写,并且还需要/
每个目录之后才能知道它不是文件。 ~
是终端中的一个特殊字符,它会自动评估当前用户的主目录。如果您需要知道您所在的目录,请使用命令pwd
.
When you don't know how to use a Linux command, there is a manual page that you can refer to by typing:
当您不知道如何使用 Linux 命令时,可以通过键入以下内容来参考手册页:
man [insert command here]
at a terminal prompt.
在终端提示下。
Also, to auto complete long file paths when typing in the terminal, you can hit Tabafter you've started typing the path and you will either be presented with choices, or it will insert the remaining part of the path.
此外,要在终端中输入时自动完成长文件路径,您可以Tab在开始输入路径后点击,您将看到选择,或者插入路径的其余部分。