How to copy and paste in Linux

You may be used to a GUI, where you would copy files by right-clicking on the file, selecting “Copy”, then going to a different directory and selecting “Paste”.

If you need to perform the same action in CLI/Terminal then you can use the “cp” command which means copy [to].

The syntax is; cp [file name and location] [location to be pasted to]

Example: If I want to copy a file from the Doanloads folder on my machine over to a USB drive, I would do the following;

cp -r /home/YourHostname/Downloads/Folder1 /media/starz/USBdriveName

cp /home/YourHostname/Downloads/File1 /media/starz/USBdriveName

The same example above except we’ll copy a folder/directory instead of a file;

Notes:

  • If you’re in the same directory as the file to be copied then you can just input the file name without the file path
  • If you’re copying a whole folder/directory then you need to insert the -r switch after cp. This recursively copies a directory and its contents (which could be files or other sub directories)
  • If there is a specific folder you want to paste into then add the file path as needed
  • If you want to copy multiple files/folders then you don’t need to do these one by one, just seperate the file/folders to be copied by a space or in some cases a single or double quote i.e. 'example' or "example" this is where it can certainly be more efficient to use Terminal instead of GUI
  • You can copy items which may have a pattern. Let’s say you have files named file1.txt and file2.txt and file3.txt – instead of itemising these individually, you can use a wildcard instead. Therefore the command to copy all files with the .txt extension would be;
  • cp /home/YourHostname/Downloads/*.txt /media/starz/USBdriveName