How to copy a directory in Linux
How to copy a directory in Linux with a file manager or terminal
When you purchase through links on our site, we may earn an affiliate commission.Here’s how it works.
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 standardCTRL + Cshortcut 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 thatyour user account ownsor 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), theCTRL + Vkeyboard shortcut, or the right-click context menu to paste the directory into a location.
Get the best Black Friday deals direct to your inbox, plus news, reviews, and more.
Sign up to be the first to know about unmissable Black Friday deals on top tech, plus get all your favorite TechRadar content.
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.
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 usingLinux commandsis necessary for more complicated file management projects like batch processing and renaming operations using a shell script.
Thecpcommand 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-rflag before its two required arguments, like this:
There is one key difference between thecpcommand and a Linux desktop’s file explorer. With thecpcommand, 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.
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 Threads @johnloeffler.
Currently playing: Baldur’s Gate 3 (just like everyone else).
Anthropic’s new Claude 3.5 Haiku AI model is 4 times more expensive than its predecessor
Your doctor may have an AI assistant taking notes during your next Zoom call
Black Friday is here: Sony XM5 over-ears drop to their lowest-seen price – act fast!