Tuesday, October 2, 2018

cp command examples

cp Command

1) Copy single file on same directory 
cp abc.txt  abc1.txt

2) Copy single file on different directory
cp abc.txt  /home/unix/abc1.txt

3) Copy multiple files with same extension in different directory
cp *.txt  /home/unix/

4) Copy multiple files in different directory
cp abc.txt abc1.txt abc2.txt /home/unix/

5) Copy a directory to different directory 
cp -R xyz/ /home/unix/

6) Copy multiple directory to different directory
cp -R xyz/ abc/ abc1/ /home/unix/

7) Copy a file with preserve file attributes (permissions, group and user owernship)
cp --preserve abc.txt  abc1.txt

8) Creating a hard link with cp command
cp -l abc.txt abc1.txt

9) Creating a soft link with cp command
cp -s abc.txt /home/unix/abc1.txt

10) Showing progress of cp command
cp -v *.txt /home/unix/

No comments:

Post a Comment

Remove CTRL-M characters from a file in UNIX

 We can remove ^M by below methods 1st Method - Using sed command Type below command:    sed -e "s/^M//" filename > newfilena...