Introduction to copying folders and file instances in linux

Source: Internet
Author: User

This article introduces some basic usage of copying folders and files in linux. For more information, see this article.

CP command
Format: CP [Option] source file or directory target file or directory
Option Description:-B with the same name.
-F forcibly overwrite files with the same name
-R: retained the original directory structure to copy files recursively.

Cp-r/tmp/a/root/

Example

. Copy the file. The file is copied only when the source file is modified later than the target file.
Cp-u-v file1 file2

. Copy file file1 to file file2
Cp file1 file2

. Copy file file1 to file file2.
Cp-I file1 file2

. Copy the file file1 to file2. Because the target file already exists, use the forced copy mode.
Cp-f file1 file2

. Copy the directory dir1 to the directory dir2
Cp-R file1 file2

. Copy the file file1, file2, file3, and directory dir1 to dir2.
Cp-R file1 file2 file3 dir1 dir2

. File attributes are retained during replication.
Cp-p a.txt tmp/

. The directory structure of the file is retained during replication.
Cp-P/var/tmp/a.txt./temp/

. Backup files generated during replication
Cp-B a.txt tmp/

. The backup file is generated during replication ~ 1 ~ Format
Cp-B-V t a.txt/tmp

. Specifies the tail mark of the backup file
Cp-B-S _ bak a.txt/tmp


Copy file not prompted

# Vi ~ /. Bashrc

If you see the following content, the following commands are executed using aliases, that is, the-I parameter is automatically added.

Alias rm = 'rm-I'
Alias cp = 'cp-I'
Alias mv = 'mv-I'

In order to allow copying and moving a large number of files to overwrite the target, no prompts are generated one by one. The command should be written in this way.

# Cp-rf/home/huzs.net/*/www/huzs.net/

Note that the cp command is added before it, meaning it is not allowed to be used ~ /. Run the alias in bashrc, that is, the-I parameter.


Cp command

Function: copy the given file or directory to another file or directory, just like the copy command in DOS, which is very powerful.

Syntax: cp [Option] source file or directory target file or directory

Note: This Command copies the specified source file to the target file or multiple source files to the target directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.