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. If for some reason these keyboard shortcuts don’t work, the terminal might not be properly configured for it. Look for options that allow you to customize keyboard shortcuts. These are instructions for the most popular terminals:
Gnome Terminal – Click the hamburger menu and click “Preferences.” Navigate to “Shortcuts” and scroll to “Edit.” The options for “Copy” and “Paste” will appear there ready to be configured.Konsole – Go to “Settings” and then click on “Configure Keyboard Shortcuts.” Search for “Copy,” configure it to use the key combos mentioned previously, then do the same for “Paste.”
Most other terminals will lock you into the default universal combination for copying/pasting in the console without the ability to configure them.
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. That, of course, assumes that your file is in the same directory you’re working out of. You can specify both. You also have the option of renaming your file while copying it. Specify the new name in the destination.
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. 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:
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. 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. If you want to use multiple file types, say JPG and PNG, you can use the brackets from before.
Make Copying More Interactive
As you may have noticed while following this guide, using cp does not give you any sort of confirmation or prompt after finishing what it’s doing unless it encounters an error. This may cause a bit of discomfort especially when you’re doing very large file copy operations on slower hardware that could take a long time to complete. By attaching the -v flag to your command, you tell cp to give you its most detailed output on what it does. The -i flag provides confirmation prompts so that you have a chance to cancel certain operations like overwriting certain files. Generally the -v and -i flags are available in a large range of commands that are common to Linux.
Rsync vs CP
If you need to do several copy operations that overwrite files (such as creating a backup that you will update once in awhile) for some reason, rsync might just put a smile on your face. rsync is a little more advanced in that it goes into the minutiae of each file, does a full comparison of the data in both, and within the file itself, only overwrites the data that has changed. This is especially useful if the destination folder is in an SSD, as it saves write cycles and doesn’t needlessly degrade the drive’s health by overwriting entire files. Learn how to make use of rsync to copy files in Linux.
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. Similarly, you can also rename the file. There is one major difference, though. You don’t need the -r flag to move a whole folder. Image credit: Neron Photos on Pexels cp functions more as a Swiss Army knife that just wants to get the job done. If you have to overwrite something, cp does it for you. Because of its capability for interactivity, it’s also more beginner-friendly and gives you a bit more control over the copying process. If you configure the “Copy” function in your terminal to respond to that key combination, you will encounter problems when copying a line of text from an executing command while it’s still in the process of doing something.