How to copy a directory in Linux
How to copy a directory in Linux with a file manager or terminal
Knowing how to copy a directory in Linux systems like Ubuntu and Mint is essential for anyone looking to keep their computer's file system organized and efficient. Fortunately, Linux gives you several easy ways to do so using both desktop environment file explorers and Linux's trusty command-line terminal interface.
So whether you're new to Linux and just looking to learn the basics or you're a regular Linux user who wants to brush up an essential disk management tools, we're here to show you how to copy directories quickly and safely in Linux.
How to copy a directory on Linux desktop file explorers
The easiest way to copy a directory on Linux systems like Ubuntu or Mint is going to be through the desktop file explorer. If you're coming from Windows or MacOS, Linux desktop environments like Ubuntu's GNOME or Mint's Cinnamon will look familiar. They provide a simple visual interface for managing your computer's files and directories using cut, copy, and paste functionality.
Navigate through the file system to the directory containing the one you want to copy. After left-clicking on the directory icon, you have a couple of options for copying the directory to the system's clipboard. Some desktop environment use windows with menu bars along the top, so if one is available, you'll find the copy command inside the "Edit" dropdown menu.
You can also use the standard CTRL + C shortcut to copy the directory or you can use a context menu, brought up by right-clicking on the directory icon, and selecting copy.
Once a directory is copied to the clipboard, it can be pasted anywhere in the file system that your user account owns or at least has permission to modify (directories containing important system files, for example, often require higher-level permission to change).
Pasting the copied directory works just like copying it does. You can use the "Edit" dropdown menu (if available), the CTRL + V keyboard shortcut, or the right-click context menu to paste the directory into a location.
Get daily insight, inspiration and deals in your inbox
Sign up for breaking news, reviews, opinion, top tech deals, and more.
- These are the best Linux terminal emulators of 2020
- Find the best Linux distros for privacy and security for 2020
- Learn these six Linux terminal time savers
- Check out the best lightweight Linux distros of 2020
When you have navigated to the target location for the copied directory, if you have any other directory icons selected when you use the paste command, or you right-click a directory icon and select the paste option, you will copy into that directory, not the one you are currently in.
To copy into the current directory, make sure nothing is selected when pasting or right-click on any empty space inside the directory window and use the context menu.
If you are in a location that already contains a directory with the same name as the one you are copying, some Linux systems will append a suffix to the copied directory's name to prevent a conflict.
Others might ask what you wish to do to resolve the naming conflict and present a few solutions. This might include merging the two directories by pasting the contents of the directory you are copying into the existing directory.
- These are the best Linux distros for beginners
How to copy a directory using Linux's command-line interface
If you are using a version of Linux without a GUI or you are using a Linux terminal window, the above solutions obviously won't work. Luckily, the Linux command line isn't as complicated as it sometimes looks.
What's more, knowing how to copy a directory on Linux systems using Linux commands is necessary for more complicated file management projects like batch processing and renaming operations using a shell script.
- These are the best Linux laptops of 2020
The cp command is used to copy files as well as directories from the command line. By default, it only copies a single file so to make it copy a directory, you need to include the -r flag before its two required arguments, like this:
cp -r source destination
There is one key difference between the cp command and a Linux desktop's file explorer. With the cp command, attempting to copy a directory into a location that already contains a directory with the same name will result in an error, so make sure the copied directory doesn't conflict with what's already in that location.
- These are the best Linux training providers and online courses
John (He/Him) is the Components Editor here at TechRadar and he is also a programmer, gamer, activist, and Brooklyn College alum currently living in Brooklyn, NY.
Named by the CTA as a CES 2020 Media Trailblazer for his science and technology reporting, John specializes in all areas of computer science, including industry news, hardware reviews, PC gaming, as well as general science writing and the social impact of the tech industry.
You can find him online on Bluesky @johnloeffler.bsky.social