Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of copying Files by cp Command in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the method of copying files with cp commands in linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

In linux, you can use the cp command to copy a file and copy a source file or directory to a specified destination file or directory; it can copy a single source file into a specific file with a specified file name or an existing directory; this command supports copying multiple files at the same time.

The operating environment of this tutorial: centos7 system, thinkpad T480 computer.

Command format of cp

Take moving file 1234.txt as an example

Ls-l / / displays information about all files in the current folder

Copy the 1234.txt file to the new file 2345.txt

Copy 1234.txt 2345.txt

Here you can see that the two files are of the same size and have different timestamps

Copy the 1234.txt file to the new file 3456.txt and keep the timestamp the same

What if the copied new file name already exists?

If you write something to 1234.txt and copy it to 2345.txt again, you will find that the original 2345.txt file will be overwritten and will be executed successfully without warning.

To avoid not knowing whether a file with the same name is overwritten, you can add the-I option.

Example:

Cp-I 1234.txt 3456.txt

You can see that there is an overwrite confirmation reminder when the new file name already exists in the current directory

Enter n to cancel the replication.

Copy files to folders in the same directory and other folders in different directories

Cp 123.txt test / / same directory cp 1234.txt / home/zinkky/test / / different directories need to be taken with a path

Copying a directory to a new directory requires the option-r

Example:

Cp-r test python

This is the end of this article on "the method of cp command to copy files in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report