如何将包含文件的文件夹复制到Unix / Linux中的另一个文件夹? [关闭]

本文翻译自:How do I copy folder with files to another folder in Unix/Linux? [closed]

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不会复制文件夹中的文件。


#1楼

参考:https://stackoom.com/question/10c2U/如何将包含文件的文件夹复制到Unix-Linux中的另一个文件夹-关闭


#2楼

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. 如果destination不存在,则将创建它。
  • -R means copy directories recursively . -R表示copy directories recursively You can also use -r since it's case-insensitive. 您也可以使用-r因为它不区分大小写。
  • Note the nuances with adding the trailing / as per @muni764's comment . 请注意添加尾随/根据@ muni764的评论的细微差别。

#3楼

使用:

$ cp -R SRCFOLDER DESTFOLDER/

#4楼

You are looking for the cp command. 您正在寻找cp命令。 You need to change directories so that you are outside of the directory you are trying to copy. 您需要更改目录,以便您不在要复制的目录之外。 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. Linux是大小写敏感的,还需要/每个目录后,知道这是不是一个文件。 ~ 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 . 如果您需要知道自己所在的目录,请使用命令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 Tab after 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键,然后您将看到选项,或者它将插入路径的剩余部分。

发布了0 篇原创文章 · 获赞 73 · 访问量 55万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105286716