cp命令主要是使用来复制文件和目录的,
基本使用语法:cp 源文件 目标目录root@kali:~/eth10/eth10# ls
test test.txt
root@kali:~/eth10/eth10# ls test
root@kali:~/eth10/eth10# cp test.txt test/
root@kali:~/eth10/eth10# ls test/
test.txt
root@kali:~/eth10/eth10#
cp在复制目录时会自动跳过目录,因此需要使用-r参数来进行复制root@kali:~/eth10/eth10# ls test1
root@kali:~/eth10/eth10# cp test/ test1/
cp: 略过目录'test/'
root@kali:~/eth10/eth10# cp -r test/ test1/
root@kali:~/eth10/eth10# ls test1
test
另外cp在复制文件时会自动覆盖同名文件,因此我们可以使用-i参数来进行提示是覆盖还是跳过,y覆盖,n跳过!root@kali:~/eth10/eth10# ls
test test1 test.txt
root@kali:~/eth10/eth10# cp test.txt test
root@kali:~/eth10/eth10# ls test
test test.txt
root@kali:~/eth10/eth10# cp -i test.txt test/
cp:是否覆盖'test/test.txt'? n
root@kali:~/eth10/eth10#
最后我们可以使用-b参数,主要是对同名文件重命名(文件名后添加~)后再进行复制root@kali:~/eth10/eth10# cp -b test.txt test/
root@kali:~/eth10/eth10# ls test/
test test.txt test.txt~
root@kali:~/eth10/eth10#