Copying and pasting is one of the most used actions on a computer. While it is easy to do so with the Ctrl + C and Ctrl + V keyboard shortcuts, on the Linux terminal it is not so straightforward. You have several options to get the job done. Here is how you can copy and paste text, files and directories in Linux terminal.
Copy and Paste Text
If you just want to copy a piece of text in the terminal, all you need to do is highlight it with your mouse, then press Ctrl + Shift + C to copy.
To paste it where the cursor is, use the keyboard shortcut Ctrl + Shift + V.
The Paste shortcut also applies when you copy a section of text from a Word document (or any other application) and want to paste it in the terminal. For example, you can copy a command from a web page in your browser and use the Ctrl + Shift + V shortcut to paste it in the terminal.
Copy and Paste a Single File
Any time you want to copy a file or folder in the Linux command line, the above keyboard shortcut won’t work. You have to use the cp
command. cp is shorthand for copy. The syntax is simple, too. Use cp
followed by the file you want to copy and the destination where you want it moved.
cp your-file.txt ~/Documents/

That, of course, assumes that your file is in the same directory you’re working out of. You can specify both.
cp ~/Downloads/your-file.txt ~/Documents/
You also have the option of renaming your file while copying it. Specify the new name in the destination.
cp ~/Downloads/your-file.txt ~/Documents/new-name.txt
Copy and Paste a Folder and Its Contents
In order to copy a folder and its contents, you’re going to need to tell the cp
command to copy recursively. That’s simple enough with the -r
flag.
cp -r ~/Downloads/pictures-directory ~/Pictures/family-vacation-pics

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/

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/

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
I`m using debian 10.4 and none of the copy=paste commands will work with my terminal.
I often use those commands in Termux and they work!