How Unix copies files and folder directories

Source: Internet
Author: User
Tags root directory

Demo System and Application scope

Demo System: FreeBSD9.1

Applicable scope: UNIX and Linux system

CP Replication Command Usage

Command Implementation Results Description
CP file1 File2 Copy the existing file named File1 to the usr file named File2.
CP file1/crchive Copy the file1 to the archive directory, which is a subdirectory under the root directory.
CP File1 Mystuff/newfile will be able to replicate file1 to the MyStuff directory in the current directory. If NewFile is a subdirectory, File1 is copied to the NewFile subdirectory under MyStuff. If NewFile is not a subdirectory, file is copied to the MyStuff subdirectory and named NewFile.
CP File1 File2/archive Copy file1 and file2 to the archive directory, which is located in the root directory.

By default, if you accidentally copy a file to an existing file with the same name, the CP command will only have the content in the file now, for example, the CP file1 file2 command, if the File2 file already exists, the command will overwrite the File2 file with the contents of File1. You can use the Cp-i command to send a prompt to ask for coverage before a file must already be available. Original website Unix How to copy files and folder directories

How UNIX replicates the entire folder

This is also a lot of users often encounter the problem is to put the entire directory and the contents of this directory, including subdirectories, are copied to another location, then you can use Cp-r file1 file2 execution.

You can use the Cp-r-i/file1 file2 This command will copy all the contents of the File1 folder directory to the name File2 directory, if the File2 folder directory has the same file as the File1 directory, you will be prompted whether to overwrite.

Note: When you use the CP folder directory to copy commands, be careful not to use the cp-r/*/file2, which will copy all the contents of the root directory into a subdirectory named File2, but File2 is in the root directory, so there will be a dead loop. The system will continue to replicate the contents of the/file2 directory, and if this is done on some high-speed disks, the disk will fill the entire hard drive at a very fast rate.

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.