一. 文件管理(cp, mv, rm)
cp: 文件復(fù)制命令
- SRC DEST
- SRC是文件:
- 如果目標不存在則會新建DEST, 并將SRC中的內(nèi)容填充至DEST
$ ls test.txt $ cat test.txt this is a test $ cp test.txt test2 $ cat test2 this is a test
- SRC是文件:
- 如果目標存在:
-
如果DEST是文件: 將SRC中的內(nèi)容覆蓋至DEST中(此時建議使用-i選項)
$ echo abc > test.txt $ cat test.txt abc $ cp test.txt test2 $ cat test2 abc
-
如果DEST是目錄: 在DEST下新建與源文件同名的文件, 并將SRC中的內(nèi)容填充至新文件
$ pwd /home/centos/Downloads $ cd ../Documents/ $ cp test.txt ../Downloads/test.txt $ cat ../Downloads/test.txt/test.txt abc
-
SRC是多個文件
-
DEST必須存在, 且為目錄, 其它情形均會出錯
$ cp test* ../Downloads/test.txt/test.txt cp: target `../Downloads/test.txt/test.txt' is not a directory
-
SRC是目錄: 常用選項為-r(遞歸復(fù)制)
- 如果DEST不存在: 則創(chuàng)建指定目錄, 復(fù)制SRC目錄中的所有文件至DEST中
$ cp -r Documents/ Downloads/abc $ ls Downloads/abc/ test2 test.txt
- 如果DEST存在
- 如果DEST是文件: 報錯
- 如果DEST是目錄, 創(chuàng)建目錄并復(fù)制源目錄
-
-
options
-
-i: 交互式
$ cp -i test2 ../Downloads/abc/test2 cp: overwrite `../Downloads/abc/test2'? y
-
-R/r: 遞歸復(fù)制
$ cp Documents/ Downloads/ cp: omitting directory `Documents/ $ cp -r Documents/ Downloads/
-
-a: 歸檔復(fù)制 相當于-dR --preserve=all
-d: --no-deference --preserve=links
--preserve=[ATTR_LIST]mode: 權(quán)限 ownership timestamp links xattr context all
- -p: --preserve=mode, ownership, timestamp保留屬主屬組及時間戳
- -v: --verbose
- -f: --force 強制執(zhí)行
mv: 移動文件
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
-
如果SRC是單個文件:
- 如果DEST不存在: 移動
$ mv Documents/test2 Music/
- 如果目標存在:
- DEST為文件: 覆蓋
$ mv Documents/test.txt Downloads/abc/test.txt
- DEST為目錄: 移動
- DEST為文件: 覆蓋
- 如果在同一目錄下且名字不相同: 重命名
- 如果DEST不存在: 移動
-
options
- -i: 交互式選項(與cp類似)
- -f --force: 強制(當有同名文件是直接覆蓋不提示)
rm: remove 刪除
rm [OPTION]... FILE...
-
options
- -i: 交互式
- -f: 強制刪除
- -r: 遞歸刪除