How to copy files under linux

王林
Release: 2020-10-22 16:44:27
Original
29275 people have browsed it

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 [选项] 源文件 目标文件
Copy after login

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
#改名复制
Copy after login

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
#目标位置有同名文件,所以会提示是否覆盖
Copy after login

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/
#目录原名复制
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template