linx复制文件夹到u盘 (linix复制文件夹)

复制和粘贴是计算机上最常用的操作之一。使用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命令对文件权限的作用的方法。