千家信息网

linux命令——cp

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,cp命令主要是使用来复制文件和目录的,基本使用语法:cp 源文件 目标目录root@kali:~/eth20/eth20# lstest test.txtroot@kali:~/eth20/eth2
千家信息网最后更新 2025年02月03日linux命令——cp

cp命令主要是使用来复制文件和目录的,

基本使用语法:

cp 源文件 目标目录
root@kali:~/eth20/eth20# lstest  test.txtroot@kali:~/eth20/eth20# ls testroot@kali:~/eth20/eth20# cp test.txt test/root@kali:~/eth20/eth20# ls test/test.txtroot@kali:~/eth20/eth20#


cp在复制目录时会自动跳过目录,因此需要使用-r参数来进行复制

root@kali:~/eth20/eth20# ls test1root@kali:~/eth20/eth20# cp test/ test1/cp: 略过目录'test/'root@kali:~/eth20/eth20# cp -r test/ test1/root@kali:~/eth20/eth20# ls test1test


另外cp在复制文件时会自动覆盖同名文件,因此我们可以使用-i参数来进行提示是覆盖还是跳过,y覆盖,n跳过!

root@kali:~/eth20/eth20# lstest  test1  test.txtroot@kali:~/eth20/eth20# cp test.txt testroot@kali:~/eth20/eth20# ls testtest  test.txtroot@kali:~/eth20/eth20# cp -i test.txt test/cp:是否覆盖'test/test.txt'? nroot@kali:~/eth20/eth20#

最后我们可以使用-b参数,主要是对同名文件重命名(文件名后添加~)后再进行复制

root@kali:~/eth20/eth20# cp -b test.txt test/root@kali:~/eth20/eth20# ls test/test  test.txt  test.txt~root@kali:~/eth20/eth20#


0