How to Use Linux to Copy Files and Folders

The 'cp' command duplicates files from the shell prompt

What to Know

  • Use the cp command in the following format: cp [option] source destination to copy files and folders to another directory.
  • Example: Copy sample.txt from /home/user/docs to /home/user/desktop: cp ~/docs/sample.txt ~/desktop/sample.txt
  • In a Linux desktop environment, right-click and drag the file. Release the mouse and choose copy and move options from the menu.

This article explains how to use the Linux cp command to copy files and folders from one directory to another. As with any Linux command, cp supports a variety of switches, and the command runs under the hood when you copy files using a graphical file manager.

Copy Files From the Shell Prompt

From a shell prompt, use the cp command. It takes the following general form:

cp [option] source destination

The command accepts a handful of specific options that present as switches. Check the manpage for cp or execute cp --help for a specific context.

For example, to copy the file sample.txt from /home/user/docs to /home/user/desktop, execute the following command:

cp ~/docs/sample.txt ~/desktop/sample.txt

The cp command works with hard and soft links, metacharacters, and wildcards.

Copy Files in the Desktop Environment

Because Linux offers several robust desktop environments, each DE's default file manager functions slightly differently. In general, though, graphical file managers all support the same conventions. To copy a file, right-click it and drag it; when you release the mouse, you'll see a context menu offering options including copying and moving.

This process works for the desktop, as well.

Some distributions do not allow files to appear on the desktop. Check your DE's settings to toggle whether files may appear on the desktop. This setting is not generally set in a graphical file manager, but rather in system-level settings, depending on the distribution.

Files that begin with a dot are, by default, hidden from display, although you can copy them even when they're hidden. Press Ctrl+H to view them in a graphical file manager or execute ls -a to display them in a listing within the shell.

Was this page helpful?