Linux cp command-Linux general technology-Linux programming and kernel information. The following is a detailed description. Cp: copy operation
The cp command, that is, the copy command, is used to copy files or subdirectories. This command has nearly 40 command line parameters. Currently, I only want to learn the most common ones.
$ Cp file1 file2
Copy file1 to file2, and file1 still exists. The content of file2 is overwritten with the content of file1.
To avoid overwriting, use the-I and-B commands as in the mv command.
$ Cp-bi file1 file2
The cp command can also copy multiple files at a time
$ Cp tempdir1/* tempdir2
In this way, all the files under tempdir1 are cp under tempdir2.
To copy a sub-directory to another sub-directory, use the-r command.
$ Cp-r tempdir1 tempdir2
In this way, copy tempdir1 and its subfiles to tempdir2.
$ Cp tempdir2/tempdir1/file tempdir3
In this way, the file is copied to tempdir3.
If you want to copy the file along with its subdirectory structure, you need to use the-p parameter.
$ Cp-p tempdir2/tempdir1/file teempdir3
In this way, the entire sub-directory structure is copied (other files in the sub-directory structure will not be copied, which is different from the-r command)
In this way, not only the file is copied, but also a unified subdirectory structure is established.
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.