Linux first week study notes (+)
2.11.CP Command
CP ( Copy shorthand) Command: used to copy one or more source files or directories to a specified destination file or directory.
Cp–r : Copy Directory
- I. : Security Options
-------------------------------------------------------------------------------------------
CP command: Copy /etc/passwd/ files to /tmp/ directory from the name of the 01.txt
[Email protected] ~]# Cp/etc/passwd/tmp/01.txt
[Email protected] ~]# ls/tmp
01.txt
Daizhihong
Daizhihong1
Ks-script-9pf2we
Ls1
Systemd-private-17411cf38aa84739852c7f37c5bb6b71-chronyd.service-qj4br8
Systemd-private-17411cf38aa84739852c7f37c5bb6b71-vgauthd.service-lrctds
Systemd-private-17411cf38aa84739852c7f37c5bb6b71-vmtoolsd.service-tptave
Systemd-private-600bc20c894f45978b1376aee644f335-chronyd.service-9iyyvb
Systemd-private-600bc20c894f45978b1376aee644f335-vgauthd.service-vbgivb
Systemd-private-600bc20c894f45978b1376aee644f335-vmtoolsd.service-mlvpl3
Yum.log
------------------------------------------------------------------------------------------------
Cp-r Copy directory: Create a new directory /tmp/daizhihong3/ , and then put /tmp/daizhihong/ directory Copy to /tmp/daizhihong3/ in Directory
[Email protected] ~]# mkdir-pv/tmp/daizhihong3/
mkdir: The directory has been created "/tmp/daizhihong3/"
[Email protected] ~]# cp-r/tmp/daizhihong//tmp/daizhihong3/
[Email protected] ~]# tree/tmp/daizhihong3/
/tmp/daizhihong3/
└── Daizhihong
└── 11.txt
1 directory, 1 file
Note: Sometimes the copy source is added in the copy directory. / "and the target is not added." / ", in Linux When you copy a directory in the system, you need to bring "/" the.
------------------------------------------------------------------------------------------------
!$ : Represents the last parameter that executes the previous command
[Email protected] ~]# tree/tmp/daizhihong3/
/tmp/daizhihong3/
└── Daizhihong
└── 11.txt
1 directory, 1 file
[email protected] ~]# tree!$ (Executive Tree the last parameter of the previous line of the command)
tree/tmp/daizhihong3/
/tmp/daizhihong3/
└── Daizhihong
└── 11.txt
1 directory, 1 file
--------------------------------------------------------------------------------------------
" - I. "parameter: Before we use which when you query the absolute path of a command, a " - I. "parameter, the meaning of this parameter is a security parameter, ask whether the execution is because the added" - I. "The Parameters
[email protected] ~]# which CP
Alias cp=' Cp-i '
/usr/bin/cp
[Email protected] ~]#
[email protected] ~]# which RM
Alias rm=' Rm-i '
/usr/bin/rm
[Email protected] ~]# cp/tmp/daizhihong/11.txt/tmp/daizhihong1/
CP : whether to overwrite "/tmp/daizhihong1/11.txt" ? n( the "-I " parameter will prompt if it needs to be overwritten or if it needs to be deleted when the RM command is executed, so "-i" is a security parameter)
When typing a command, do not ask for the command format as follows:
[[Email protected]~]#/usr/bin/cp/tmp/daizhihong/11.txt/tmp/daizhihong1/
[Email protected] ~]#
Absolute path command format execution will not prompt for an inquiry
-------------------------------------------------------------------------------------------
The following experiment shows that when the target directory is already present, the source directory is placed directly into the target directory, and if the target directory does not exist it will copy the source directory and change the name.
[Email protected] ~]# Tree/tmp/daizhihong
/tmp/daizhihong
└── 11.txt
0 directories, 1 file
[Email protected] ~]# tree/tmp/daizhihong1
/tmp/daizhihong1
└── on
└── 11.txt
1 directory, 1 file
[Email protected] ~]# cp-r/tmp/daizhihong//tmp/daizhihong1/
[Email protected] ~]# ls/tmp/daizhihong1/
Daizhihong
[Email protected] ~]# tree/tmp/daizhihong1
/tmp/daizhihong1
├── on
│ └── 11.txt
└── Daizhihong (the source directory is placed directly in the target directory when the target directory already exists )
└── 11.txt
2 directories, 2 files
[Email protected] ~]#
Linux first week study notes (18)