🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 139 (from laksa162)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
3 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal
Last Crawled2026-04-14 11:14:48 (3 days ago)
First Indexed2025-06-09 16:22:09 (10 months ago)
HTTP Status Code200
Meta TitleHow To Copy Files and Directories in the Linux terminal | Tom's Hardware
Meta DescriptionCopy files and directories via the Linux command line
Meta Canonicalnull
Boilerpipe Text
Copying files and directories in the Linux terminal is really efficient and straightforward once you know how to do it. It’s useful when we need to manage our files and directories without the need for a GUI, for example in a BASH script. We can do this whether we are at our desk or if we are accessing a machine remotely via SSH. In this how-to we’ll look at the cp command which copies files and directories. We’ll look at some arguments that we can add to get the most out of this command. While you become accustomed to these commands it’s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions. Article continues below All the commands in this how-to will work on most Linux machines. We’ve used an Ubuntu LTS install but you could run this how-to on a Raspberry Pi . All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t. How to Copy a Single File in Linux (Image credit: Tom's Hardware) Let’s start really simply by copying a single file. The command syntax is structured as follows. cp <location and name of item to copy> <location and name for copied item> 1. Create a new file called test1.txt. touch test1.txt 2. List the contents of the directory to check if the file has been created. You should now see the file test1.txt. Get Tom's Hardware's best news and in-depth reviews, straight to your inbox. ls 3. Copy the test1.txt file and rename it to test2.txt. This copies the item into the same directory as the original but into a new file. cp test1.txt test2.txt 4. List the contents of the directory to check the file has been copied and renamed. You should see that the original file test1.txt is listed and the copied file test2.txt is listed. ls How to Copy a Directory in Linux (Image credit: Tom's Hardware) Let’s run through a similar example to show that cp can be used to copy a directory by using the -r argument. Though we have used an empty directory as an example, any directory contents would also be copied to the new directory using this argument. 1. Create an empty directory in your home directory. mkdir test_directory 2. Copy and rename the new directory. cp -r test_directory test_directory_2 3. List the directory contents to check the copied directory is created. You should see the directories test_directory and test_directory_2 listed. ls How to Copy Files to a Different Location in Linux (Image credit: Tom's Hardware) For the next example let’s look at copying a file to a different location. 1. Create an empty directory in your home directory. mkdir test_directory 2. Create a test file in your home directory. touch test1.txt 3. Copy the test file from the home directory into the test directory. This copies test1.txt from the home directory into test_directory. $ cp test1.txt test_directory 4. Check the file has been copied correctly by changing directory to test_directory and listing the contents. cd test_directory ls How to Copy Files to and From Directories While Renaming Them (Image credit: Tom's Hardware) If you know the location of a file and the target location you want to copy the file to, you don’t need to move into the directories directly and you can run the cp command from the home directory. Here’s an example of how it could be done. 1. Create 2 empty directories. From the home directory run the following command to create two new directories. mkdir folder1 folder2 2. Move inside folder1 and make a test file called test1.txt. cd folder1 touch test1.txt 3. Return to the home directory. cd 4. Copy and rename the test file from the home directory. We can supply the cp command with the name and location of the target file to copy and where to copy the file, renaming it to test2.txt along the way. cp folder1/test1.txt folder2/test2.txt 5. Check that the file has been copied correctly by changing directory to folder2 and listing the contents. Use cd to change directory and ls to check the file copied correctly. You should see test2.txt listed inside folder2 . cd folder2 ls How to Copy a File to a Parent Directory (Image credit: Tom's Hardware) As you move through directories you may need to occasionally copy a file to the parent directory of a current location. This can be achieved without having to type long directory locations into a command by using .. to target the parent directory. Here’s how. 1. Create a test directory using mkdir . mkdir test_directory 2. Move into test_directory . cd test_directory 3. Create a test file inside test_directory. touch test1.txt 4. Copy test1.txt to the parent directory. Here we simply add .. to the cp command to create a copy of test1.txt into the parent directory of the current location. cp test1.txt .. 5. Move to the parent directory and check if the file has been copied. You should see that test1.txt is now listed at this location. cd ls As you can see the cp command is very simple to use but is very capable and, with a little practice, it’s often much quicker to be able to surgically copy and rename files using cp than using graphical interface tools.
Markdown
![](https://sb.scorecardresearch.com/p/?c1=2&c2=10055482&cv=4.4.0&cj=1) [Skip to main content](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal#main) Open menu [![Tom's Hardware](https://www.tomshardware.com/media/img/brand_logo.svg) Tom's Hardware](https://www.tomshardware.com/uk) UK Edition ![flag of GB](https://vanilla.futurecdn.net/tomshardware/media/shared/img/flags/nosize/GB.svg) [![UK Edition](https://vanilla.futurecdn.net/tomshardware/media/shared/img/flags/nosize/GB.svg)UK](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal) [![US Edition](https://vanilla.futurecdn.net/tomshardware/media/shared/img/flags/nosize/US.svg)US](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal) [![AU Edition](https://vanilla.futurecdn.net/tomshardware/media/shared/img/flags/nosize/AU.svg)Australia](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal) [![CA Edition](https://vanilla.futurecdn.net/tomshardware/media/shared/img/flags/nosize/CA.svg)Canada](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal) [RSS](https://www.tomshardware.com/uk/feeds.xml) Subscribe Sign in - View Profile - Sign out Search - [Best Picks](https://www.tomshardware.com/uk/best-picks) - CPU Buying Advice - [CPU Best Picks](https://www.tomshardware.com/uk/pc-components/cpus/best-picks) - [CPU Reviews](https://www.tomshardware.com/uk/pc-components/cpus/reviews) - GPU Buying Advice - [GPU Best Picks](https://www.tomshardware.com/reviews/best-gpus,4380.html) - [GPU Reviews](https://www.tomshardware.com/uk/pc-components/gpus/reviews) - Laptop Buying Advice - [Laptop Best Picks](https://www.tomshardware.com/uk/laptops/best-picks) - [Laptop Reviews](https://www.tomshardware.com/uk/laptops/reviews) - More Buying Advice - [Keyboard Best Picks](https://www.tomshardware.com/uk/peripherals/keyboards/best-picks) - [Gaming Monitor Best Picks](https://www.tomshardware.com/uk/monitors/gaming-monitors/best-picks) - [Gaming Headset Best Picks](https://www.tomshardware.com/uk/peripherals/headphones-headsets/gaming-headsets/best-picks) - [3D Printer Best Picks](https://www.tomshardware.com/uk/3d-printing/best-picks) - [Webcam Best Picks](https://www.tomshardware.com/uk/peripherals/webcams/best-picks) - [Mice Best Picks](https://www.tomshardware.com/uk/peripherals/mice/best-picks) - [How We Test](https://www.tomshardware.com/news/how-we-test) - [CPUs](https://www.tomshardware.com/uk/pc-components/cpus) - CPU Brands - [AMD Ryzen](https://www.tomshardware.com/uk/tag/ryzen) - [Intel Lunar Lake](https://www.tomshardware.com/uk/tag/lunar-lake) - [Nvidia](https://www.tomshardware.com/uk/tag/nvidia) - [Qualcomm](https://www.tomshardware.com/uk/tag/qualcomm) - [Apple](https://www.tomshardware.com/uk/tag/apple) - [Benchmarking](https://www.tomshardware.com/uk/tag/benchmark) - Platforms - [X86](https://www.tomshardware.com/uk/tag/x86) - [ARM](https://www.tomshardware.com/uk/tag/arm) - [Panther Lake](https://www.tomshardware.com/uk/tag/panther-lake) - [Zen 5](https://www.tomshardware.com/uk/tag/zen-5) - [AM5](https://www.tomshardware.com/uk/tag/am5) - [Chipmaking](https://www.tomshardware.com/uk/tag/chip) - [DUV](https://www.tomshardware.com/uk/tag/duv) - [EUV](https://www.tomshardware.com/uk/tag/euv) - [Rare Earth Metals](https://www.tomshardware.com/uk/tag/rare-earth-metals) - [GPUs](https://www.tomshardware.com/uk/pc-components/gpus) - GPU Brands - [Nvidia Blackwell](https://www.tomshardware.com/uk/tag/nvidia-blackwell) - [Nvidia Geforce](https://www.tomshardware.com/uk/tag/geforce) - [AMD Radeon](https://www.tomshardware.com/uk/tag/radeon) - [Intel Arc](https://www.tomshardware.com/uk/tag/intel-arc) - [Snapdragon X](https://www.tomshardware.com/uk/tag/snapdragon-x) - [Benchmarking](https://www.tomshardware.com/uk/tag/benchmark) - Memory Tech - [GDDR7](https://www.tomshardware.com/uk/tag/gddr7) - [GDDR8](https://www.tomshardware.com/uk/tag/gddr8) - [HBM](https://www.tomshardware.com/uk/tag/hbm) - AI Architecture - [Nvidia Vera Rubin](https://www.tomshardware.com/uk/tag/vera-rubin) - [Meta MTIA](https://www.tomshardware.com/uk/tag/mtia) - [Google TPU](https://www.tomshardware.com/uk/tag/tpu) - [AMD Instinct](https://www.tomshardware.com/uk/tag/instinct) - [Microsoft Maia](https://www.tomshardware.com/uk/tag/maia) - [Drivers](https://www.tomshardware.com/uk/pc-components/gpus/gpu-drivers) - [PC Components](https://www.tomshardware.com/uk/pc-components) - Memory - [RAM](https://www.tomshardware.com/uk/pc-components/ram) - [DRAM](https://www.tomshardware.com/uk/pc-components/ram/dram) - [DDR5](https://www.tomshardware.com/uk/pc-components/ram/dram/ddr5) - [Storage](https://www.tomshardware.com/uk/pc-components/storage) - [HDDs](https://www.tomshardware.com/uk/pc-components/storage/hdds) - [SSDs](https://www.tomshardware.com/uk/pc-components/storage/ssds) - [Cooling](https://www.tomshardware.com/uk/pc-components/cooling) - [Air Cooling](https://www.tomshardware.com/uk/pc-components/cooling/air-cooling) - [Liquid Cooling](https://www.tomshardware.com/uk/pc-components/cooling/liquid-cooling) - [Thermal Paste](https://www.tomshardware.com/uk/pc-components/cooling/thermal-paste) - [Networking](https://www.tomshardware.com/uk/networking) - [Routers](https://www.tomshardware.com/uk/networking/routers) - [Motherboards](https://www.tomshardware.com/uk/pc-components/motherboards) - [Overclocking](https://www.tomshardware.com/uk/pc-components/overclocking) - [PC Cases](https://www.tomshardware.com/uk/pc-components/pc-cases) - [PC Building](https://www.tomshardware.com/uk/desktops/pc-building) - [Power Supplies](https://www.tomshardware.com/uk/pc-components/power-supplies) - [News](https://www.tomshardware.com/uk/news) - [Tech Industry News](https://www.tomshardware.com/uk/tech-industry) - [CPU News](https://www.tomshardware.com/uk/pc-components/cpus/news) - [GPU News](https://www.tomshardware.com/uk/pc-components/gpus/news) - [Chips Act](https://www.tomshardware.com/uk/tag/chips-and-science-act) - [Semiconductors](https://www.tomshardware.com/uk/tech-industry/manufacturing/semiconductors) - [Cybersecurity](https://www.tomshardware.com/uk/tech-industry/cyber-security) - [Supercomputers](https://www.tomshardware.com/uk/tech-industry/supercomputers) - [Quantum Computing](https://www.tomshardware.com/uk/tech-industry/quantum-computing) - Company News - [AMD](https://www.tomshardware.com/uk/tag/amd) - [Intel](https://www.tomshardware.com/uk/tag/intel) - [Nvidia](https://www.tomshardware.com/uk/tag/nvidia) - [Radeon](https://www.tomshardware.com/uk/tag/radeon) - [Microsoft](https://www.tomshardware.com/uk/tag/microsoft) - [TSMC](https://www.tomshardware.com/uk/tag/tsmc) - [Ryzen](https://www.tomshardware.com/uk/tag/ryzen) - [IBM](https://www.tomshardware.com/uk/tag/ibm) - [Newsletter](https://www.tomshardware.com/how-to/sign-up-for-newsletter) - [Laptops](https://www.tomshardware.com/uk/laptops) - [Gaming Laptops](https://www.tomshardware.com/uk/laptops/gaming-laptops) - [Ultrabooks](https://www.tomshardware.com/uk/laptops/ultrabooks-ultraportables) - [MacBooks](https://www.tomshardware.com/uk/laptops/macbooks) - Laptop Brands - [Asus](https://www.tomshardware.com/uk/tag/asus) - [Razer](https://www.tomshardware.com/uk/tag/razer) - [HP](https://www.tomshardware.com/uk/tag/hp) - [MSI](https://www.tomshardware.com/uk/tag/msi) - [Desktops](https://www.tomshardware.com/uk/desktops) - [PC Building](https://www.tomshardware.com/uk/desktops/pc-building) - [PC Cases](https://www.tomshardware.com/uk/pc-components/pc-cases) - [Gaming PCs](https://www.tomshardware.com/uk/desktops/gaming-pcs) - [Monitors](https://www.tomshardware.com/uk/monitors) - [Gaming Monitors](https://www.tomshardware.com/uk/monitors/gaming-monitors) - [Peripherals](https://www.tomshardware.com/uk/peripherals) - [Keyboards](https://www.tomshardware.com/uk/peripherals/keyboards) - [Mice](https://www.tomshardware.com/uk/peripherals/mice) - [3D Printers](https://www.tomshardware.com/uk/3d-printing) - [Headphones](https://www.tomshardware.com/uk/peripherals/headphones-headsets) - Desktop Brands - [Alienware](https://www.tomshardware.com/uk/tag/alienware) - [Corsair](https://www.tomshardware.com/uk/tag/corsair) - [GeForce](https://www.tomshardware.com/uk/tag/geforce) - [Intel Arc](https://www.tomshardware.com/uk/tag/intel-arc) - [Gigabyte](https://www.tomshardware.com/uk/tag/gigabyte) - [Acer](https://www.tomshardware.com/uk/tag/acer) - [Software & AI](https://www.tomshardware.com/uk/software) - [Artificial Intelligence](https://www.tomshardware.com/uk/tech-industry/artificial-intelligence) - [Machine Learning](https://www.tomshardware.com/uk/tag/machine-learning) - [R\&D](https://www.tomshardware.com/uk/tag/randd) - [Intel Gaudi](https://www.tomshardware.com/uk/tag/gaudi) - [Cerebras](https://www.tomshardware.com/uk/tag/cerebras) - [xAI](https://www.tomshardware.com/uk/tag/xai) - [LLMs](https://www.tomshardware.com/uk/tag/llm) - [OpenAI](https://www.tomshardware.com/uk/tag/openai) - [Anthropic](https://www.tomshardware.com/uk/tag/anthropic) - [DeepSeek](https://www.tomshardware.com/uk/tag/deepseek) - [Gemini](https://www.tomshardware.com/uk/tag/gemini) - [Grok](https://www.tomshardware.com/uk/tag/grok) - [Operating Systems](https://www.tomshardware.com/uk/software/operating-systems) - [Windows](https://www.tomshardware.com/uk/software/operating-systems/windows) - [MacOS](https://www.tomshardware.com/uk/software/operating-systems/macos) - [iOS](https://www.tomshardware.com/uk/software/operating-systems/ios) - [ChromeOS](https://www.tomshardware.com/uk/software/operating-systems/chromeos) - [Linux](https://www.tomshardware.com/uk/software/operating-systems/linux) - [Software](https://www.tomshardware.com/uk/software) - [Programming](https://www.tomshardware.com/uk/software/programming) - [Applications](https://www.tomshardware.com/uk/software/applications) - [Microsoft Office](https://www.tomshardware.com/uk/software/applications/microsoft-office) - [Web Browsers](https://www.tomshardware.com/uk/software/browsers) - [Coupons](https://www.tomshardware.com/coupons) - [Laptop and PC Coupons](https://www.tomshardware.com/coupons/category/laptops-and-computers) - [Dell Coupon Codes](https://www.tomshardware.com/coupons/dell.com) - [Asus Coupon Codes](https://www.tomshardware.com/coupons/ASUS) - [Logitech Promo Codes](https://www.tomshardware.com/coupons/logitech.com) - [Samsung Promo codes](https://www.tomshardware.com/coupons/samsung.com) - [Hardware Coupons](https://www.tomshardware.com/coupons/category/ssds-motherboards-and-hardware) - [Newegg Promo Codes](https://www.tomshardware.com/coupons/newegg.com) - [Corsair Discount Codes](https://www.tomshardware.com/coupons/corsair.com) - [Razer Promo Codes](https://www.tomshardware.com/coupons/razer.com) - [Anycubic Discount codes](https://www.tomshardware.com/coupons/anycubic) - [Software Coupons](https://www.tomshardware.com/coupons/category/online-software) - [Bitdefender Coupons](https://www.tomshardware.com/coupons/bitdefender.com) - [Simplisafe Coupons](https://www.tomshardware.com/coupons/simplisafe.com) - [MacPaw Coupons](https://www.tomshardware.com/coupons/macpaw.com) - [Squarespace Coupon Codes](https://www.tomshardware.com/coupons/squarespace) - [Gaming Coupons](https://www.tomshardware.com/coupons/category/video-games) - [Kinguin Discount Codes](https://www.tomshardware.com/coupons/kinguin.net) - [Loaded Discount Codes](https://www.tomshardware.com/coupons/cdkeys.com) - [Logitech G Promo Codes](https://www.tomshardware.com/coupons/logitechg.com) - [SteelSeries Coupons](https://www.tomshardware.com/coupons/steelseries) - More [Premium](https://www.tomshardware.com/uk/premium) [Forums](https://forums.tomshardware.com/) - [Home](https://www.tomshardware.com/uk) - [Best Picks](https://www.tomshardware.com/uk/best-picks) - [View Best Picks](https://www.tomshardware.com/uk/best-picks) - CPU Buying Advice - [CPU Best Picks](https://www.tomshardware.com/uk/pc-components/cpus/best-picks) - [CPU Reviews](https://www.tomshardware.com/uk/pc-components/cpus/reviews) - GPU Buying Advice - [GPU Best Picks](https://www.tomshardware.com/reviews/best-gpus,4380.html) - [GPU Reviews](https://www.tomshardware.com/uk/pc-components/gpus/reviews) - Laptop Buying Advice - [Laptop Best Picks](https://www.tomshardware.com/uk/laptops/best-picks) - [Laptop Reviews](https://www.tomshardware.com/uk/laptops/reviews) - More Buying Advice - [Keyboard Best Picks](https://www.tomshardware.com/uk/peripherals/keyboards/best-picks) - [Gaming Monitor Best Picks](https://www.tomshardware.com/uk/monitors/gaming-monitors/best-picks) - [Gaming Headset Best Picks](https://www.tomshardware.com/uk/peripherals/headphones-headsets/gaming-headsets/best-picks) - [3D Printer Best Picks](https://www.tomshardware.com/uk/3d-printing/best-picks) - [Webcam Best Picks](https://www.tomshardware.com/uk/peripherals/webcams/best-picks) - [Mice Best Picks](https://www.tomshardware.com/uk/peripherals/mice/best-picks) - [How We Test](https://www.tomshardware.com/news/how-we-test) - [CPUs](https://www.tomshardware.com/uk/pc-components/cpus) - [View CPUs](https://www.tomshardware.com/uk/pc-components/cpus) - CPU Brands - [AMD Ryzen](https://www.tomshardware.com/uk/tag/ryzen) - [Intel Lunar Lake](https://www.tomshardware.com/uk/tag/lunar-lake) - [Nvidia](https://www.tomshardware.com/uk/tag/nvidia) - [Qualcomm](https://www.tomshardware.com/uk/tag/qualcomm) - [Apple](https://www.tomshardware.com/uk/tag/apple) - [Benchmarking](https://www.tomshardware.com/uk/tag/benchmark) - Platforms - [X86](https://www.tomshardware.com/uk/tag/x86) - [ARM](https://www.tomshardware.com/uk/tag/arm) - [Panther Lake](https://www.tomshardware.com/uk/tag/panther-lake) - [Zen 5](https://www.tomshardware.com/uk/tag/zen-5) - [AM5](https://www.tomshardware.com/uk/tag/am5) - [Chipmaking](https://www.tomshardware.com/uk/tag/chip) - [View Chipmaking](https://www.tomshardware.com/uk/tag/chip) - [DUV](https://www.tomshardware.com/uk/tag/duv) - [EUV](https://www.tomshardware.com/uk/tag/euv) - [Rare Earth Metals](https://www.tomshardware.com/uk/tag/rare-earth-metals) - [GPUs](https://www.tomshardware.com/uk/pc-components/gpus) - [View GPUs](https://www.tomshardware.com/uk/pc-components/gpus) - GPU Brands - [Nvidia Blackwell](https://www.tomshardware.com/uk/tag/nvidia-blackwell) - [Nvidia Geforce](https://www.tomshardware.com/uk/tag/geforce) - [AMD Radeon](https://www.tomshardware.com/uk/tag/radeon) - [Intel Arc](https://www.tomshardware.com/uk/tag/intel-arc) - [Snapdragon X](https://www.tomshardware.com/uk/tag/snapdragon-x) - [Benchmarking](https://www.tomshardware.com/uk/tag/benchmark) - Memory Tech - [GDDR7](https://www.tomshardware.com/uk/tag/gddr7) - [GDDR8](https://www.tomshardware.com/uk/tag/gddr8) - [HBM](https://www.tomshardware.com/uk/tag/hbm) - AI Architecture - [Nvidia Vera Rubin](https://www.tomshardware.com/uk/tag/vera-rubin) - [Meta MTIA](https://www.tomshardware.com/uk/tag/mtia) - [Google TPU](https://www.tomshardware.com/uk/tag/tpu) - [AMD Instinct](https://www.tomshardware.com/uk/tag/instinct) - [Microsoft Maia](https://www.tomshardware.com/uk/tag/maia) - [Drivers](https://www.tomshardware.com/uk/pc-components/gpus/gpu-drivers) - [PC Components](https://www.tomshardware.com/uk/pc-components) - [View PC Components](https://www.tomshardware.com/uk/pc-components) - Memory - [RAM](https://www.tomshardware.com/uk/pc-components/ram) - [DRAM](https://www.tomshardware.com/uk/pc-components/ram/dram) - [DDR5](https://www.tomshardware.com/uk/pc-components/ram/dram/ddr5) - [Storage](https://www.tomshardware.com/uk/pc-components/storage) - [View Storage](https://www.tomshardware.com/uk/pc-components/storage) - [HDDs](https://www.tomshardware.com/uk/pc-components/storage/hdds) - [SSDs](https://www.tomshardware.com/uk/pc-components/storage/ssds) - [Cooling](https://www.tomshardware.com/uk/pc-components/cooling) - [View Cooling](https://www.tomshardware.com/uk/pc-components/cooling) - [Air Cooling](https://www.tomshardware.com/uk/pc-components/cooling/air-cooling) - [Liquid Cooling](https://www.tomshardware.com/uk/pc-components/cooling/liquid-cooling) - [Thermal Paste](https://www.tomshardware.com/uk/pc-components/cooling/thermal-paste) - [Networking](https://www.tomshardware.com/uk/networking) - [View Networking](https://www.tomshardware.com/uk/networking) - [Routers](https://www.tomshardware.com/uk/networking/routers) - [Motherboards](https://www.tomshardware.com/uk/pc-components/motherboards) - [Overclocking](https://www.tomshardware.com/uk/pc-components/overclocking) - [PC Cases](https://www.tomshardware.com/uk/pc-components/pc-cases) - [PC Building](https://www.tomshardware.com/uk/desktops/pc-building) - [Power Supplies](https://www.tomshardware.com/uk/pc-components/power-supplies) - [News](https://www.tomshardware.com/uk/news) - [View News](https://www.tomshardware.com/uk/news) - [Tech Industry News](https://www.tomshardware.com/uk/tech-industry) - [View Tech Industry News](https://www.tomshardware.com/uk/tech-industry) - [CPU News](https://www.tomshardware.com/uk/pc-components/cpus/news) - [GPU News](https://www.tomshardware.com/uk/pc-components/gpus/news) - [Chips Act](https://www.tomshardware.com/uk/tag/chips-and-science-act) - [Semiconductors](https://www.tomshardware.com/uk/tech-industry/manufacturing/semiconductors) - [Cybersecurity](https://www.tomshardware.com/uk/tech-industry/cyber-security) - [Supercomputers](https://www.tomshardware.com/uk/tech-industry/supercomputers) - [Quantum Computing](https://www.tomshardware.com/uk/tech-industry/quantum-computing) - Company News - [AMD](https://www.tomshardware.com/uk/tag/amd) - [Intel](https://www.tomshardware.com/uk/tag/intel) - [Nvidia](https://www.tomshardware.com/uk/tag/nvidia) - [Radeon](https://www.tomshardware.com/uk/tag/radeon) - [Microsoft](https://www.tomshardware.com/uk/tag/microsoft) - [TSMC](https://www.tomshardware.com/uk/tag/tsmc) - [Ryzen](https://www.tomshardware.com/uk/tag/ryzen) - [IBM](https://www.tomshardware.com/uk/tag/ibm) - [Newsletter](https://www.tomshardware.com/how-to/sign-up-for-newsletter) - [Laptops](https://www.tomshardware.com/uk/laptops) - [View Laptops](https://www.tomshardware.com/uk/laptops) - [Gaming Laptops](https://www.tomshardware.com/uk/laptops/gaming-laptops) - [Ultrabooks](https://www.tomshardware.com/uk/laptops/ultrabooks-ultraportables) - [MacBooks](https://www.tomshardware.com/uk/laptops/macbooks) - Laptop Brands - [Asus](https://www.tomshardware.com/uk/tag/asus) - [Razer](https://www.tomshardware.com/uk/tag/razer) - [HP](https://www.tomshardware.com/uk/tag/hp) - [MSI](https://www.tomshardware.com/uk/tag/msi) - [Desktops](https://www.tomshardware.com/uk/desktops) - [View Desktops](https://www.tomshardware.com/uk/desktops) - [PC Building](https://www.tomshardware.com/uk/desktops/pc-building) - [View PC Building](https://www.tomshardware.com/uk/desktops/pc-building) - [PC Cases](https://www.tomshardware.com/uk/pc-components/pc-cases) - [Gaming PCs](https://www.tomshardware.com/uk/desktops/gaming-pcs) - [Monitors](https://www.tomshardware.com/uk/monitors) - [View Monitors](https://www.tomshardware.com/uk/monitors) - [Gaming Monitors](https://www.tomshardware.com/uk/monitors/gaming-monitors) - [Peripherals](https://www.tomshardware.com/uk/peripherals) - [View Peripherals](https://www.tomshardware.com/uk/peripherals) - [Keyboards](https://www.tomshardware.com/uk/peripherals/keyboards) - [Mice](https://www.tomshardware.com/uk/peripherals/mice) - [3D Printers](https://www.tomshardware.com/uk/3d-printing) - [Headphones](https://www.tomshardware.com/uk/peripherals/headphones-headsets) - Desktop Brands - [Alienware](https://www.tomshardware.com/uk/tag/alienware) - [Corsair](https://www.tomshardware.com/uk/tag/corsair) - [GeForce](https://www.tomshardware.com/uk/tag/geforce) - [Intel Arc](https://www.tomshardware.com/uk/tag/intel-arc) - [Gigabyte](https://www.tomshardware.com/uk/tag/gigabyte) - [Acer](https://www.tomshardware.com/uk/tag/acer) - [Software & AI](https://www.tomshardware.com/uk/software) - [View Software & AI](https://www.tomshardware.com/uk/software) - [Artificial Intelligence](https://www.tomshardware.com/uk/tech-industry/artificial-intelligence) - [View Artificial Intelligence](https://www.tomshardware.com/uk/tech-industry/artificial-intelligence) - [Machine Learning](https://www.tomshardware.com/uk/tag/machine-learning) - [R\&D](https://www.tomshardware.com/uk/tag/randd) - [Intel Gaudi](https://www.tomshardware.com/uk/tag/gaudi) - [Cerebras](https://www.tomshardware.com/uk/tag/cerebras) - [xAI](https://www.tomshardware.com/uk/tag/xai) - [LLMs](https://www.tomshardware.com/uk/tag/llm) - [View LLMs](https://www.tomshardware.com/uk/tag/llm) - [OpenAI](https://www.tomshardware.com/uk/tag/openai) - [Anthropic](https://www.tomshardware.com/uk/tag/anthropic) - [DeepSeek](https://www.tomshardware.com/uk/tag/deepseek) - [Gemini](https://www.tomshardware.com/uk/tag/gemini) - [Grok](https://www.tomshardware.com/uk/tag/grok) - [Operating Systems](https://www.tomshardware.com/uk/software/operating-systems) - [View Operating Systems](https://www.tomshardware.com/uk/software/operating-systems) - [Windows](https://www.tomshardware.com/uk/software/operating-systems/windows) - [MacOS](https://www.tomshardware.com/uk/software/operating-systems/macos) - [iOS](https://www.tomshardware.com/uk/software/operating-systems/ios) - [ChromeOS](https://www.tomshardware.com/uk/software/operating-systems/chromeos) - [Linux](https://www.tomshardware.com/uk/software/operating-systems/linux) - [Software](https://www.tomshardware.com/uk/software) - [View Software](https://www.tomshardware.com/uk/software) - [Programming](https://www.tomshardware.com/uk/software/programming) - [Applications](https://www.tomshardware.com/uk/software/applications) - [Microsoft Office](https://www.tomshardware.com/uk/software/applications/microsoft-office) - [Web Browsers](https://www.tomshardware.com/uk/software/browsers) - [Coupons](https://www.tomshardware.com/coupons) - [View Coupons](https://www.tomshardware.com/coupons) - [Laptop and PC Coupons](https://www.tomshardware.com/coupons/category/laptops-and-computers) - [View Laptop and PC Coupons](https://www.tomshardware.com/coupons/category/laptops-and-computers) - [Dell Coupon Codes](https://www.tomshardware.com/coupons/dell.com) - [Asus Coupon Codes](https://www.tomshardware.com/coupons/ASUS) - [Logitech Promo Codes](https://www.tomshardware.com/coupons/logitech.com) - [Samsung Promo codes](https://www.tomshardware.com/coupons/samsung.com) - [Hardware Coupons](https://www.tomshardware.com/coupons/category/ssds-motherboards-and-hardware) - [View Hardware Coupons](https://www.tomshardware.com/coupons/category/ssds-motherboards-and-hardware) - [Newegg Promo Codes](https://www.tomshardware.com/coupons/newegg.com) - [Corsair Discount Codes](https://www.tomshardware.com/coupons/corsair.com) - [Razer Promo Codes](https://www.tomshardware.com/coupons/razer.com) - [Anycubic Discount codes](https://www.tomshardware.com/coupons/anycubic) - [Software Coupons](https://www.tomshardware.com/coupons/category/online-software) - [View Software Coupons](https://www.tomshardware.com/coupons/category/online-software) - [Bitdefender Coupons](https://www.tomshardware.com/coupons/bitdefender.com) - [Simplisafe Coupons](https://www.tomshardware.com/coupons/simplisafe.com) - [MacPaw Coupons](https://www.tomshardware.com/coupons/macpaw.com) - [Squarespace Coupon Codes](https://www.tomshardware.com/coupons/squarespace) - [Gaming Coupons](https://www.tomshardware.com/coupons/category/video-games) - [View Gaming Coupons](https://www.tomshardware.com/coupons/category/video-games) - [Kinguin Discount Codes](https://www.tomshardware.com/coupons/kinguin.net) - [Loaded Discount Codes](https://www.tomshardware.com/coupons/cdkeys.com) - [Logitech G Promo Codes](https://www.tomshardware.com/coupons/logitechg.com) - [SteelSeries Coupons](https://www.tomshardware.com/coupons/steelseries) [Premium](https://www.tomshardware.com/uk/premium) [Forums](https://forums.tomshardware.com/) [Tom's Hardware Subscription](https://www.tomshardware.com/uk/subscription?utm_source=brandsite&utm_medium=hawk&utm_campaign=BAU2026) [![Tom's Hardware Subscription](https://images.fie.futurecdn.net/lmw5ywbsp62ztm9d-17743654800265-250-80.png.webp)](https://www.tomshardware.com/uk/subscription?utm_source=brandsite&utm_medium=hawk&utm_campaign=BAU2026) Why subscribe? - Get deeper insights with deeper News Analysis posts - Read exclusive subscriber-only features and interviews - Unlock access to Bench, our custom benchmark test visualizer, and compare products [From£5 /mth](https://www.tomshardware.com/uk/subscription?utm_source=brandsite&utm_medium=hawk&utm_campaign=BAU2026) [Subscribe now](https://www.tomshardware.com/uk/subscription?utm_source=brandsite&utm_medium=hawk&utm_campaign=BAU2026) Don't miss these [![a floppy drive attached to a Tesla via the glove box USB port](https://cdn.mos.cms.futurecdn.net/U8TWe6Qq8Y9SMuJ7tn7v9H.png) Storage Engineer installs 3.5-inch floppy drive in a Tesla](https://www.tomshardware.com/pc-components/storage/engineer-installs-3-5-inch-floppy-drive-in-a-tesla-modern-ev-recognizes-and-runs-ancient-storage-device-even-plays-an-mp3-file-from-diskette "Engineer installs 3.5-inch floppy drive in a Tesla ") [![French politician on a laptop](https://cdn.mos.cms.futurecdn.net/8rh5kLKHAvNzqnaeftVA6a.jpg) Windows French government says it's ditching Windows for Linux](https://www.tomshardware.com/software/windows/french-government-say-its-ditching-windows-for-linux-country-accelerates-plans-to-ditch-us-based-software-in-digital-sovereignty-push "French government says it's ditching Windows for Linux") [![Intel 486 CPU](https://cdn.mos.cms.futurecdn.net/8QGkMbkDm8MZbB6wmBrczZ.jpg) Linux Linux devs start removing support for 37-year-old Intel 486 CPU](https://www.tomshardware.com/software/linux/linux-devs-start-removing-support-for-37-year-old-intel-486-cpu-head-honcho-linus-torvalds-says-zero-real-reason-to-continue-support "Linux devs start removing support for 37-year-old Intel 486 CPU") [![A collection of the best SSDs we\&\#039;ve tested, in a small red toolbox, on a wooden table](https://cdn.mos.cms.futurecdn.net/nbtHJx4DAUSRPqR7hjWMg5.jpg) External SSDs Best External SSDs 2026](https://www.tomshardware.com/reviews/best-external-hard-drive-ssd,5987.html "Best External SSDs 2026") [![Apollo 11](https://cdn.mos.cms.futurecdn.net/pebbe9ud4C68YH4HDFyfvm.jpg) Software Original Apollo 11 code open-sourced by NASA](https://www.tomshardware.com/software/original-apollo-11-code-open-sourced-by-nasa-original-command-module-and-lunar-module-code-repos-are-now-public-domain-resources "Original Apollo 11 code open-sourced by NASA") [![Sharge Disk Pro 2TB](https://cdn.mos.cms.futurecdn.net/Wa5nqredGwDPFXqpfQizpP.jpg) External SSDs Sharge Disk Pro 2TB review: Great sustained writes, active cooling, and a built-in hub](https://www.tomshardware.com/pc-components/external-ssds/sharge-disk-pro-2tb-review "Sharge Disk Pro 2TB review: Great sustained writes, active cooling, and a built-in hub") [![Best Hard Drives](https://cdn.mos.cms.futurecdn.net/y9LgDuCwqtA6FcACp9WuxX.jpg) HDDs Best Hard Drives 2026: The best HDDs for desktop PCs, NAS, and more, based on our extensive benchmarking](https://www.tomshardware.com/best-picks/best-hard-drives "Best Hard Drives 2026: The best HDDs for desktop PCs, NAS, and more, based on our extensive benchmarking") [![Official Ubuntu 26.04 LTS (Resolute Raccoon) wallpaper](https://cdn.mos.cms.futurecdn.net/SnrWme89odSfJjPBZ6MRTH.jpg) Operating Systems Ubuntu Linux raises minimum system requirements by 50%](https://www.tomshardware.com/software/operating-systems/ubunto-linux-raises-minimum-system-requirements-to-6gb-of-ram-it-was-previously-raised-from-1gb-to-4gb-in-2018 "Ubuntu Linux raises minimum system requirements by 50%") [![metalwork filing](https://cdn.mos.cms.futurecdn.net/GbGWEhHw9zYBQDH2sijHvQ.jpg) Macbooks MacBook user explains why he files the sharp metal edges off his Apple laptops](https://www.tomshardware.com/laptops/macbooks/macbook-user-explains-why-he-files-the-sharp-metal-edges-off-his-apple-laptops-unibody-design-facilitates-a-surprisingly-deep-roundover "MacBook user explains why he files the sharp metal edges off his Apple laptops") [![Windows 11](https://cdn.mos.cms.futurecdn.net/A3bqjPsbEd6W9WtTAebSpJ.jpg) Windows Microsoft simplifies Windows Insider program — fewer channels, and switching without wiping your device](https://www.tomshardware.com/software/windows/microsoft-simplifies-windows-insider-program-fewer-channels-and-switching-without-wiping-your-device "Microsoft simplifies Windows Insider program — fewer channels, and switching without wiping your device") [![Linus Torvalds in a bow tie](https://cdn.mos.cms.futurecdn.net/ids4kQSJRnSAyRq48R9Br7.jpg) Linux After 34 years, the Linux kernel community finally has a contingency plan to replace Linus Torvalds](https://www.tomshardware.com/software/linux/linux-kernel-community-draws-up-contingency-plan-to-replace-linus-torvalds-should-the-need-arise-only-34-years-in-the-making "After 34 years, the Linux kernel community finally has a contingency plan to replace Linus Torvalds") [![Android Smartphone as a Webcam](https://cdn.mos.cms.futurecdn.net/WCEG3fFHhXPHLjeYW9kjyF.jpg) Android How to setup an Android smartphone as a webcam — Camo Studio unlocks new uses for old smartphones in Windows 10 or 11 and OBS software](https://www.tomshardware.com/phones/android/how-to-setup-an-android-smartphone-as-a-webcam-camo-studio-unlocks-new-uses-for-old-smartphones-in-windows-10-or-11-and-obs-software "How to setup an Android smartphone as a webcam — Camo Studio unlocks new uses for old smartphones in Windows 10 or 11 and OBS software") [![Modded PS5 running Linux \&amp; playing GTA V ](https://cdn.mos.cms.futurecdn.net/tLYGp6pdZakh3t8PGRxQRh.png) PlayStation Linux hacked onto a PS5 to turn Sony's console into a Steam Machine](https://www.tomshardware.com/video-games/playstation/linux-hacked-onto-a-ps5-to-turn-sonys-console-into-a-steam-machine-gta-v-enhanced-edition-runs-at-60-fps-on-1440pwith-ray-tracing "Linux hacked onto a PS5 to turn Sony's console into a Steam Machine") [![Desperate developer](https://cdn.mos.cms.futurecdn.net/96AaEg8c3qSTnPXmN3KuQM.jpg) Artificial Intelligence Claude Code deletes developers' production setup, including its database and snapshots](https://www.tomshardware.com/tech-industry/artificial-intelligence/claude-code-deletes-developers-production-setup-including-its-database-and-snapshots-2-5-years-of-records-were-nuked-in-an-instant "Claude Code deletes developers' production setup, including its database and snapshots") [![The NexPhone connected to a monitor and peripherals running Windows 11](https://cdn.mos.cms.futurecdn.net/Qb7N4TLT4iscAbBApNptX4.jpg) Phones Windows Phone makes a spiritual comeback thanks to NexPhone, which can triple-boot Windows, Android, and Linux](https://www.tomshardware.com/phones/windows-phone-makes-a-spiritual-comeback-thanks-to-nexphone-which-can-triple-boot-windows-android-and-linux-three-in-one-device-is-powered-by-qualcomm-chipset-and-even-has-external-monitor-support "Windows Phone makes a spiritual comeback thanks to NexPhone, which can triple-boot Windows, Android, and Linux") Trending - [🔥TH Premium Deal](https://www.tomshardware.com/tech-industry/toms-hardware-premium-3-month) - [Big Spring Sale](https://www.tomshardware.com/pc-components/the-best-amazon-big-spring-sale-tech-deals-2026-featuring-the-best-prices-on-the-latest-gaming-pcs-gpus-laptops-monitors-peripherals-and-more) - [Intel Xeon 600](https://www.tomshardware.com/pc-components/cpus/intel-returns-to-boxed-workstation-cpus-with-xeon-600-granite-rapids-ws-delivers-up-to-86-cores-4tb-of-memory-and-128-pcie-5-lanes) - [RAM Combo Deals](https://www.tomshardware.com/desktops/gaming-pcs/best-ram-combo-deals-2026-make-pc-builds-and-upgrades-more-affordable-with-the-best-ram-bundle-deals-available) - [DLSS 5](https://www.tomshardware.com/tech-industry/artificial-intelligence/nvidia-debuts-dlss-5-for-increased-visual-fidelity-in-games-ai-infused-tech-transforms-pixels-with-photorealistic-lighting-and-materials) - [Bartlett Lake](https://www.tomshardware.com/pc-components/cpus/intel-keeps-socket-lga-1700-alive-with-new-p-core-only-cpus-bartlett-lake-is-official-but-targets-embedded-applications-with-up-to-12-cores) - [RAM Shortage](https://www.tomshardware.com/uk/tag/ram-shortage) 1. [Software](https://www.tomshardware.com/uk/software) 2. [Operating Systems](https://www.tomshardware.com/uk/software/operating-systems) 3. [Linux](https://www.tomshardware.com/uk/software/operating-systems/linux) # How To Copy Files and Directories in the Linux terminal [How-To](https://www.tomshardware.com/uk/how-to) By [Jo Hinchliffe](https://www.tomshardware.com/uk/author/jo-hinchliffe) Contributions from [Les Pounder](https://www.tomshardware.com/uk/author/les-pounder) published 9 June 2025 Copy files and directories via the Linux command line When you purchase through links on our site, we may earn an affiliate commission. [Here’s how it works](https://www.tomshardware.com/reviews/about-us,4260.html#section-affiliate-advertising-disclosure). ![Copies of cyborg penguins](https://cdn.mos.cms.futurecdn.net/cMyjzJw7fiG9sLq8vqiC78.jpg) (Image credit: Pexels / OpenClipArt) - Copy link - [Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal) - [X](https://twitter.com/intent/tweet?text=How+To+Copy+Files+and+Directories+in+the+Linux+terminal&url=https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal) - [Whatsapp](whatsapp://send?text=How+To+Copy+Files+and+Directories+in+the+Linux+terminal+https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal?fwa) - [Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal&title=How+To+Copy+Files+and+Directories+in+the+Linux+terminal) - [Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal&media=https%3A%2F%2Fcdn.mos.cms.futurecdn.net%2FcMyjzJw7fiG9sLq8vqiC78.jpg) - [Flipboard](https://share.flipboard.com/bookmarklet/popout?title=How+To+Copy+Files+and+Directories+in+the+Linux+terminal&url=https%3A%2F%2Fwww.tomshardware.com%2Fsoftware%2Flinux%2Fhow-to-copy-files-and-directories-in-the-linux-terminal) - [Email](mailto:?subject=I%20found%20this%20webpage&body=Hi,%20I%20found%20this%20webpage%20and%20thought%20you%20might%20like%20it%20https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal) Share this article [0](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal#xenforo-comments-3880964) Join the conversation [Follow us](https://google.com/preferences/source?q=tomshardware.com) Add us as a preferred source on Google Newsletter Stay On the Cutting Edge: Get the Tom's Hardware Newsletter Get Tom's Hardware's best news and in-depth reviews, straight to your inbox. *** By signing up, you agree to our [Terms of services](https://futureplc.com/terms-conditions/) and acknowledge that you have read our [Privacy Notice](https://futureplc.com/privacy-policy). You also agree to receive marketing emails from us that may include promotions from our trusted partners and sponsors, which you can unsubscribe from at any time. You are now subscribed Your newsletter sign-up was successful *** An account already exists for this email address, please log in. Subscribe to our newsletter Copying files and directories in the Linux terminal is really efficient and straightforward once you know how to do it. It’s useful when we need to manage our files and directories without the need for a GUI, for example in a BASH script. We can do this whether we are at our desk or if we are accessing a machine remotely via SSH. In this how-to we’ll look at the *cp* command which copies files and directories. We’ll look at some arguments that we can add to get the most out of this command. While you become accustomed to these commands it’s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions. Article continues below You may like - [![An ASCII animated real-time weather show forms the terminal backdrop](https://cdn.mos.cms.futurecdn.net/Ge2X37u3hh2CTmqxjkDU3N.jpg) Weathr app turns the Linux terminal into a live weather display](https://www.tomshardware.com/software/linux/weathr-turns-the-linux-terminal-into-a-live-weather-app-background-ascii-animated-real-time-weather-show-is-powered-by-open-meteo) - [![CDE Time Capsule project screenshot showing 1990s-style Linux](https://cdn.mos.cms.futurecdn.net/v5xGHmoyTqEyVrhNsdZWJb.jpg) Developer's 1994 Linux desktop recreation runs in your browser as a modern web app](https://www.tomshardware.com/software/linux/nostalgic-developer-recreates-the-1994-linux-desktop-as-a-modern-web-app-for-your-browser-open-source-project-brings-old-school-cde-interface-back-from-the-dead-and-features-classic-90s-web-browser-text-editor-and-more) - [![Thermalright Warframe 360 cooler screen](https://cdn.mos.cms.futurecdn.net/Kd3hE2Yw5qQSH9Pu7sbyYc.jpg) Thermalright's LCD software for Windows ported to Linux](https://www.tomshardware.com/pc-components/liquid-cooling/enthusiast-ports-thermalrights-lcd-software-for-windows-to-linux-fully-fledged-port-supports-a-ton-of-models-and-enables-rgb-and-lcd-customization) All the commands in this how-to will work on most Linux machines. We’ve used an Ubuntu LTS install but you could run this how-to on a[Raspberry Pi](https://www.tomshardware.com/news/raspberry-pi). All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing *ctrl, alt* and *t.* ## How to Copy a Single File in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/JoHumsQhSTbnqJwpYrA4Dg.png) (Image credit: Tom's Hardware) Let’s start really simply by copying a single file. The command syntax is structured as follows. ``` cp <location and name of item to copy> <location and name for copied item> ``` 1\. **Create a new file called test1.txt.** ``` touch test1.txt ``` 2\. **List the contents of the directory to check if the file has been created.** You should now see the file test1.txt. Stay On the Cutting Edge: Get the Tom's Hardware Newsletter Get Tom's Hardware's best news and in-depth reviews, straight to your inbox. By signing up, you agree to our [Terms of services](https://futureplc.com/terms-conditions/) and acknowledge that you have read our [Privacy Notice](https://futureplc.com/privacy-policy). You also agree to receive marketing emails from us that may include promotions from our trusted partners and sponsors, which you can unsubscribe from at any time. ``` ls ``` 3\. **Copy the** ***test1.txt*** **file and rename it to test2.txt.** This copies the item into the same directory as the original but into a new file. ``` cp test1.txt test2.txt ``` 4\. **List the contents of the directory to check the file has been copied and renamed.** You should see that the original file test1.txt is listed and the copied file test2.txt is listed. ``` ls ``` ## How to Copy a Directory in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/x84Ai4t2mx7buH62eAcCwf.png) (Image credit: Tom's Hardware) Let’s run through a similar example to show that *cp* can be used to copy a directory by using the *\-r* argument. Though we have used an empty directory as an example, any directory contents would also be copied to the new directory using this argument. What to read next - [![Free Alternatives to Photoshop](https://cdn.mos.cms.futurecdn.net/NBxoPBibTiKWqw8gpD7kXG.jpg) Developer patches Wine to make Photoshop 2021 & 2025 run on Linux, fixes Creative Cloud installers](https://www.tomshardware.com/software/linux/developer-patches-wine-to-make-photoshop-2021-and-2025-run-on-linux-adobe-creative-cloud-installers-finally-work-thanks-to-html-javascript-and-xml-fixes) - [![Modded PS5 running Linux \&amp; playing GTA V ](https://cdn.mos.cms.futurecdn.net/tLYGp6pdZakh3t8PGRxQRh.png) Linux hacked onto a PS5 to turn Sony's console into a Steam Machine](https://www.tomshardware.com/video-games/playstation/linux-hacked-onto-a-ps5-to-turn-sonys-console-into-a-steam-machine-gta-v-enhanced-edition-runs-at-60-fps-on-1440pwith-ray-tracing) - [![The moon](https://cdn.mos.cms.futurecdn.net/Bwujki4D37irHWE8XbcRE7.jpg) Dev creates astrology-powered CPU scheduler for Linux, makes decisions based on planetary positions and zodiac signs](https://www.tomshardware.com/software/linux/dev-creates-astrology-powered-cpu-scheduler-for-linux-makes-decisions-based-on-planetary-positions-and-zodiac-signs-sched-ext-framework-informed-by-lunar-phases-cosmic-weather-reports-and-dynamic-time-slicing) 1\. **Create an empty directory in your home directory.** ``` mkdir test_directory ``` 2\. **Copy and rename the new directory.** ``` cp -r test_directory test_directory_2 ``` 3\. **List the directory contents to check the copied directory is created.** You should see the directories test\_directory and test\_directory\_2 listed. ``` ls ``` ## How to Copy Files to a Different Location in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/fKiHeto3P2NbDsYBL6cu4g.png) (Image credit: Tom's Hardware) For the next example let’s look at copying a file to a different location. 1\. **Create an empty directory in your home directory.** ``` mkdir test_directory ``` 2\. **Create a test file in your home directory.** ``` touch test1.txt ``` 3\. **Copy the test file from the home directory into the test directory.** This copies test1.txt from the home directory into test\_directory. ``` $ cp test1.txt test_directory ``` 4\. **Check the file has been copied correctly by changing directory to test\_directory and listing the contents.** ``` cd test_directory ls ``` ## How to Copy Files to and From Directories While Renaming Them ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/Bi3JEk4GzDLs38s4YuiZnf.png) (Image credit: Tom's Hardware) If you know the location of a file and the target location you want to copy the file to, you don’t need to move into the directories directly and you can run the *cp* command from the home directory. Here’s an example of how it could be done. 1\. **Create 2 empty directories.** From the home directory run the following command to create two new directories. ``` mkdir folder1 folder2 ``` 2\. **Move inside** ***folder1*** **and make a test file called test1.txt.** ``` cd folder1 touch test1.txt ``` 3\. **Return to the** ***home*** **directory.** ``` cd ``` 4\. **Copy and rename the test file from the home** **directory.** We can supply the *cp* command with the name and location of the target file to copy and where to copy the file, renaming it to test2.txt along the way. ``` cp folder1/test1.txt folder2/test2.txt ``` 5\. **Check that the file has been copied correctly** by changing directory to folder2 and listing the contents. Use *cd* to change directory and *ls* to check the file copied correctly. You should see *test2.txt* listed inside *folder2*. ``` cd folder2 ls ``` ## How to Copy a File to a Parent Directory ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/cp3dkZSR9WrExaas94hjJg.png) (Image credit: Tom's Hardware) As you move through directories you may need to occasionally copy a file to the parent directory of a current location. This can be achieved without having to type long directory locations into a command by using *..* to target the parent directory. Here’s how. 1\. **Create a test directory using** ***mkdir*****.** ``` mkdir test_directory ``` 2\. **Move into test\_directory*****.*** ``` cd test_directory ``` 3\. **Create a test file inside** **test\_directory.** ``` touch test1.txt ``` 4\. **Copy** **test1.txt to the parent directory.** Here we simply add .. to the *cp* command to create a copy of test1.txt into the parent directory of the current location. ``` cp test1.txt .. ``` 5\. **Move to the parent directory and check if the file has been copied.** You should see that test1.txt is now listed at this location. ``` cd ls ``` As you can see the cp command is very simple to use but is very capable and, with a little practice, it’s often much quicker to be able to surgically copy and rename files using cp than using graphical interface tools. TOPICS [Ubuntu](https://www.tomshardware.com/uk/tag/ubuntu) [See all comments (0)](https://www.tomshardware.com/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal#xenforo-comments-3880964) ![Jo Hinchliffe](https://cdn.mos.cms.futurecdn.net/aPF4Yyru8FqfhkQARU2rdV.jpg) [Jo Hinchliffe](https://www.tomshardware.com/uk/author/jo-hinchliffe) Jo Hinchliffe is a UK-based freelance writer for Tom's Hardware US. His writing is focused on tutorials for the Linux command line. With contributions from - [Les Pounder](https://www.tomshardware.com/uk/author/les-pounder) Read more [![An ASCII animated real-time weather show forms the terminal backdrop](https://cdn.mos.cms.futurecdn.net/Ge2X37u3hh2CTmqxjkDU3N.jpg) Linux Weathr app turns the Linux terminal into a live weather display](https://www.tomshardware.com/software/linux/weathr-turns-the-linux-terminal-into-a-live-weather-app-background-ascii-animated-real-time-weather-show-is-powered-by-open-meteo "Weathr app turns the Linux terminal into a live weather display ") [![CDE Time Capsule project screenshot showing 1990s-style Linux](https://cdn.mos.cms.futurecdn.net/v5xGHmoyTqEyVrhNsdZWJb.jpg) Linux Developer's 1994 Linux desktop recreation runs in your browser as a modern web app](https://www.tomshardware.com/software/linux/nostalgic-developer-recreates-the-1994-linux-desktop-as-a-modern-web-app-for-your-browser-open-source-project-brings-old-school-cde-interface-back-from-the-dead-and-features-classic-90s-web-browser-text-editor-and-more "Developer's 1994 Linux desktop recreation runs in your browser as a modern web app ") [![Thermalright Warframe 360 cooler screen](https://cdn.mos.cms.futurecdn.net/Kd3hE2Yw5qQSH9Pu7sbyYc.jpg) Liquid Cooling Thermalright's LCD software for Windows ported to Linux](https://www.tomshardware.com/pc-components/liquid-cooling/enthusiast-ports-thermalrights-lcd-software-for-windows-to-linux-fully-fledged-port-supports-a-ton-of-models-and-enables-rgb-and-lcd-customization "Thermalright's LCD software for Windows ported to Linux") [![Free Alternatives to Photoshop](https://cdn.mos.cms.futurecdn.net/NBxoPBibTiKWqw8gpD7kXG.jpg) Linux Developer patches Wine to make Photoshop 2021 & 2025 run on Linux, fixes Creative Cloud installers](https://www.tomshardware.com/software/linux/developer-patches-wine-to-make-photoshop-2021-and-2025-run-on-linux-adobe-creative-cloud-installers-finally-work-thanks-to-html-javascript-and-xml-fixes "Developer patches Wine to make Photoshop 2021 & 2025 run on Linux, fixes Creative Cloud installers ") [![Modded PS5 running Linux \&amp; playing GTA V ](https://cdn.mos.cms.futurecdn.net/tLYGp6pdZakh3t8PGRxQRh.png) PlayStation Linux hacked onto a PS5 to turn Sony's console into a Steam Machine](https://www.tomshardware.com/video-games/playstation/linux-hacked-onto-a-ps5-to-turn-sonys-console-into-a-steam-machine-gta-v-enhanced-edition-runs-at-60-fps-on-1440pwith-ray-tracing "Linux hacked onto a PS5 to turn Sony's console into a Steam Machine") [![The moon](https://cdn.mos.cms.futurecdn.net/Bwujki4D37irHWE8XbcRE7.jpg) Linux Dev creates astrology-powered CPU scheduler for Linux, makes decisions based on planetary positions and zodiac signs](https://www.tomshardware.com/software/linux/dev-creates-astrology-powered-cpu-scheduler-for-linux-makes-decisions-based-on-planetary-positions-and-zodiac-signs-sched-ext-framework-informed-by-lunar-phases-cosmic-weather-reports-and-dynamic-time-slicing "Dev creates astrology-powered CPU scheduler for Linux, makes decisions based on planetary positions and zodiac signs") Latest in Linux [![Intel 486 CPU](https://cdn.mos.cms.futurecdn.net/8QGkMbkDm8MZbB6wmBrczZ.jpg) Linux Linux devs start removing support for 37-year-old Intel 486 CPU](https://www.tomshardware.com/software/linux/linux-devs-start-removing-support-for-37-year-old-intel-486-cpu-head-honcho-linus-torvalds-says-zero-real-reason-to-continue-support "Linux devs start removing support for 37-year-old Intel 486 CPU") [![GeForce RTX 5090 Founders Edition](https://cdn.mos.cms.futurecdn.net/RH2UfQ4PEty8QdC39Tkoom.jpg) Linux Ubuntu 26.04 boosts performance by up to 12% on an RTX 5090 thanks to optimizations with Gnome 50](https://www.tomshardware.com/software/linux/rtx-5090-gets-12-percent-gaming-boost-in-ubuntu-26-04-thanks-to-optimizations-with-gnome-50-latest-popular-distro-update-brings-significant-performance-uplift-for-nvidias-top-gpu "Ubuntu 26.04 boosts performance by up to 12% on an RTX 5090 thanks to optimizations with Gnome 50") [![CDE Time Capsule project screenshot showing 1990s-style Linux](https://cdn.mos.cms.futurecdn.net/v5xGHmoyTqEyVrhNsdZWJb.jpg) Linux Developer's 1994 Linux desktop recreation runs in your browser as a modern web app](https://www.tomshardware.com/software/linux/nostalgic-developer-recreates-the-1994-linux-desktop-as-a-modern-web-app-for-your-browser-open-source-project-brings-old-school-cde-interface-back-from-the-dead-and-features-classic-90s-web-browser-text-editor-and-more "Developer's 1994 Linux desktop recreation runs in your browser as a modern web app ") [![Linus Torvalds](https://cdn.mos.cms.futurecdn.net/GS7gXxfBQBEo6KvaLYY3Jk.jpg) Linux Linux 7.0 launches with enablement for Intel Nova Lake, AMD Zen 6](https://www.tomshardware.com/software/linux/linux-7-0-launches-with-enablement-for-intel-nova-lake-amd-zen-6-major-kernel-update-expected-in-ubuntu-26-04-lts-and-fedora-44-first "Linux 7.0 launches with enablement for Intel Nova Lake, AMD Zen 6") [![Intel MMX](https://cdn.mos.cms.futurecdn.net/sDn2qWtXneZJ5EAcMGwpYQ.jpg) Linux Linux kernel 7.0 finally abandons the 28-year-old Intel 440BX chipset](https://www.tomshardware.com/software/linux/linux-kernel-7-0-finally-abandons-intel-440bx-edac-driver-removal-marks-another-goodbye-to-the-legendary-motherboard-chipset "Linux kernel 7.0 finally abandons the 28-year-old Intel 440BX chipset") [![An ASCII animated real-time weather show forms the terminal backdrop](https://cdn.mos.cms.futurecdn.net/Ge2X37u3hh2CTmqxjkDU3N.jpg) Linux Weathr app turns the Linux terminal into a live weather display](https://www.tomshardware.com/software/linux/weathr-turns-the-linux-terminal-into-a-live-weather-app-background-ascii-animated-real-time-weather-show-is-powered-by-open-meteo "Weathr app turns the Linux terminal into a live weather display ") Latest in How To [![Flipper Zero](https://cdn.mos.cms.futurecdn.net/e6zsd7htE55ByzCT277B7Z.png) Cybersecurity Flipper Zero pen-testing tool gets an AI-powered companion app](https://www.tomshardware.com/tech-industry/cyber-security/flipper-zero-pen-testing-tool-gets-an-ai-powered-companion-app-natural-language-interface-allows-for-faster-easier-hacking "Flipper Zero pen-testing tool gets an AI-powered companion app") [![The Ryzen 7 9850X3D CPU leaning against a graphics card.](https://cdn.mos.cms.futurecdn.net/7k8sTnJ6KjRrHv4pdqLRba.jpg) CPUs How to use Precision Boost Overdrive and Curve Optimizer to improve Ryzen CPU performance](https://www.tomshardware.com/pc-components/cpus/how-to-use-precision-boost-overdrive-and-curve-optimizer-to-improve-ryzen-cpu-performance "How to use Precision Boost Overdrive and Curve Optimizer to improve Ryzen CPU performance") [![Android Smartphone as a Webcam](https://cdn.mos.cms.futurecdn.net/WCEG3fFHhXPHLjeYW9kjyF.jpg) Android How to setup an Android smartphone as a webcam — Camo Studio unlocks new uses for old smartphones in Windows 10 or 11 and OBS software](https://www.tomshardware.com/phones/android/how-to-setup-an-android-smartphone-as-a-webcam-camo-studio-unlocks-new-uses-for-old-smartphones-in-windows-10-or-11-and-obs-software "How to setup an Android smartphone as a webcam — Camo Studio unlocks new uses for old smartphones in Windows 10 or 11 and OBS software") [![Plex Server](https://cdn.mos.cms.futurecdn.net/ymSAnpMHVL9HymTU6S9LNh.jpg) Streaming How to use Plex and a spare computer to build a streaming movie service](https://www.tomshardware.com/service-providers/streaming/how-to-use-plex-and-a-spare-computer-to-build-a-streaming-movie-service "How to use Plex and a spare computer to build a streaming movie service") [![Xbox Controller](https://cdn.mos.cms.futurecdn.net/T3s9MQiDjNX2G3NeEQEhvi.jpg) Xbox How to connect an Xbox controller to your Windows PC — wired and wireless gaming made easy](https://www.tomshardware.com/video-games/xbox/how-to-connect-an-xbox-controller-to-your-windows-pc-wired-and-wireless-gaming-made-easy "How to connect an Xbox controller to your Windows PC — wired and wireless gaming made easy") [![AMD Ryzen 7 9800X3D](https://cdn.mos.cms.futurecdn.net/xTDkvKn3YbMsk8uzfxKSZh.jpg) CPUs How to choose a CPU – A guide to picking the right processor for your PC](https://www.tomshardware.com/pc-components/cpus/cpu-buying-guide "How to choose a CPU – A guide to picking the right processor for your PC") No comments yet [Comment from the forums](https://forums.tomshardware.com/threads/how-to-copy-files-and-directories-in-the-linux-terminal.3880964/) Tom's Hardware is part of Future plc, an international media group and leading digital publisher. [Visit our corporate site](https://futureplc.com/). [![Add as a preferred source on Google](https://cdn.mos.cms.futurecdn.net/flexiimages/mednnv697g1760357120.png) Add as a preferred source on Google](https://google.com/preferences/source?q=tomshardware.com) - [Terms and conditions](https://futureplc.com/terms-conditions/) - [Contact Future's experts](https://futureplc.com/contact/) - [Privacy policy](https://futureplc.com/privacy-policy/) - [Cookies policy](https://futureplc.com/cookies-policy/) - [Accessibility Statement](https://futureplc.com/accessibility-statement/) - [Advertise with us](https://go.future-advertising.com/Toms-Hardware-Media-Kit.html) - [About us](https://www.tomshardware.com/uk/reviews/about-us,4260.html#section-contact-info) - [Coupons](https://www.tomshardware.com/coupons) - [Careers](https://futureplc.com/careers/) - [Do not sell or share my personal information](https://www.tomshardware.com/uk/privacy-portal) © Future Publishing Limited Quay House, The Ambury, Bath BA1 1UA. All rights reserved. England and Wales company registration number 2008885. ![]() ×
Readable Markdown
Copying files and directories in the Linux terminal is really efficient and straightforward once you know how to do it. It’s useful when we need to manage our files and directories without the need for a GUI, for example in a BASH script. We can do this whether we are at our desk or if we are accessing a machine remotely via SSH. In this how-to we’ll look at the *cp* command which copies files and directories. We’ll look at some arguments that we can add to get the most out of this command. While you become accustomed to these commands it’s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions. Article continues below All the commands in this how-to will work on most Linux machines. We’ve used an Ubuntu LTS install but you could run this how-to on a[Raspberry Pi](https://www.tomshardware.com/news/raspberry-pi). All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing *ctrl, alt* and *t.* ## How to Copy a Single File in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/JoHumsQhSTbnqJwpYrA4Dg.png) (Image credit: Tom's Hardware) Let’s start really simply by copying a single file. The command syntax is structured as follows. ``` cp <location and name of item to copy> <location and name for copied item> ``` 1\. **Create a new file called test1.txt.** ``` touch test1.txt ``` 2\. **List the contents of the directory to check if the file has been created.** You should now see the file test1.txt. Get Tom's Hardware's best news and in-depth reviews, straight to your inbox. ``` ls ``` 3\. **Copy the** ***test1.txt*** **file and rename it to test2.txt.** This copies the item into the same directory as the original but into a new file. ``` cp test1.txt test2.txt ``` 4\. **List the contents of the directory to check the file has been copied and renamed.** You should see that the original file test1.txt is listed and the copied file test2.txt is listed. ``` ls ``` ## How to Copy a Directory in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/x84Ai4t2mx7buH62eAcCwf.png) (Image credit: Tom's Hardware) Let’s run through a similar example to show that *cp* can be used to copy a directory by using the *\-r* argument. Though we have used an empty directory as an example, any directory contents would also be copied to the new directory using this argument. 1\. **Create an empty directory in your home directory.** ``` mkdir test_directory ``` 2\. **Copy and rename the new directory.** ``` cp -r test_directory test_directory_2 ``` 3\. **List the directory contents to check the copied directory is created.** You should see the directories test\_directory and test\_directory\_2 listed. ``` ls ``` ## How to Copy Files to a Different Location in Linux ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/fKiHeto3P2NbDsYBL6cu4g.png) (Image credit: Tom's Hardware) For the next example let’s look at copying a file to a different location. 1\. **Create an empty directory in your home directory.** ``` mkdir test_directory ``` 2\. **Create a test file in your home directory.** ``` touch test1.txt ``` 3\. **Copy the test file from the home directory into the test directory.** This copies test1.txt from the home directory into test\_directory. ``` $ cp test1.txt test_directory ``` 4\. **Check the file has been copied correctly by changing directory to test\_directory and listing the contents.** ``` cd test_directory ls ``` ## How to Copy Files to and From Directories While Renaming Them ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/Bi3JEk4GzDLs38s4YuiZnf.png) (Image credit: Tom's Hardware) If you know the location of a file and the target location you want to copy the file to, you don’t need to move into the directories directly and you can run the *cp* command from the home directory. Here’s an example of how it could be done. 1\. **Create 2 empty directories.** From the home directory run the following command to create two new directories. ``` mkdir folder1 folder2 ``` 2\. **Move inside** ***folder1*** **and make a test file called test1.txt.** ``` cd folder1 touch test1.txt ``` 3\. **Return to the** ***home*** **directory.** ``` cd ``` 4\. **Copy and rename the test file from the home** **directory.** We can supply the *cp* command with the name and location of the target file to copy and where to copy the file, renaming it to test2.txt along the way. ``` cp folder1/test1.txt folder2/test2.txt ``` 5\. **Check that the file has been copied correctly** by changing directory to folder2 and listing the contents. Use *cd* to change directory and *ls* to check the file copied correctly. You should see *test2.txt* listed inside *folder2*. ``` cd folder2 ls ``` ## How to Copy a File to a Parent Directory ![Copy Files and Directories in Linux](https://cdn.mos.cms.futurecdn.net/cp3dkZSR9WrExaas94hjJg.png) (Image credit: Tom's Hardware) As you move through directories you may need to occasionally copy a file to the parent directory of a current location. This can be achieved without having to type long directory locations into a command by using *..* to target the parent directory. Here’s how. 1\. **Create a test directory using** ***mkdir*****.** ``` mkdir test_directory ``` 2\. **Move into test\_directory*****.*** ``` cd test_directory ``` 3\. **Create a test file inside** **test\_directory.** ``` touch test1.txt ``` 4\. **Copy** **test1.txt to the parent directory.** Here we simply add .. to the *cp* command to create a copy of test1.txt into the parent directory of the current location. ``` cp test1.txt .. ``` 5\. **Move to the parent directory and check if the file has been copied.** You should see that test1.txt is now listed at this location. ``` cd ls ``` As you can see the cp command is very simple to use but is very capable and, with a little practice, it’s often much quicker to be able to surgically copy and rename files using cp than using graphical interface tools.
Shard139 (laksa)
Root Hash14957725849104319939
Unparsed URLcom,tomshardware!www,/software/linux/how-to-copy-files-and-directories-in-the-linux-terminal s443