The basic command to copy a folder

To copy a folder in Linux, use the cp command with the -r flag, which tells the system to copy recursively — meaning it copies the folder and everything inside it. The basic structure is: cp -r source_folder destination_folder

For example, if you have a folder called "Documents" in your home directory and want to copy it to your Desktop, you would type: cp -r ~/Documents ~/Desktop/Documents. The system will create a new folder called Documents on your Desktop with all the same files and subfolders inside.

If you want to copy the folder into an existing folder rather than create a new one with the same name, you can omit the final folder name. For instance, cp -r ~/Documents ~/Desktop copies Documents into Desktop, so the files end up at ~/Desktop/Documents.

Key Takeaways

  • The cp -r command copies a folder and all its contents; the -r flag is required for folders.
  • Always specify both the source folder (what you are copying) and the destination (where it goes), separated by a space.
  • Use cp -r -v to see each file as it copies, which helps you confirm the operation is working on large folders.
  • The -i flag (as in cp -r -i) prompts you before overwriting if a folder with that name already exists.

Copying to a different location with a new name

You can copy a folder and rename it at the same time by specifying a different name in the destination path. For example, cp -r ~/Documents ~/Desktop/Documents_backup creates a copy of Documents on your Desktop but names it Documents_backup instead.

This is useful when you want to keep the original folder in place and create a backup or variant with a different name. The new folder is completely independent — changes to one do not affect the other.

Copying a folder to the current directory

If you are already inside the folder where you want the copy to appear, you can use a dot (.) to represent the current directory. For example, if you are on your Desktop and want to copy a folder from your Documents, type: cp -r ~/Documents .

This copies the Documents folder into your current location (Desktop) and keeps the same name. The dot is a shorthand that saves you from typing out the full path.

Seeing what is being copied with the verbose flag

When you copy a large folder with many files, the command may take a few seconds or longer, and you might wonder if anything is happening. Add the -v flag (for verbose) to see each file as it copies: cp -r -v ~/Documents ~/Desktop/Documents

The system will print the name of each file and subfolder as it copies them. This is especially helpful if you are copying thousands of files and want to confirm the operation is progressing rather than frozen.

Protecting against accidental overwrites

If a folder with the destination name already exists, cp will overwrite it by default — meaning files inside the existing folder may be replaced or deleted. To prevent this, use the -i flag, which prompts you before overwriting: cp -r -i ~/Documents ~/Desktop/Documents

When you run this command and a folder named Documents already exists on your Desktop, the system will ask "overwrite ~/Desktop/Documents?" and wait for you to type y (yes) or n (no). This gives you a chance to stop the operation if you realize you are about to overwrite something you wanted to keep.

Copying multiple folders at once

You can copy more than one folder in a single command by listing each source folder before the destination. For example: cp -r ~/Documents ~/Pictures ~/Desktop copies both Documents and Pictures into your Desktop folder.

The last path in the command is always treated as the destination, and everything before it is copied there. This works only if the destination is a folder that already exists — if it does not, the command will fail.

What to do if you get a permission error

If you see a message like "Permission denied" when trying to copy a folder, it usually means the folder or one of its files is owned by another user or has restricted permissions. You may be able to copy it anyway by using sudo (which runs the command with administrator privileges): sudo cp -r /path/to/folder ~/Desktop

Be cautious with sudo — it gives the command full system access. Only use it when you are certain the folder is one you should be copying. If you use sudo, the copied folder will be owned by the root user, which may cause problems later; you can change ownership afterward with sudo chown -R $USER ~/Desktop/folder_name.

Frequently Asked Questions

What is the difference between cp and cp -r?

cp alone copies only single files. cp -r copies folders and everything inside them recursively. If you try to use cp without the -r flag on a folder, you will get an error message saying "is a directory".

Can I copy a folder to itself?

No — copying a folder into itself will cause an error or create an infinite loop. Always make sure your destination is different from your source, or at least that the destination folder does not already contain the source folder.

How do I copy a folder but leave out certain files?

The basic cp command does not have a built-in exclude option. For selective copying, you can use rsync instead: rsync -r --exclude='*.tmp' ~/Documents ~/Desktop/Documents copies Documents but skips any files ending in .tmp. This is more complex but gives you fine control over what gets copied.

Does copying a folder take up extra disk space?

Yes — a copy uses as much disk space as the original. If your Documents folder is 5 GB, copying it will use another 5 GB on your drive. Make sure you have enough free space before copying large folders.

Can I copy a folder from one computer to another?

Not with cp alone — that command works only on your local machine. To copy to another computer, use scp (find copy): scp -r ~/Documents username@remote_computer:/path/to/destination. You will need SSH access to the other computer and permission to write to the destination folder.