Introduction to Commands:
The CP command is used to copy files or directories. Directive English original meaning: copy
Instruction Path:/BIN/CP
Command syntax:
USAGE:CP [OPTION] ... [-T] SOURCE DEST
OR:CP [OPTION] ... SOURCE ... DIRECTORY
OR:CP [OPTION] ...-t DIRECTORY SOURCE ...
Command parameters:
This command parameter is red Hat Enterprise Linux Server release 5.7 under the CP command parameter, different versions of Linux CP command parameters may be different.
Parameters |
Long parameters |
Description |
-A |
|
Equivalent to-DR |
-B |
|
If the target file is deleted or overwritten, the target file is backed up, and the backup file ends with the string backed up |
-D |
|
Copy Symbolic Links |
-F |
|
Force replication |
-H |
|
Force the CP command to copy symbolic links. The default value is to follow the symbolic link, which is to copy the file to the symbolic link point. |
-I. |
|
Interactive mode. Ask before overwriting the target file |
-L |
|
Create a hard link, not a copy |
-P |
|
The property of the source directory or file is reserved |
-P |
|
The source directory or file's path is reserved |
-r/-r |
|
Working with specified directories and subdirectories |
-V |
--verbose |
Show details of command execution |
|
--help |
Show Commands online Help |
|
--version |
Display Command version information |
Examples of Use:
1: View Help for the rmdir command
[email protected] ~]# CP--help
USAGE:CP [OPTION] ... [-T] SOURCE DEST
OR:CP [OPTION] ... SOURCE ... DIRECTORY
OR:CP [OPTION] ...-t DIRECTORY SOURCE ...
Copy source to DEST, or multiple source (s) to DIRECTORY.
Mandatory arguments to long options is Mandatory for short options too.
-A,--archive same as-dr--preserve=all
--backup[=control] Make a backup of each existing destination file
-B like--backup but does don't accept an argument
--copy-contents copy contents of special files when recursive
-d Same as--no-dereference--preserve=link
-F,--force if an existing destination file cannot is
Opened, remove it and try again
-I,--interactive prompt before overwrite
-H Follow command-line symbolic links
-L,--link link files instead of copying
-L,--dereference always follow symbolic links
-P,--no-dereference never follow symbolic links
-p Same as--preserve=mode,ownership,timestamps
--preserve[=attr_list] Preserve the specified attributes (default:
Mode,ownership,timestamps), if possible
Additional Attributes:context, links,
Xattr, all
-C Same as--preserve=context
--no-preserve=attr_list don ' t preserve the specified attributes
--parents use full source file name under DIRECTORY
-R,-R,--recursive copy directories recursively
--remove-destination Remove each existing destination file before
Attempting to open it (contrast with--force)
--sparse=when control creation of sparse files
--strip-trailing-slashes remove any trailing slashes from each SOURCE
Argument
-S,--symbolic-link make symbolic links instead of copying
-S,--suffix=suffix override the usual backup suffix
-T,--target-directory=directory Copy all SOURCE arguments to directory
-T,--no-target-directory treat DEST as a normal file
-U,--update copy only if the SOURCE file is newer
than the destination file or when the
Destination file is missing
-V,--verbose explain what's being done
-X,--one-file-system stay on the This file system
-Z,--context=context Set security context of copy to context
--help Display this Help and exit
--version output version information and exit
By default, sparse SOURCE files is detected by a crude heuristic and the
Corresponding DEST file is made sparse as well. That's the behavior
Selected by--sparse=auto. Specify--sparse=always to create a sparse DEST
File whenever the SOURCE file contains a long enough sequence of zero bytes.
Use--sparse=never to inhibit creation of sparse files.
The backup suffix is ' ~ ', and unless set with--suffix or Simple_backup_suffix.
The version control method may be selected via the--backup option or through
The Version_control environment variable. Here is the values:
None, off never make backups (even if--backup is given)
Numbered, t make numbered backups
Existing, nil numbered if numbered backups exist, simple otherwise
Simple, never always make simple backups
As a special case, CP makes a backup of SOURCE when the force and backup
Options are given and SOURCE and DEST is the same name for a existing,
Regular file.
[email protected].
Or
[[email protected] ~]# man CP
2: Copy file file1 and rename to File2
[[email protected] kerry]# ls
File1
[email protected] kerry]# CP file1 file2
[[email protected] kerry]# ls
File1 file2
3: Copy the Kerry directory under the file to the TMP directory
[Email protected] ~]# cp/home/kerry/*/tmp
[Email protected] ~]# cd/tmp
4: Copy all directories under directory including subdirectories to another directory
[[Email protected] ~] #cp-R/home/tomcat//tmp/bak
5: Preserve file attributes when copying (save modified date, time, and access control list associated with the source file, etc.)
[Email protected] kerry]# LS-LRT
Total 8
-rw-r--r--1 root root 3886 Jan 23:04 install.log.syslog
[Email protected] kerry]# cp-p install.log.syslog INSTALL.LOG.SYSLOG.BAK1
[email protected] kerry]# CP Install.log.syslog INSTALL.LOG.SYSLOG.BAK2
[Email protected] kerry]# LS-LRT
Total 24
-rw-r--r--1 root root 3886 Jan 23:04 install.log.syslog.bak1
-rw-r--r--1 root root 3886 Jan 23:04 install.log.syslog
-rw-r--r--1 root root 3886 Jan 23:10 install.log.syslog.bak2
6: Copy files in exchange form
[Email protected] kerry]# cp-i/var/log/*.
Cp:overwrite './acpid '? N
Cp:overwrite './anaconda.log '? N
Cp:overwrite './anaconda.syslog '? Y
Cp:overwrite './anaconda.xlog '? N
cp:omitting directory '/var/log/audit '
Cp:overwrite './boot.log '? N
Cp:overwrite './boot.log.1 '? N
Cp:overwrite './boot.log.2 '? N
Linux Command Learning summary: CP command