软件下载

linux怎么粘贴(如何在Linux终端中复制和粘贴文本)

软件下载 投稿 2022-05-29 11:48:36 浏览

复制和粘贴是计算机上最常用的操作之一。使用Ctrl+ C和Ctrl+ V键盘快捷键很容易做到,但是在Linux终端上却不是那么简单。您有几种选择可以完成工作。这是在Linux终端中复制和粘贴文本,文件和目录的方法。

如何在Linux终端中复制和粘贴文本、文件和文件夹

 

复制和粘贴文字

如果您只想在终端中复制一段文本,您要做的就是用鼠标突出显示该文本,然后按Ctrl+ Shift+ C进行复制。

要将其粘贴到光标所在的位置,请使用键盘快捷键Ctrl+ Shift+ V。

当您从Word文档(或任何其他应用程序)复制一段文本并希望将其粘贴到终端时,粘贴快捷方式也适用。例如,您可以从浏览器中的网页复制命令,然后使用Ctrl+ Shift+ V快捷方式将其粘贴到终端中。

复制并粘贴单个文件

每当您想在Linux命令行中复制文件或文件夹时,上述键盘快捷键将不起作用。您必须使用cp命令。cp是复制的简写。语法也很简单。使用,cp后跟要复制的文件以及要将其移动到的目的地。

cp your-file.txt ~/Documents/
如何在Linux终端中复制和粘贴文本、文件和文件夹

 

当然,这假定您的文件位于要处理的目录中。您可以同时指定。

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-pics
Linux Cli Copy Folder
All 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-pics
Copy and Paste Multiple Files
You 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 Multiple
All three files of differing file types will be copied to the Documents directory.

Copy and Paste All Files of the Same Type
If 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 Type
If 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 Folder
If 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.txt
There is one major difference, though. You don’t need the -r flag to move a whole folder.

mv ~/Downloads/downloaded-folder ~/Pictures/vacation-pics
That’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 DepositPhotos

Is this article useful?  
 
Popular Posts

Xfce Review: A Lean, Mean Linux Machine


How to Hide the Top Bar and Side Panel in Ubuntu 20.04


How to Share Files Between Android and Ubuntu on Your Network


How to Fix High CPU Usage in Linux


How to Speed Up Your Linux Desktop with Compton

Affiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.

Never Miss Out
Receive update of our latest tutorials.

Your email address
See all newsletters | Privacy Policy

如何在Linux终端中复制和粘贴文本、文件和文件夹

 

您其余所有语法都完全相同。该-r标志用于告诉cp它正在使用目录,并且应该复制其内容。

如果希望粘贴操作覆盖现有文件,则可以添加-f标志:

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

复制并粘贴多个文件

您也可以复制多个文件。Linux命令行使您可以使用括号同时定位多个项目{}。您可以使用它们列出要复制的每个文件的名称,并用逗号分隔。

cp ~/Downloads/{file1.txt,file2.jpg,file3.odt} ~/Documents/
如何在Linux终端中复制和粘贴文本、文件和文件夹

 

具有不同文件类型的所有三个文件都将被复制到Documents目录中。

复制和粘贴相同类型的所有文件

如果要复制大量相同类型的文件,则可以使用通配符*。星号/通配符告诉Linux命令行在该位置绝对接受任何内容。因此,如果您告诉Linux复制*.jpg,它将复制所有JPG文件,而不管名称是.jpg部分之前是什么。

cp ~/Downloads/*.jpg ~/Pictures/
如何在Linux终端中复制和粘贴文本、文件和文件夹

 

如果要使用多种文件类型(例如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命令对文件权限的作用的方法。

「真诚赞赏,手留余香」

求资源网

真诚赞赏,手留余香

使用微信扫描二维码完成支付

继续浏览有关教程的文章
发表评论
留言与评论(共有 0 条评论)
   
验证码:
版权声明

求资源网所发布的一切破解补丁,软件,以及其他分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途。
否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。