The cp Command Guide – 15 Linux cp Examples

file and directory is a operation system . is file and directory . in Linuxsystem , we can cpcommand implement .

What is the cp Command?

we in to , cpis a file and directory command . in we provide some in operation can can to cpcommand .

1. Running cp Without Arguments

is cp command use . myfile.txt from a to a , we can :

  1. $ cp myfile.txt /home/pungki/office

Copy without options

if we no for , we in directory a file . in , myfile.txt/home/pungki/Documentsdirectory . if we directory is /home/pungki/Documets,no to /home/pungki/Documents/myfile.txtfile . /home/pungki/officeis a directory , file to .

2. Copying Multiple Files

To copy multiple files, separate them with spaces:

  1. $ cp file_1.txt file_2.txt file_3.txt /home/pungki/office

Copying multiple files

3. Copying a Directory

to a directory has . need -r or -R implement . -r or -R operation . directory is directory , this all is to . :

  1. $ cp r directory_1 /home/pungki/office

Copy directory

need Note , need in directory . to information cp: omitting directory‘directory_1/

Copy directory error

if to information , directory not to file .

4. file , not is

file use some file . has , can can to “method ” or to file , not is . to to , we can use -l.

  1. $ cp l file_4.txt /home/pungki/office

Copy hardlinks

from , we to file_4.txt already to /home/pungki/office/file_4.txt. has inode, 835386. is Note, not can directory . let we a .

directory directory_1 inode is 278230

Inode number of original directory

file file_5.txt inode is 279231

Original inode number of file

for directory_1 cp command

Copy using -rl options

directory_1 inode is 274800

Inode number of copied directory

file_5.txt inode is 279231. file

Inode number of copied file

5. file

has or . we -s implement . is command .

  1. $ cp s /home/pungki/Documents/file_6.txt file_6.txt

can in directory perform . in , we to /home/pungki/office/file6.txt file /home/pungki/Documents/file6.txt. is , in will /home/pungki/officedirectory . directory , can cp -s command .

in file , to /home/pungki/office/file_6.txtfile . in file .

Symbolic links

6. not file

[:is file ]

we can -P implement . for use cp command , . .

  1. $ cp P file_6.txt ./movie

Copy using -P option

, cp command file_6.txt. file is a .

7. file

in we can -L. , this and -P . is :

  1. $ cp L file_6.txt ./movie

Copy using -L option

use this , file will and file_6.txtfile . we can from file . file has 50 file_6.txtfile has 33 .

8. file

we a directory , we -r or -R. is we can -afile . file and directory , if has can . is : [: -a file or directory ]

  1. $ cp a directory_1/ /home/pungki/office

Copy using -a option

command a directory1 directory to /home/pungki/officedirectory . , **file6.txt**.

9. display in

, , we to command Hint. if in file all , we can -v .

  1. $ cp v *.txt /home/pungki/office

Verbose option

we from directory all txt file to /home/pungki/office directory , -vdisplay in operation process . these information Helpwe process .

10. file file

we -uimplement . is :

  1. $ cp vu *.txt /home/pungki/office

Copy only if newer

we to file_1.txt is 0. then we vi Editor, some . , we file already 36 . and simultaneously in /home/pungki/officedirectory , we already all txtfile . we -u , -v view operation , cp command directory file . , we to has file_1.txt to /home/pungki/office directory .

11. use

is directory file . use -i , .

  1. $ cp ir directory_1/ /home/pungki/office/

Interactive mode

12. file

directory already has file , cp command directory file . use –backup , cp command a has file a Backup. ../office for /home/pungki/office . is :

  1. $ cp backup=simple v *.txt ../office

Backup option

we to , –backup=simple a in file (~) file . –backup has some :

  • none, off:from not ( –backup)
  • numbered, t:
  • existing, nil :if in use , [: is ]
  • simple, never :is use

13. file

cp command provide we –attributes-only . , this file , not data . is :

  1. $ cp attributesonly file_6.txt v ../office

Copy attributes only

from , file file_6.txt has 50 . –attributes-only, file has 0. is file no .

14.

-f perform operation . if file not can , can -f .

  1. $ cp f *.txt v ../office

Copy with force

15. in

we can , –remove-destination implement . this and -ffor . if cp command in directory file , cp command file , then . is :

  1. $ cp removedestination *.txt v ../office

Remove destination option

Summary

cp command is Linux command . for to Linux , this command . can in man cp or cp –help display Helpinformation .


via: http://linoxide.com/linux-command/linux-cp-command/

Translator: Luoxcat for : Mr

This article is by LCTT , Linux

Original URL: http://linux.cn/article-2687-1.html

Leave a Comment

Your email address will not be published.