How to Copy (and Paste) Files and Directories from Linux Command Line

Linux Cli Copy Featured

Copying and pasting files is one of the most basic things you can do on a computer. On Linux, you have several options to get the job done. On the command line things are more direct, giving you more control, and in some cases, simplifying things dramatically.

Copy a Single File

Linux Cli Copy Document

Any time you want to copy a file or folder in the Linux command line, you’re going 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 a Folder and Its Contents

Linux Cli Copy Folder

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.

Copy Multiple Files

Linux Cli Copy Multiple

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 All Files of the Same Type

Linux Cli Copy All File 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.

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 it.

There is one major difference, though. You don’t need the -r flag to move a whole folder.

That’s all there really 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 Linux? Here’s how to fix the infamous “No space left on device” error. We can also show you how to reset the root password in Linux. Dive on in!


  1. You’ve used “your-file.txt” in several examples. Does that mean I should write “red-rose.txt” if the file name is “red rose.txt”?

  2. I believe this copy systax is wrong. You have to use a . somewhere in the arguement to tell it to copy to the same name or something. All your examples provide syntax errors.

Comments are closed.