LINUX

LINUX CP指令

介紹

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

語法

cp [options] files (file | directory)

常用的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.

範例

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

⤍ cp myfile anotherfile

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

⤍ cp myfile1 myfile2 myfile3 mydir

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

⤍ cp -r old_dir new_dir

發佈留言