Home  >  Article  >  Operation and Maintenance  >  How to copy files under linux

How to copy files under linux

王林
王林Original
2020-10-22 11:55:5229176browse

How to copy files under Linux: You can use the cp command to copy files, such as [cp cangls /tmp/], which means copying the cangls file to the tmp directory. The cp command is mainly used to copy files and directories, and it can also copy the entire directory.

How to copy files under linux

cp command is mainly used to copy files and directories. With certain options, you can also copy the entire directory and compare the old and new files of the two files. Be upgraded and other functions.

(Recommended tutorial: linux video tutorial)

The basic format of the cp command is as follows:

[root@localhost ~]# cp [选项] 源文件 目标文件

Options:

How to copy files under linux

Example:

cp command can copy both files and directories. Let’s first take a look at how to copy files, for example:

[root@localhost ~]# touch cangls
#建立源文件
[root@localhost ~]# cp cangls /tmp/
#把源文件不改名复制到 /tmp/ 目录下
如果需要改名复制,则命令如下:
[root@localhost ~]# cp cangls /tmp/bols
#改名复制

If a file with the same name already exists in the copy target location, you will be prompted whether to overwrite it, because the default execution of the cp command is "cp -i" Aliases, for example:

[root@localhost ~]# cp cangls /tmp/
cp:是否覆盖"/tmp/cangls"?y
#目标位置有同名文件,所以会提示是否覆盖

Next we look at how to copy a directory. In fact, you only need to use the "-r" option to copy a directory, for example:

[root@localhost ~]# mkdir movie
#建立测试目录
[root@localhost ~]# cp -r /root/movie/ /tmp/
#目录原名复制

Related tutorials: linux tutorial

The above is the detailed content of How to copy files under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn