失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > unix和linux命令_Linux / UNIX中的cp命令

unix和linux命令_Linux / UNIX中的cp命令

时间:2018-11-11 11:45:10

相关推荐

unix和linux命令_Linux / UNIX中的cp命令

unix和linux命令

In this guide, we focus on cp command in Linux/Unix systems. cp command – short for copy – is a command used for copying files and directories in Linux. It’s a command that is widely used both by Linux beginners and seasoned experts on a regular basis. Let’s dive in and see how this command is used.

在本指南中,我们重点介绍Linux / Unix系统中的cp命令。 cp命令–复制的缩写–是用于在Linux中复制文件和目录的命令。 这是Linux初学者和经验丰富的专家定期广泛使用的命令。 让我们深入看看如何使用此命令。

Linux cp命令示例 (Linux cp command example)

The basic command structure of cp command is as follows:

cp命令的基本命令结构如下:

$ cp [options] source dest

Let’s look at some examples of using cp command to copy files and folders in Linux.

让我们看一些在Linux中使用cp命令复制文件和文件夹的示例。

将文件从当前目录复制到子目录 (Copy a file from current directory to subdirectory)

To copy a file from the present working directory to a subdirectory use the syntax below:

要将文件从当前工作目录复制到子目录,请使用以下语法:

$ cp file directory

Example

For example, to copy a filefile1.txtto a sub directory calleddataexecute thecpcommand as follows. Later use thelscommand to verify the existence of the file in the directory.

例如,要将文件file1.txt复制到名为data的子目录,请执行cp命令,如下所示。 以后使用ls命令来验证目录中文件的存在。

$ cp file1.txt data

Sample output

样品输出

将文件从当前目录复制到绝对目标路径 (Copy a file from current directory to an absolute destination path)

To copy a file from the present working directory to a different destination directory or absolute path, use the syntax below.

要将文件从当前工作目录复制到其他目标目录或绝对路径,请使用以下语法。

$ cp file /path/to/directory

Example

$ cp file1.txt /home/james/

Output

输出量

将文件从绝对源路径复制到绝对路径 (Copy a file from absolute source path to an absolute path)

To copy a file(s) from a different file path to another absolute path use the syntax:

要将文件从其他文件路径复制到另一个绝对路径,请使用以下语法:

cp /path/to/source/file /path/to/destination/directory

Example

$ cp /home/james/file1.txt /opt/data

Sample output

样品输出

复制多个文件 (Copy multiple files)

Linux cp command also allows you to copy more than one file at a go using the syntax below.

Linux cp命令还允许您使用以下语法一次复制多个文件。

$ cp file1 file2 .... /path/to/directory

Example

$ cp file1.txt file2.txt file3.txt /home/james/

Sample output

样品输出

复制带有详细输出的文件 (Copy file with verbose output)

To display verbose output, use the-vflag as shown.

要显示详细的输出,请使用-v标志,如图所示。

cp -v file1.txt file2.txt /home/james

Sample output

样品输出

交互式复制文件 (Copy files interactively)

To copy files interactively i.e to provoke a prompt from the Linux shell, use the-iflag as shown.

要以交互方式复制文件,即从Linux Shell引起提示,请使用-i标志,如图所示。

$ cp -i file1.txt /home/james

Sample output

样品输出

复制与某个文件扩展名关联的文件 (Copy files associated with a certain file extension)

If you wish to copy a number of files with the same file extension, say.txtor.pdffollow the example below.

如果您希望复制多个具有相同文件扩展名的文件,请按照以下示例说.txt.pdf

$ cp *.txt /home/james

递归复制Linux目录 (Linux Copy Directory Recursively)

If you want to copy a directory alongside all its contents, use the-Rattribute followed by the directory name as shown.

如果要复制目录及其所有内容,请使用-R属性,后跟目录名称,如图所示。

$ cp -R data /home/james

Sample output

样品输出

To copy the contents of a directory but not the directory itself, run the command as follows.

要复制目录的内容而不是目录本身,请按以下方式运行命令。

$ cp -R data/* /home/james

Sample output

样品输出

Linux man cp (Linux man cp)

We can runman cpcommand to look at the documentation of cp command. This is useful to find out the right options to use with the cp command.

我们可以运行man cp命令来查看man cp命令的文档。 这对于找出与cp命令一起使用的正确选项很有用。

man cp

Sample output

样品输出

摘要 (Summary)

Linux cp command helps us in copying files and folders easily. It’s one of the most used commands. The man page of cp command is very helpful in finding the suitable options to use.

Linux cp命令可帮助我们轻松复制文件和文件夹。 这是最常用的命令之一。 cp命令的手册页对找到合适的选项很有帮助。

翻译自: /26120/cp-command-in-linux-unix

unix和linux命令

如果觉得《unix和linux命令_Linux / UNIX中的cp命令》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。