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.