linux終端怎麼複製貼上

複製和貼上是計算機上最常用的操作之一。使用Ctrl C和Ctrl V鍵盤快捷鍵很容易做到,但是在Linux終端上卻不是那麼簡單。您有幾種選擇可以完成工作。這是在Linux終端中複製和貼上文字,檔案和目錄的方法。

複製和貼上文字

如果您只想在終端中複製一段文字,您要做的就是用滑鼠突出顯示該文字,然後按Ctrl Shift C進行復制。

要將其貼上到游標所在的位置,請使用鍵盤快捷鍵Ctrl Shift V。

當您從Word文件(或任何其他應用程式)複製一段文字並希望將其貼上到終端時,貼上快捷方式也適用。例如,您可以從瀏覽器中的網頁複製命令,然後使用Ctrl Shift V快捷方式將其貼上到終端中。

複製並貼上單個檔案

每當您想在Linux命令列中複製檔案或資料夾時,上述鍵盤快捷鍵將不起作用。您必須使用cp命令。cp是複製的簡寫。語法也很簡單。使用,cp後跟要複製的檔案以及要將其移動到的目的地。

cp your-file.txt ~/Documents/

當然,這假定您的檔案位於要處理的目錄中。您可以同時指定。

cp ~/Downloads/your-file.txt ~/Documents/

您還可以選擇在複製檔案時重新命名檔案。在目的地中指定新名稱。

cp ~/Downloads/your-file.txt ~/Documents/new-name.txt

複製和貼上資料夾及其內容

為了複製資料夾及其內容,您將需要告訴cp命令以遞迴方式複製。使用-r標誌就足夠簡單了。

cp -r ~/Downloads/pictures-directory ~/Pictures/family-vacation-picsLinux Cli Copy FolderAll the rest of your syntax is exactly the same. The -r flag serves to tell cp that it’s working with a directory and should copy its contents.If you want the paste action to overwrite existing files, you can add the -f flag:cp -rf ~/Downloads/pictures-directory ~/Pictures/family-vacation-picsCopy and Paste Multiple FilesYou can also copy multiple files. The Linux command line lets you target multiple items at once with brackets {}. You can use them to list the names of each file to be copied separated by commas.cp ~/Downloads/{file1.txt,file2.jpg,file3.odt} ~/Documents/Linux Cli Copy MultipleAll three files of differing file types will be copied to the Documents directory.Copy and Paste All Files of the Same TypeIf you have a ton of files of the same type to copy, you can use the wildcard character *. The asterisk/wildcard tells the Linux command line to accept absolutely anything in that place. So, if you tell Linux to copy *.jpg, it’ll copy all JPG files, regardless of the name or whatever comes before the .jpg part.cp ~/Downloads/*.jpg ~/Pictures/Linux Cli Copy All File TypeIf you want to use multiple file types, say JPG and PNG, you can use the brackets from before.cp ~/Downloads/*.{jpg,png} ~/Pictures/Move a File or FolderIf you came here looking to move a file from one place to another without making a duplicate, you can do that easily too, but moving a file requires the mv command. The syntax is very similar to cp.mv ~/Downloads/your-file.txt ~/Documents/Similarly, you can also rename it.mv ~/Downloads/your-file.txt ~/Documents/renamed.txtThere is one major difference, though. You don’t need the -r flag to move a whole folder.mv ~/Downloads/downloaded-folder ~/Pictures/vacation-picsThat’s all there is to it. You’re ready to start copying and moving your files from the command line. You can see that the command line way can be very efficient in some situations.Want more pointers on the Linux command line? Here’s how to check sudo history or find out what the chmod 777 command does to your file permission.Image credit: Copy – Paste by DepositPhotosIs this article useful?   Popular PostsXfce Review: A Lean, Mean Linux MachineHow to Hide the Top Bar and Side Panel in Ubuntu 20.04How to Share Files Between Android and Ubuntu on Your NetworkHow to Fix High CPU Usage in LinuxHow to Speed Up Your Linux Desktop with ComptonAffiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.Never Miss OutReceive update of our latest tutorials.Your email addressSee all newsletters | Privacy Policy

您其餘所有語法都完全相同。該-r標誌用於告訴cp它正在使用目錄,並且應該複製其內容。

如果希望貼上操作覆蓋現有檔案,則可以新增-f標誌:

cp -rf ~/Downloads/pictures-directory ~/Pictures/family-vacation-pics

複製並貼上多個檔案

您也可以複製多個檔案。Linux命令列使您可以使用括號同時定位多個專案{}。您可以使用它們列出要複製的每個檔案的名稱,並用逗號分隔。

cp ~/Downloads/{file1.txt,file2.jpg,file3.odt} ~/Documents/

具有不同檔案型別的所有三個檔案都將被複制到Documents目錄中。

複製和貼上相同型別的所有檔案

如果要複製大量相同型別的檔案,則可以使用萬用字元*。星號/萬用字元告訴Linux命令列在該位置絕對接受任何內容。因此,如果您告訴Linux複製*.jpg,它將複製所有JPG檔案,而不管名稱是.jpg部分之前是什麼。

cp ~/Downloads/*.jpg ~/Pictures/

如果要使用多種檔案型別(例如JPG和PNG),則可以使用之前的括號。

cp ~/Downloads/*.{jpg,png} ~/Pictures/

移動檔案或資料夾

如果您來這裡是想將檔案從一個位置移動到另一個位置而不進行復制,那麼您也可以輕鬆地做到這一點,但是移動檔案需要mv命令。語法與cp非常相似。

mv ~/Downloads/your-file.txt ~/Documents/

同樣,您也可以重新命名它。

mv ~/Downloads/your-file.txt ~/Documents/renamed.txt

但是,有一個主要區別。您不需要-r標誌來移動整個資料夾。

mv ~/Downloads/downloaded-folder ~/Pictures/vacation-pics

這裡的所有都是它的。您已經準備好從命令列開始複製和移動檔案。您會看到命令列方式在某些情況下可能非常有效。

在Linux命令列上需要更多指標嗎?這是檢查sudo歷史記錄或查明chmod 777命令對檔案許可權的作用的方法。