ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.5 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/ |
| Last Crawled | 2026-04-05 15:37:56 (13 days ago) |
| First Indexed | 2022-03-03 15:20:12 (4 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Copy Files and Directories in the Linux Terminal |
| Meta Description | New to Linux? Here's how to copy files and directories in a jiffy using the terminal! |
| Meta Canonical | null |
| Boilerpipe Text | Summary
The cp command can be used to copy files to a directory, copy multiple files to a single directory, and copy a file to a directory with a different name.
The rsync command, primarily used for transferring files between computers, can also be used to copy files and directories on the same PC and provides a detailed output of the file transfer.
Like any other operating system, you can
copy and paste
files and directories (folders) in a Linux distribution using the desktop interface. But you can save time by copying those files in the Terminal. Here's how.
What is the cp Command?
The cp command is the native copying tool built into Linux.
cp
stands for copy and is, you guessed it, used to copy files and directories in Linux. You can use
cp
to copy files to a directory, copy one directory to another, and copy multiple files to a single directory. Here are all examples that demonstrate the use of the
cp
command.
Copy File on Linux with the cp Command
Consider
cp
's syntax in its simplest form.
cp [file] [directory]
An example of its use would look like this.
cp Test1.txt copy_Test1_here/
The above command will copy the text file
Test1.txt
to the
copy_Test1_here/
directory.
If you have multiple files that you need to copy to one directory, simply list each file with a space in between.
cp Test1.txt Test2.txt Test3.txt Test4.txt copy_all_Tests_here/
You can also copy a file to a directory but save it using a different name. Here's the syntax for that.
cp [file] [directory]/[new filename]
This will copy the contents of the first tile and save it in the directory as the new filename. A real-life example of the same would look like this.
Given that there's a file
Test1.txt
that needs to be copied to the directory
copy_Test1_here
as
Test2.txt
:
cp Test1.txt copy_Test1_here/Test2.txt
Want to keep it in the same directory? You can copy a file and rename it like so:
cp Test1.txt Test2.txt
If you're unsure if the file was copied to the destination location, you can also use the option
-v
to
print the names of the files or directories
that were copied (like a computer program output).
For example, let's assume that there's a file
Test_Example
that needs to be copied to
dir_1
. To display the output of the copy operation, you'd use the
-v
option.
cp -v Test_Example.txt dir_1
The output would look like this:
'Test_Example.txt' -> 'dir_1/Test_Example.txt
Copy a Directory on Linux
Want to copy an entire directory? Let's assume that
dir_1
and
dir_2
are two directories in
/Desktop
. To copy
dir_1
to
dir_2
using the
cp
command, here's what you need to type.
cp -a dir_1 dir_2
Here option
-a
stands for "archive" and is used to let the computer know that we're dealing with directories. The command copies the directory
dir_1
to
dir_2
.
Most of the same rules apply to copying directoreis that apply to files. For example, you can copy a nested directory just like you might a nested file, and you can pass the -v argument to main cp display the copy operation that has been performed.
The -a flag is actually a combination of two other flags: -R and -d. The -R argument specifies that the copy operation is recursive, and that it must copy the contents of the object being copied as well as the object itself — this is essential for copying folders. The -d argument ensures that all file and folder attributes are preserved.
It is possible to copy folders with just
cp -r dir_1 dir_2
but you may lose specialized attributes if you do that.
Copy Files and Directories with rsync
The
rsync
command stands for "Remote Sync" and is primarily used to
transfer files and directories
between computers on the same network. However, it also allows copying files and directories on the same PC. Here are some examples.
Considering that we have two directories
dir_1
,
dir_2
, and a file
Test.txt
in
dir_1
. If we want to copy the file to
dir_2
, here's what the
rsync
command to do the same would look like.
rsync -v dir_1/Test.txt dir_2
Here
-v
is short for "verbose." It causes the details of the file transfer to appear, similar to the
-v
option in the
cp
command. This allows you to confirm the copy was successful. Here's what the output will be in our case:
sent 110 bytes received 35 bytes 290.00 bytes/sectotal size is 24 speedup is 0.17
You can also copy multiple files at once from one directory to another. Assume that you're in
/Desktop
in which there are two directories
dir_1
and
dir_2
.
dir_1
has four files
test1
,
test2
,
test3
, and
test4
and you want to copy them to
dir_2
. Here's how you can do that using
rsync
:
rsync -v dir_1/Test1.txt dir_1/Test2.txt dir_1/Test3.txt dir_1/Test4.txt dir_2
The above command will copy the files
test1
,
test2
,
test3
, and
test4
to the directory
dir_2
.
To copy one directory to another, we must use the
-a
option. Here's an example of how to copy directories using Rsync.
rsync -av dir_1 dir_2
If you're new to Linux and commands seem hard to follow, make sure to take your time and familiarize yourself with
basic Linux commands
first. You can also learn a lot about commands by using the
man
command
.
Apart from
rsync
and
cp
,
the
install
command
also allows you to copy files in Linux. |
| Markdown | Menu
[](https://www.howtogeek.com/)
Sign in now
Close
- [News](https://www.howtogeek.com/news/)
- [Tech Deals](https://www.howtogeek.com/deals/)
- - [PC Hardware](https://www.howtogeek.com/pc-hardware/)
Submenu
- [Networking](https://www.howtogeek.com/networking/)
- [Storage and NAS](https://www.howtogeek.com/storage-and-nas/)
- [Components](https://www.howtogeek.com/components/)
- [Peripherals](https://www.howtogeek.com/peripherals/)
- [Operating Systems](https://www.howtogeek.com/operating-systems/)
Submenu
- [Linux](https://www.howtogeek.com/category/linux/)
- [Windows](https://www.howtogeek.com/category/windows/)
- [Software](https://www.howtogeek.com/software/)
Submenu
- [Programming](https://www.howtogeek.com/category/programming/)
- [Applications](https://www.howtogeek.com/applications/)
- [Mobile](https://www.howtogeek.com/category/mobile/)
Submenu
- [Android](https://www.howtogeek.com/category/android/)
- [iPhone](https://www.howtogeek.com/category/ios/)
- [Carriers](https://www.howtogeek.com/category/cellular-carriers/)
- [New Tech](https://www.howtogeek.com/new-tech/)
Submenu
- [Hobbies](https://www.howtogeek.com/category/hobbies/)
- [Smart Home](https://www.howtogeek.com/category/smart-home/)
- [Homelab](https://www.howtogeek.com/tag/homelab/)
- [Single-Board Computers (SBCs)](https://www.howtogeek.com/sbc/)
- [Cutting Edge](https://www.howtogeek.com/category/cutting-edge/)
- [Streaming](https://www.howtogeek.com/streaming/)
Submenu
- [Streaming Content](https://www.howtogeek.com/streaming-content/)
- [Streaming Platforms](https://www.howtogeek.com/streaming-platforms/)
- [Audio/Video](https://www.howtogeek.com/audio-video/)
- [Automotive](https://www.howtogeek.com/category/automotive/)
- [Reviews](https://www.howtogeek.com/category/product-reviews/)
- [Buying Guides](https://www.howtogeek.com/buying-guides/)
- [Sign in](https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/)
- [Newsletter](https://www.howtogeek.com/page/newsletter/)
Menu
[](https://www.howtogeek.com/)
Follow
Followed
Like
More Action
Sign in now
[🔥Tech Deals](https://www.howtogeek.com/deals/)
[Storage](https://www.howtogeek.com/tag/storage/)
[Streaming](https://www.howtogeek.com/category/streaming/)
[Linux](https://www.howtogeek.com/category/linux/)
[Open Source](https://www.howtogeek.com/tag/open-source/)
[Microsoft Excel](https://www.howtogeek.com/tag/microsoft-excel/)
[Android](https://www.howtogeek.com/category/android/)
[Windows](https://www.howtogeek.com/category/windows/)
Close
# How to Copy Files and Directories in the Linux Terminal

Credit: Hannah Stryker / How-To Geek
[](https://www.howtogeek.com/author/mohammedabubakar/)
By [Abubakar Mohammed](https://www.howtogeek.com/author/mohammedabubakar/)
Updated
Oct 18, 2023, 9:31 AM EDT
[Sign in to your How-To Geek account]()
[Add Us On](https://www.google.com/preferences/source?q=howtogeek.com "Add Us On")
Jump links
### Jump Links
- [What is the cp Command?](https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/#what-is-the-cp-command)
- [Copy File on Linux with the cp Command](https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/#copy-file-on-linux-with-the-cp-command)
- [Copy a Directory on Linux](https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/#copy-a-directory-on-linux)
- [Copy Files and Directories with rsync](https://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/#copy-files-and-directories-with-rsync)
follow
Follow
followed
Followed
Like
Like
Log in
Here is a fact-based summary of the story contents:
Try something different:
Show me the facts
Explain it like I’m 5
Give me a lighthearted recap
### Summary
- The cp command can be used to copy files to a directory, copy multiple files to a single directory, and copy a file to a directory with a different name.
- The rsync command, primarily used for transferring files between computers, can also be used to copy files and directories on the same PC and provides a detailed output of the file transfer.
Like any other operating system, you can [copy and paste](https://www.howtogeek.com/203741/how-to-copy-and-paste-text-into-the-linux-terminal/) files and directories (folders) in a Linux distribution using the desktop interface. But you can save time by copying those files in the Terminal. Here's how.
## What is the cp Command?
The cp command is the native copying tool built into Linux. `cp` stands for copy and is, you guessed it, used to copy files and directories in Linux. You can use `cp` to copy files to a directory, copy one directory to another, and copy multiple files to a single directory. Here are all examples that demonstrate the use of the `cp` command.
## Copy File on Linux with the cp Command
Consider `cp`'s syntax in its simplest form.
```
cp [file] [directory]
```
An example of its use would look like this.
```
cp Test1.txt copy_Test1_here/
```

The above command will copy the text file `Test1.txt` to the `copy_Test1_here/` directory.
If you have multiple files that you need to copy to one directory, simply list each file with a space in between.
```
cp Test1.txt Test2.txt Test3.txt Test4.txt copy_all_Tests_here/
```
You can also copy a file to a directory but save it using a different name. Here's the syntax for that.
```
cp [file] [directory]/[new filename]
```
This will copy the contents of the first tile and save it in the directory as the new filename. A real-life example of the same would look like this.
Given that there's a file `Test1.txt` that needs to be copied to the directory `copy_Test1_here` as `Test2.txt` :
```
cp Test1.txt copy_Test1_here/Test2.txt
```

Want to keep it in the same directory? You can copy a file and rename it like so:
```
cp Test1.txt Test2.txt
```
If you're unsure if the file was copied to the destination location, you can also use the option `-v` to [print the names of the files or directories](https://www.howtogeek.com/448446/how-to-use-the-ls-command-on-linux/) that were copied (like a computer program output).
For example, let's assume that there's a file `Test_Example` that needs to be copied to `dir_1` . To display the output of the copy operation, you'd use the `-v` option.
```
cp -v Test_Example.txt dir_1
```
The output would look like this:
```
'Test_Example.txt' -> 'dir_1/Test_Example.txt
```

## Copy a Directory on Linux
Want to copy an entire directory? Let's assume that `dir_1` and `dir_2` are two directories in `/Desktop` . To copy `dir_1` to `dir_2` using the `cp` command, here's what you need to type.
```
cp -a dir_1 dir_2
```

Here option `-a` stands for "archive" and is used to let the computer know that we're dealing with directories. The command copies the directory `dir_1` to `dir_2` .
Most of the same rules apply to copying directoreis that apply to files. For example, you can copy a nested directory just like you might a nested file, and you can pass the -v argument to main cp display the copy operation that has been performed.
The -a flag is actually a combination of two other flags: -R and -d. The -R argument specifies that the copy operation is recursive, and that it must copy the contents of the object being copied as well as the object itself — this is essential for copying folders. The -d argument ensures that all file and folder attributes are preserved.
It is possible to copy folders with just `cp -r dir_1 dir_2` but you may lose specialized attributes if you do that.
## Copy Files and Directories with rsync
The `rsync` command stands for "Remote Sync" and is primarily used to [transfer files and directories](https://www.howtogeek.com/135533/how-to-use-rsync-to-backup-your-data-on-linux/) between computers on the same network. However, it also allows copying files and directories on the same PC. Here are some examples.
Considering that we have two directories `dir_1` , `dir_2` , and a file `Test.txt` in `dir_1` . If we want to copy the file to `dir_2` , here's what the `rsync` command to do the same would look like.
```
rsync -v dir_1/Test.txt dir_2
```

Here `-v` is short for "verbose." It causes the details of the file transfer to appear, similar to the `-v` option in the `cp` command. This allows you to confirm the copy was successful. Here's what the output will be in our case:
```
sent 110 bytes received 35 bytes 290.00 bytes/sectotal size is 24 speedup is 0.17
```
You can also copy multiple files at once from one directory to another. Assume that you're in `/Desktop` in which there are two directories `dir_1` and `dir_2` . `dir_1` has four files `test1` , `test2` , `test3` , and `test4` and you want to copy them to `dir_2`. Here's how you can do that using `rsync`:
```
rsync -v dir_1/Test1.txt dir_1/Test2.txt dir_1/Test3.txt dir_1/Test4.txt dir_2
```
The above command will copy the files `test1` , `test2` , `test3` , and `test4` to the directory `dir_2` .
To copy one directory to another, we must use the `-a` option. Here's an example of how to copy directories using Rsync.
```
rsync -av dir_1 dir_2
```

If you're new to Linux and commands seem hard to follow, make sure to take your time and familiarize yourself with [basic Linux commands](https://www.howtogeek.com/757339/10-basic-linux-commands-for-beginners/) first. You can also learn a lot about commands by using the [`man` command](https://www.howtogeek.com/663440/how-to-use-linuxs-man-command-hidden-secrets-and-basics/).
Apart from `rsync` and `cp`, [the `install` command](https://www.howtogeek.com/411366/how-to-copy-files-with-the-install-command-on-linux/) also allows you to copy files in Linux.
- [Linux](https://www.howtogeek.com/category/linux/ "Linux")
- [Linux & macOS Terminal](https://www.howtogeek.com/tag/terminal/ "Linux & macOS Terminal")
- [Files](https://www.howtogeek.com/tag/files/ "Files")
Follow
Followed
Like
Share
[Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F%2F&src=sdkpreparse) [X](https://twitter.com/intent/tweet?text=How%20to%20Copy%20Files%20and%20Directories%20in%20the%20Linux%20Terminal&url=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F) [WhatsApp](https://web.whatsapp.com/send?text=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F) [Threads](https://www.threads.net/intent/post?text=How%20to%20Copy%20Files%20and%20Directories%20in%20the%20Linux%20Terminal%20https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F) [Bluesky](https://bsky.app/intent/compose?text=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F) [LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F&title=How%20to%20Copy%20Files%20and%20Directories%20in%20the%20Linux%20Terminal&source=www.howtogeek.com&summary=New%20to%20Linux%3F%20Here%27s%20how%20to%20copy%20files%20and%20directories%20in%20a%20jiffy%20using%20the%20terminal%21) [Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F) [Flipboard](http://share.flipboard.com/bookmarklet/popout?v=2&title=How%20to%20Copy%20Files%20and%20Directories%20in%20the%20Linux%20Terminal&url=https%3A%2F%2Fwww.howtogeek.com%2F778790%2Fhow-to-copy-files-and-directories-in-linux-terminal%2F&utm_campaign=tools&utm_medium=article-share&utm_source=www.howtogeek.com) [Copy link]() [Email](<mailto:?Subject=How to Copy Files and Directories in the Linux Terminal&Body=Check%20this%20out%21%0Ahttps://www.howtogeek.com/778790/how-to-copy-files-and-directories-in-linux-terminal/>)
Readers like you help support How-To Geek. When you make a purchase using links on our site, we may earn an affiliate commission. [Read More](https://www.valnetinc.com/en/terms-of-use).
Close
- ### Desktop
- ### Mobile
[](https://www.howtogeek.com/linux-des-are-experiencing-an-extinction-event-kde-gnome-are-to-blame/)
##### [Linux desktop environments are dying, and KDE and GNOME killed them](https://www.howtogeek.com/linux-des-are-experiencing-an-extinction-event-kde-gnome-are-to-blame/ "Linux desktop environments are dying, and KDE and GNOME killed them")
7 minutes ago
[](https://www.howtogeek.com/why-i-dont-use-linux-on-my-desktop/)
##### [Why I don't use Linux on my desktop PC](https://www.howtogeek.com/why-i-dont-use-linux-on-my-desktop/ "Why I don't use Linux on my desktop PC")
44 minutes ago
[](https://www.howtogeek.com/i-replaced-3-paid-productivity-apps-with-one-simple-python-script/)
##### [I replaced 3 paid productivity apps with one simple Python script](https://www.howtogeek.com/i-replaced-3-paid-productivity-apps-with-one-simple-python-script/ "I replaced 3 paid productivity apps with one simple Python script")
1 hour ago
[See More](https://www.howtogeek.com/category/desktop/)
[](https://www.howtogeek.com/the-3-changes-i-made-for-the-ultimate-android-auto-setup/)
##### [I finally found the ultimate Android Auto setup: Here's the 3 changes I made to get here](https://www.howtogeek.com/the-3-changes-i-made-for-the-ultimate-android-auto-setup/ "I finally found the ultimate Android Auto setup: Here's the 3 changes I made to get here")
52 minutes ago
[](https://www.howtogeek.com/your-pixel-phone-is-packed-with-ai-features-you-probably-dont-want/)
##### [Your Pixel phone is packed with AI features you probably don't want](https://www.howtogeek.com/your-pixel-phone-is-packed-with-ai-features-you-probably-dont-want/ "Your Pixel phone is packed with AI features you probably don't want")
2 hours ago
[](https://www.howtogeek.com/android-auto-has-a-hidden-developer-menu-most-people-never-open/)
##### [Android Auto has a hidden developer menu most people never open](https://www.howtogeek.com/android-auto-has-a-hidden-developer-menu-most-people-never-open/ "Android Auto has a hidden developer menu most people never open")
23 hours ago
[See More](https://www.howtogeek.com/category/mobile/)
Trending Now
[](https://www.howtogeek.com/these-tech-upgrades-will-take-your-hobbies-to-the-next-level/)
##### [These 5 tech upgrades will take your hobbies to the next level](https://www.howtogeek.com/these-tech-upgrades-will-take-your-hobbies-to-the-next-level/ "These 5 tech upgrades will take your hobbies to the next level")
[](https://www.howtogeek.com/cosmic-desktop-incredible-but-not-ready/)
##### [COSMIC desktop is incredible, but its not ready yet](https://www.howtogeek.com/cosmic-desktop-incredible-but-not-ready/ "COSMIC desktop is incredible, but its not ready yet")
[](https://www.howtogeek.com/dont-run-home-assistant-in-docker/)
##### [Don't run Home Assistant in Docker, do this instead](https://www.howtogeek.com/dont-run-home-assistant-in-docker/ "Don't run Home Assistant in Docker, do this instead")
Recommended
[](https://www.howtogeek.com/858815/linux-rm-command/)
Oct 13, 2023
### [The Linux rm Command: Everything You Need to Know](https://www.howtogeek.com/858815/linux-rm-command/ "The Linux rm Command: Everything You Need to Know")
[](https://www.howtogeek.com/ubuntu-now-requires-more-ram-than-windows-11/)
2 days ago
### [Ubuntu now requires more RAM than Windows 11](https://www.howtogeek.com/ubuntu-now-requires-more-ram-than-windows-11/ "Ubuntu now requires more RAM than Windows 11")
[](https://www.howtogeek.com/youre-ready-for-arch-linux-if-you-stop-fearing-the-command-line/)
5 days ago
### [You’re probably ready for Arch Linux. Here’s how to tell](https://www.howtogeek.com/youre-ready-for-arch-linux-if-you-stop-fearing-the-command-line/ "You’re probably ready for Arch Linux. Here’s how to tell")
[](https://www.howtogeek.com/stop-spending-thousands-cybertruck-upgrades-5-amazon-finds-cost-200-total/)
21 hours ago
### [Stop spending thousands on Cybertruck upgrades—these 5 Amazon finds cost \$200 total](https://www.howtogeek.com/stop-spending-thousands-cybertruck-upgrades-5-amazon-finds-cost-200-total/ "Stop spending thousands on Cybertruck upgrades—these 5 Amazon finds cost $200 total")
[](https://www.howtogeek.com/)
- [Join Our Team](https://www.howtogeek.com/work-with-us/)
- [Our Audience](https://www.howtogeek.com/page/advertise/)
- [About Us](https://www.howtogeek.com/page/about/)
- [Press & Events](https://www.howtogeek.com/page/press-events/)
- [Media Coverage](https://www.howtogeek.com/page/media/)
- [Contact Us](https://www.howtogeek.com/contact/)
- Follow Us
[](https://www.valnetinc.com/en/)
- [Advertising](https://www.valnetinc.com/en/advertising)
- [Careers](https://www.valnetinc.com/en/careers)
- [Terms](https://www.valnetinc.com/en/terms-of-use)
- [Privacy](https://www.valnetinc.com/en/privacy-policy)
- [Policies](https://www.valnetinc.com/en/editorial-integrity)
[How-To Geek](https://www.howtogeek.com/) is part of the [Valnet Publishing Group](https://www.valnetinc.com/en/)
Copyright © 2026 Valnet Inc. |
| Readable Markdown | ### Summary
- The cp command can be used to copy files to a directory, copy multiple files to a single directory, and copy a file to a directory with a different name.
- The rsync command, primarily used for transferring files between computers, can also be used to copy files and directories on the same PC and provides a detailed output of the file transfer.
Like any other operating system, you can [copy and paste](https://www.howtogeek.com/203741/how-to-copy-and-paste-text-into-the-linux-terminal/) files and directories (folders) in a Linux distribution using the desktop interface. But you can save time by copying those files in the Terminal. Here's how.
## What is the cp Command?
The cp command is the native copying tool built into Linux. `cp` stands for copy and is, you guessed it, used to copy files and directories in Linux. You can use `cp` to copy files to a directory, copy one directory to another, and copy multiple files to a single directory. Here are all examples that demonstrate the use of the `cp` command.
## Copy File on Linux with the cp Command
Consider `cp`'s syntax in its simplest form.
```
cp [file] [directory]
```
An example of its use would look like this.
```
cp Test1.txt copy_Test1_here/
```

The above command will copy the text file `Test1.txt` to the `copy_Test1_here/` directory.
If you have multiple files that you need to copy to one directory, simply list each file with a space in between.
```
cp Test1.txt Test2.txt Test3.txt Test4.txt copy_all_Tests_here/
```
You can also copy a file to a directory but save it using a different name. Here's the syntax for that.
```
cp [file] [directory]/[new filename]
```
This will copy the contents of the first tile and save it in the directory as the new filename. A real-life example of the same would look like this.
Given that there's a file `Test1.txt` that needs to be copied to the directory `copy_Test1_here` as `Test2.txt` :
```
cp Test1.txt copy_Test1_here/Test2.txt
```

Want to keep it in the same directory? You can copy a file and rename it like so:
```
cp Test1.txt Test2.txt
```
If you're unsure if the file was copied to the destination location, you can also use the option `-v` to [print the names of the files or directories](https://www.howtogeek.com/448446/how-to-use-the-ls-command-on-linux/) that were copied (like a computer program output).
For example, let's assume that there's a file `Test_Example` that needs to be copied to `dir_1` . To display the output of the copy operation, you'd use the `-v` option.
```
cp -v Test_Example.txt dir_1
```
The output would look like this:
```
'Test_Example.txt' -> 'dir_1/Test_Example.txt
```

## Copy a Directory on Linux
Want to copy an entire directory? Let's assume that `dir_1` and `dir_2` are two directories in `/Desktop` . To copy `dir_1` to `dir_2` using the `cp` command, here's what you need to type.
```
cp -a dir_1 dir_2
```

Here option `-a` stands for "archive" and is used to let the computer know that we're dealing with directories. The command copies the directory `dir_1` to `dir_2` .
Most of the same rules apply to copying directoreis that apply to files. For example, you can copy a nested directory just like you might a nested file, and you can pass the -v argument to main cp display the copy operation that has been performed.
The -a flag is actually a combination of two other flags: -R and -d. The -R argument specifies that the copy operation is recursive, and that it must copy the contents of the object being copied as well as the object itself — this is essential for copying folders. The -d argument ensures that all file and folder attributes are preserved.
It is possible to copy folders with just `cp -r dir_1 dir_2` but you may lose specialized attributes if you do that.
## Copy Files and Directories with rsync
The `rsync` command stands for "Remote Sync" and is primarily used to [transfer files and directories](https://www.howtogeek.com/135533/how-to-use-rsync-to-backup-your-data-on-linux/) between computers on the same network. However, it also allows copying files and directories on the same PC. Here are some examples.
Considering that we have two directories `dir_1` , `dir_2` , and a file `Test.txt` in `dir_1` . If we want to copy the file to `dir_2` , here's what the `rsync` command to do the same would look like.
```
rsync -v dir_1/Test.txt dir_2
```

Here `-v` is short for "verbose." It causes the details of the file transfer to appear, similar to the `-v` option in the `cp` command. This allows you to confirm the copy was successful. Here's what the output will be in our case:
```
sent 110 bytes received 35 bytes 290.00 bytes/sectotal size is 24 speedup is 0.17
```
You can also copy multiple files at once from one directory to another. Assume that you're in `/Desktop` in which there are two directories `dir_1` and `dir_2` . `dir_1` has four files `test1` , `test2` , `test3` , and `test4` and you want to copy them to `dir_2`. Here's how you can do that using `rsync`:
```
rsync -v dir_1/Test1.txt dir_1/Test2.txt dir_1/Test3.txt dir_1/Test4.txt dir_2
```
The above command will copy the files `test1` , `test2` , `test3` , and `test4` to the directory `dir_2` .
To copy one directory to another, we must use the `-a` option. Here's an example of how to copy directories using Rsync.
```
rsync -av dir_1 dir_2
```

If you're new to Linux and commands seem hard to follow, make sure to take your time and familiarize yourself with [basic Linux commands](https://www.howtogeek.com/757339/10-basic-linux-commands-for-beginners/) first. You can also learn a lot about commands by using the [`man` command](https://www.howtogeek.com/663440/how-to-use-linuxs-man-command-hidden-secrets-and-basics/).
Apart from `rsync` and `cp`, [the `install` command](https://www.howtogeek.com/411366/how-to-copy-files-with-the-install-command-on-linux/) also allows you to copy files in Linux. |
| Shard | 195 (laksa) |
| Root Hash | 5883057217006082795 |
| Unparsed URL | com,howtogeek!www,/778790/how-to-copy-files-and-directories-in-linux-terminal/ s443 |