cp's Examples

cp source file destination file. In case you need a copy of the file second.txt in the same directory you have to use the cp command

$ cp second.txt third.txt

this command is used to copy files or group of files or directory

$ cp file1.txt file2.txt

overwrites the file2.txt with file1.txt

$ cp -i file1.txt file2.txt

it copies multiple files to the directory

cp current.txt news.txt file.txt news/

copies all .txt files to the directory

cp *.txt newsportal/

to create a backu destination if alrady exists

cp -b file1.txt file2.txt
$ls -l

create a backup with a specific suffix

cp -s .bak news.txt headlines.txt

create a backup with a specific suffix

cp -s .bak news.txt headlines.txt

copy fiels in recrusive manner

cp -r news.txt archive

copies when the source foile is newer than the destination file

cp -u current.txt headlines.txt

when we don not want to accidentally over erite an existing file we use nno clobber command

cp -n current.txt headlines.txt

when we want to create a symbolic link of the file

cp -s current.txt cn

create archive file while coping the files

cp -a pavani.txt /archive

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us