如何将带有文件的文件夹复制到Unix/Linux中的另一个文件夹?

时间:2021-12-29 20:20:47

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

3 个解决方案

#1


1278  

The option you're looking for is -R.

你要找的选项是-R。

cp -R source destination/

If destination doesn't exist, it will be created.

如果目标不存在,它将被创建。

-R means copy directories recursively. You can also use -r since it's case-insensitive.

-R是递归复制目录。也可以使用-r,因为它不区分大小写。

#2


338  

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. If the directory you're copying is called dir1 and you want to copy it to your /home/Pictures folder:

您正在寻找cp命令。您需要更改目录,以便您在要复制的目录之外。如果你要复制的目录是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 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,然后显示选项,或者它将插入路径的其余部分。

#3


82  

Use:

使用:

$ cp -R SRCFOLDER DESTFOLDER/

#1


1278  

The option you're looking for is -R.

你要找的选项是-R。

cp -R source destination/

If destination doesn't exist, it will be created.

如果目标不存在,它将被创建。

-R means copy directories recursively. You can also use -r since it's case-insensitive.

-R是递归复制目录。也可以使用-r,因为它不区分大小写。

#2


338  

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. If the directory you're copying is called dir1 and you want to copy it to your /home/Pictures folder:

您正在寻找cp命令。您需要更改目录,以便您在要复制的目录之外。如果你要复制的目录是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 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,然后显示选项,或者它将插入路径的其余部分。

#3


82  

Use:

使用:

$ cp -R SRCFOLDER DESTFOLDER/