LINUX

LINUX CP指令

介紹

cp指令用來複製一個或多個檔案。

語法

cp [options] files (file | directory)
Code language: Bash (bash)

常用的options

-p Copy not only the file contents, but also the file's permissions, timestamps, and if you have sufficient permission to do so, its owner and group. -a Copy a directory hierarchy recursively, preserving all file attributes and links. -r Copy a directory hierarchy recursively. This option does not preserve the files' attributes such as permission and timestamps. It does preserve symbolic links. -i Interactive mode. Ask before overwriting destination files. -f Force the copy. If a destination file exists, overwrite it unconditionally.
Code language: plaintext (plaintext)

範例

你可以複製一個檔案(複製myfile且命名為anotherfile):

⤍ cp myfile anotherfile
Code language: Bash (bash)

你可以複製多個檔案到一個檔案夾裡(複製myfile1, myfile2myfile3mydir):

⤍ cp myfile1 myfile2 myfile3 mydir
Code language: Bash (bash)

使用-a-r,你可以複製一個檔案夾:

⤍ cp -r old_dir new_dir
Code language: Bash (bash)

發佈留言