在Ubuntu中,你可以使用命令行工具來移動和復制文件。以下是一些常用的命令和選項:
命令: mv
語法: mv [options] source destination
source
: 要移動的文件或目錄。destination
: 目標位置。示例:
將文件 file1.txt
從當前目錄移動到 /home/user/documents
目錄:
mv file1.txt /home/user/documents/
將目錄 dir1
從當前目錄移動到 dir2
目錄內(如果 dir2
不存在,則重命名 dir1
為 dir2
):
mv dir1 dir2
選項:
-i
: 在覆蓋目標文件前提示用戶確認。-f
: 強制覆蓋目標文件或目錄,即使它們已經存在。-n
: 不覆蓋現有文件。-v
: 顯示每個移動文件的名稱。命令: cp
語法: cp [options] source destination
source
: 要復制的文件或目錄。destination
: 目標位置。示例:
復制文件 file1.txt
到 /path/to/destination/file1_copy.txt
:
cp file1.txt /path/to/destination/file1_copy.txt
復制目錄 dir1
及其所有內容到 /path/to/destination/dir1_copy
:
cp -r dir1 /path/to/destination/dir1_copy
選項:
-r
或 -R
: 遞歸復制整個目錄及其內容。-p
: 連同文件的屬性一起復制,常用于備份。-i
: 在覆蓋目標文件之前提示用戶確認。-f
: 強制復制,如果目標文件已存在則覆蓋。在使用這些命令時,請注意以下幾點:
-i
選項可以避免在覆蓋文件或目錄時收到確認提示。-r
選項可以遞歸地復制整個目錄及其內容。