1. 程式人生 > >linux命令——cp

linux命令——cp

linux命令 cp

cp命令主要是使用來復制文件和目錄的,

基本使用語法:

cp 源文件 目標目錄
[email protected]:~/eth10/eth10# ls
test  test.txt
[email protected]:~/eth10/eth10# ls test
[email protected]:~/eth10/eth10# cp test.txt test/
[email protected]:~/eth10/eth10# ls test/
test.txt
[email protected]:~/eth10/eth10#


cp在復制目錄時會自動跳過目錄,因此需要使用-r

參數來進行復制

[email protected]:~/eth10/eth10# ls test1
[email protected]:~/eth10/eth10# cp test/ test1/
cp: 略過目錄‘test/‘
[email protected]:~/eth10/eth10# cp -r test/ test1/
[email protected]:~/eth10/eth10# ls test1
test


另外cp在復制文件時會自動覆蓋同名文件,因此我們可以使用-i參數來進行提示是覆蓋還是跳過,y覆蓋,n跳過!

[email protected]
/* */:~/eth10/eth10# ls test test1 test.txt [email protected]:~/eth10/eth10# cp test.txt test [email protected]:~/eth10/eth10# ls test test test.txt [email protected]:~/eth10/eth10# cp -i test.txt test/ cp:是否覆蓋‘test/test.txt‘? n [email protected]:~/eth10/eth10#

最後我們可以使用-b參數,主要是對同名文件重命名(文件名後添加~

)後再進行復制

[email protected]:~/eth10/eth10# cp -b test.txt test/
[email protected]:~/eth10/eth10# ls test/
test  test.txt  test.txt~
[email protected]:~/eth10/eth10#


本文出自 “eth10” 博客,請務必保留此出處http://eth10.blog.51cto.com/13143704/1957498

linux命令——cp