cp命令,你有多強,我就能有多強。

cp命令用來將一個或多個源文件或者目錄複製到指定的目的文件或目錄。它可以將單個源文件複製成一個指定文件名的具體的文件或一個已經存在的目錄下。cp命令還支持同時複製多個文件,當一次複製多個文件時,目標文件參數必須是一個已經存在的目錄,否則將出現錯誤。

1.命令格式:

<code>cp(選項)(參數)/<code>

2.命令功能:

將一個或多個源文件或者目錄複製到指定的目的文件或目錄。

3.命令參數:

<code>-a:此參數的效果和同時指定"-dpR"參數相同;
-d:當複製符號連接時,把目標文件或目錄也建立為符號連接,並指向與源文件或目錄連接的原始文件或目錄;
-f:強行復制文件或目錄,不論目標文件或目錄是否已存在;
-i:覆蓋既有文件之前先詢問用戶;
-l:對源文件建立硬連接,而非複製文件;
-p:保留源文件或目錄的屬性;
-R/r:遞歸處理,將指定目錄下的所有文件與子目錄一併處理;
-s:對源文件建立符號連接,而非複製文件;
-u:使用這項參數後只會在源文件的更改時間較目標文件更新時或是名稱相互對應的目標文件並不存在時,才複製文件;

-S:在備份文件時,用指定的後綴“SUFFIX”代替文件的默認後綴;
-b:覆蓋已存在的文件目標前將目標文件備份;
-v:詳細顯示命令執行的操作。/<code>

4.命令實例:

1).把一個文件複製到一個目標文件中,而目標文件已經存在,那麼,該目標文件將被覆蓋。


cp命令,你有多強,我就能有多強。

把gpio複製到當前文件夾

2).將文件gpio複製到目錄tmp下,並改名為gpio1


cp命令,你有多強,我就能有多強。

複製並改名

常用用法就這兩種,別的用法請參考man信息:

<code>      NAME
cp - copy files and directories

SYNOPSIS
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.

\t\t\t-a, --archive
same as -dR --preserve=all

--attributes-only
don't copy the file data, just the attributes

--backup[=CONTROL]
make a backup of each existing destination file

-b like --backup but does not accept an argument

--copy-contents
copy contents of special files when recursive

-d same as --no-dereference --preserve=links

-f, --force
if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)

-i, --interactive
prompt before overwrite (overrides a previous -n option)

-H follow command-line symbolic links in SOURCE

-l, --link
hard link files instead of copying

-L, --dereference
always follow symbolic links in SOURCE

-n, --no-clobber
do not overwrite an existing file (overrides a previous -i option)

-P, --no-dereference
never follow symbolic links in SOURCE

-p same as --preserve=mode,ownership,timestamps

--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all

--no-preserve=ATTR_LIST
don't preserve the specified attributes

--parents
use full source file name under DIRECTORY

-R, -r, --recursive
copy directories recursively

--reflink[=WHEN]
control clone/CoW copies. See below

--remove-destination
remove each existing destination file before attempting to open it (contrast with --force)

--sparse=WHEN
control creation of sparse files. See below

--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument

-s, --symbolic-link
make symbolic links instead of copying

-S, --suffix=SUFFIX
override the usual backup suffix

-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY

-T, --no-target-directory
treat DEST as a normal file

-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing

-v, --verbose
explain what is being done

-x, --one-file-system
stay on this file system

-Z set SELinux security context of destination file to default type

--context[=CTX]
like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX

--help display this help and exit

--version
output version information and exit
/<code>


下期介紹touch命令。歡迎關注訂閱。


分享到:


相關文章: