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

How to use the Linux common command cp

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the Linux commonly used command cp how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Linux common command cp command is also a very commonly used command in our actual use, mainly used to copy files, folders and so on.

Syntax cp [options] source dest or

Cp [options] source... Directory parameter description:

-a: this option is usually used when copying a directory, preserving links, file properties, and copying everything in the directory. Its function is equal to the combination of dpR parameters.

-d: keep the link when copying. The links mentioned here are equivalent to shortcuts in the Windows system.

-f: overwrite existing target files without prompting.

-I: contrary to the-f option, prompt the user to confirm whether or not to overwrite the target file before overwriting, and the target file will be overwritten when answering y.

-p: copy the modification time and access rights to the new file in addition to copying the contents of the file.

-r: if the source file given is a directory file, all subdirectories and files under that directory will be copied.

-l: do not copy the file, just generate the linked file.

Example 1) copy file1 to another location

# cp file1.. / destDir/ # ls.. / destDir/ file12) copy the entire folder to another folder

Ls destDir testDir # cp-r testDir destDir # ls destDir file1 testDir3) forces the target file to be overwritten without asking

# cp-r testDir destDir cp: overwrite `destDir/testDir/file2'? Y cp: overwrite `destDir/testDir/file1'? Y cp: overwrite `destDir/testDir/file3'? Y # cp-nrf testDir destDir # using the-n option ignores override queries. Cp is an alias for cp-I, and the default is to prompt whether to overwrite, so you need to add the-n option.

4) copy a link for file1

Cp-s file1 file1_link # ll total 4-rw-r--r-- 1 root root 0 Jun 13 14:18 file3-rw-r--r-- 1 root root 74 Jun 13 15:37 file1-rw-r--r-- 1 root root 0 Jun 13 15:39 file2 lrwxrwxrwx 1 root root 5 Jun 14 21:44 file1_link-> file1 # cat file1_link This is a test file. Welcome to linuxdaxue.com! This is cat command test. This example copies a link for file1, and the contents of file1_link and file1 are the same.

The cp command we mainly use in our actual work is cp or cp-r, and the other commands are not commonly used, but we also need to master them so as not to check them again when we use them.

Thank you for reading this article carefully. I hope the article "how to use Linux commands cp" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report