🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 39 (from laksa035)

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
21 hours ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 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://phoenixnap.com/kb/how-to-copy-files-directories-linux
Last Crawled2026-04-06 08:48:27 (21 hours ago)
First Indexed2019-05-17 20:31:09 (6 years ago)
HTTP Status Code200
Meta TitleHow to Copy Files and Directories in Linux (With Examples)
Meta DescriptionFind out how to copy files and directories from the Linux command line. A straightforward guide with simple command examples.
Meta Canonicalnull
Boilerpipe Text
Home » KB » SysAdmin » How to Copy Files and Directories in Linux Topics: Copying files and directories in Linux is an essential administrative task. Copies are instrumental for backing up important files or transferring them to another location, for example, a data storage device. The cp command is useful for basic copying needs, while rsync excels at complex tasks, such as selectively copying specific files or creating system-wide backups. Learn how to copy files and directories in Linux using the cp and rsync commands. Prerequisites A Linux system. Access to a command line /terminal window. How to Copy Files in Linux Using cp Command The cp command is the primary method for copying files and directories within a local Linux filesystem . The basic command syntax is: cp [option] [source] [destination] The source is the file or directory you want to copy, while the destination represents the location where the copy should be placed. The destination can be a directory path or a new filename if the file needs to be renamed . Use the listed cp command options below to specify different behaviors: OPTION DESCRIPTION -v Displays additional information about the copying process. -p Forces the system to preserve source file attributes (modification time, access time, user ID (UID), group ID (GID), file flags, file mode, access control lists (ACLs) , and extended attributes (EAs)). -f If the destination file/directory exists, replaces it with the source. -i Prompts for confirmation before overwriting a file. -r Copies all files in a directory. -u Replaces files only if they satisfy the update condition. For example, when the destination file does not exist or when the source file is newer than the destination file. How to Copy a Single File Enter the following command to copy a single file within the current working directory: cp my_file.txt my_file2.txt The system does not provide an output. Use the ls command to confirm that the file has been copied. By default, the cp command runs in the same directory you are working in. However, the same file cannot exist twice in the same directory. You must rename the target file to copy it to the same location. You can add _old to the name, or add a number or change the extension (e.g., .bak instead of .txt ). Note: The cp command in Linux does not provide a warning before overwriting existing files. Use the –i option for the system to prompt you before overwiting a file. Enter the following command to copy a file from the current working directory to a different directory: cp -v my_file.txt path/to/destination Replace path/to/destination with the actual directory path. The -v option displays additional information about the copying process. The command fails if the destination directory does not exist because  cp  does not create directories. Note: Find out how to create directories in Linux with the mkdir command . Use the following command to copy a single file to a different directory and rename it: cp my_file.txt path/to/destination/my_file2.txt To copy a file without having to change directories, specify a path for the source file and the destination directory: cp -v ~/Documents/my_file.txt path/to/destination Replace the example path in the command with the actual path on your system. In this example, the -v option was used to verify that the file was copied successfully. How to Copy Multiple Files To copy more than one file at a time, list each file to be copied before entering the destination directory: cp my_file.txt my_file2.txt my_file3.txt path/to/destination The system creates a copy of all three files in the destination folder. The wildcard ( * ) character allows users to specify files that share a string of characters. The following command finds all the files with the .jpg extension in the pictures directory and copies them into the destination folder: cp ~/pictures/*.jpg path/to/destination If one of the files or directories requires root or higher-level permissions, use the sudo command to elevate privileges temporarily. How to Copy Directories in Linux Using cp Command To copy an entire directory and its subdirectories and files , use the –r option. The following command copies all files and directories from the Documents directory to the new_destination directory: cp -r ~/Documents path/to/new_destination The -r option stands for recursive, which means "everything in that location." Copying Files Using rsync Command The rsync command in Linux synchronizes or transfers data between two locations. Usage is similar to the cp command, but while cp only copies files locally. To transfer files and directories to remote systems, you can use rsync over SSH . The tool saves bandwidth and transfers files faster by compressing them and only transferring new or updated files. In addition, rsync creates a new directory if the final part of the destination path specifies a non-existent location. How to Copy a Single File Using rsync To copy one file to another directory on a local machine, type the source file's full path, followed by the destination directory: rsync -av ~/Documents/my_file.txt ~/destination/backups/ Replace the source path and /destination/backups/ destination from the example with your system's actual path and destination directory. The -a option instructs rsync to preserve file metadata and other attributes such as permissions and timestamps. The -v option provides detailed output about the file transfer process. How to Copy a Directory Using rsync In this example, rsync is used to copy the contents of the /home/phoenixnap/anaconda3/doc/config/ directory to /home/phoenixnap/backups/anaconda3/ : rsync -av /home/phoenixnap/anaconda3/doc/config/ /home/phoenixnap/backups/anaconda/ The trailing slash ( / ) at the end of the source and destination paths ensures you only copy the content of the source directory. Omitting the slash on the source directory creates a new subdirectory within the destination directory. To prevent specific files from being copied, check out our guide on how to use rsync to exclude files and directories from a data transfer. Conclusion You now know how to copy files in a local Linux filesystem. The cp and rsync commands are versatile and powerful tools for managing and backing up files, especially when combined with other essential Linux commands . Was this article helpful? Yes No
Markdown
- [Call](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Support](tel:1-855-330-1509) - [Sales](tel:1-877-588-5918) - [Login](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Bare Metal Cloud](https://bmc.phoenixnap.com/) - [Admin Hub](https://admin.phoenixnap.com/) - [Partners](https://phoenixnap.com/partners) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-colocation-mobile.svg)COLOCATION](https://phoenixnap.com/colocation) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/02-colocation-plus.svg)Colocation Premier Carrier Hotel](https://phoenixnap.com/colocation) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/03-data-center-as-a-service.svg)Data Center as a Service Solutions for Digital Transformation](https://phoenixnap.com/colocation/data-center-as-a-service) - [Data Center as a Service Overview](https://phoenixnap.com/colocation/data-center-as-a-service) - [Hardware as a Service Flexible Hardware Leasing](https://phoenixnap.com/colocation/hardware-as-a-service) - [Bare Metal Cloud API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud) - [Object Storage S3 API Compatible Storage Service](https://phoenixnap.com/object-storage) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/04-meet-me-room.svg)Meet-Me Room The Interconnectivity Hub](https://phoenixnap.com/colocation/meet-me-room) - [Meet-Me Room Overview](https://phoenixnap.com/colocation/meet-me-room) - [AWS Direct Connect Dedicated Link to Amazon Cloud](https://phoenixnap.com/colocation/aws-direct-connect) - [Google Cloud Interconnect Private Connectivity to Google Cloud](https://phoenixnap.com/google-cloud-interconnect) - [Megaport Cloud Router Simplified Multi-Cloud Connections](https://phoenixnap.com/offers/megaport-cloud-router) - [All Carriers Global Interconnectivity Options](https://phoenixnap.com/colocation/all-carriers) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/05-schedule-a-tour.svg)Schedule a Tour Guided Virtual Data Center Tour](https://phoenixnap.com/phoenix-data-center-virtual-tour) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/06-data-center-locations.svg)Data Center Locations Global Data Center Footprint](https://phoenixnap.com/colocation/data-center-locations) - [Data Center Locations Overview](https://phoenixnap.com/colocation/data-center-locations) - [Phoenix, AZ The Largest Fiber Backbone in the U.S.](https://phoenixnap.com/colocation/phoenix) - [Amsterdam, NL The Connectivity Hub of Europe](https://phoenixnap.com/colocation/amsterdam) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-bare-metal-cloud-platform.svg)BARE METAL CLOUD](https://phoenixnap.com/bare-metal-cloud) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-bare-metal-cloud-platform.svg)Platform API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud) - [Platform Overview](https://phoenixnap.com/bare-metal-cloud) - [Infrastructure As Code DevOps Integrations](https://phoenixnap.com/bare-metal-cloud/infrastructure-as-code) - [BMC vs. Dedicated Servers Choose the Best Option](https://phoenixnap.com/bare-metal-cloud-vs-dedicated-servers) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/02-bare-metal-cloud-pricing.svg)Pricing Instance pricing and cost estimation](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Instance Pricing See All Configurations](https://phoenixnap.com/bare-metal-cloud/instances) - [Pricing Calculator Get an Estimate](https://phoenixnap.com/cloud-pricing-calculator) - [Network/IP Pricing Flexible IP Pricing](https://phoenixnap.com/bare-metal-cloud/ip-pricing) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/03-kubernetes-solutions.svg)Kubernetes Solutions Streamlined Kubernetes Management](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Rancher Deployment One-Click Kubernetes Deployment](https://phoenixnap.com/bare-metal-cloud/rancher-deployment) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/04-cpus.svg)CPUs Next Gen Intel Processors](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Xeon 6 6700-series with E-Cores Supercharge Cloud-Native Workloads](https://phoenixnap.com/bare-metal-cloud/intel-xeon-6-processors-with-e-cores) - [Intel® Core™ i9 14900K Ideal for Gaming, Streaming, and Content Creation](https://phoenixnap.com/bare-metal-cloud/intel-core-i9-14900k) - [5th Gen Intel Xeon Scalable CPUs Boost Data-Intensive Workloads](https://phoenixnap.com/bare-metal-cloud/5th-gen-intel-xeon-scalable-processors) - [HPE Ampere Altra Q80-30 HPE® ProLiant RL300 as a service](https://phoenixnap.com/bare-metal-cloud/hpe-proliant-rl300) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/05-alliances.svg)Alliances Technology Partnerships](https://phoenixnap.com/bare-metal-cloud/technology-ecosystem) - [Ecosystem Underlying Technologies](https://phoenixnap.com/bare-metal-cloud/technology-ecosystem) - [NetrisOS VPC networking on bare metal](https://phoenixnap.com/bare-metal-cloud/netris) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/06-storage-options.svg)Storage Options Flexible Storage Solutions](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Object Storage S3-Compatible Storage Solution](https://phoenixnap.com/object-storage) - [Network File Storage All-Flash Scale-Out Storage Resources](https://phoenixnap.com/network-file-storage) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/07-gpu-servers.svg)GPU Servers For AI/ML and HPC workloads](https://phoenixnap.com/kb/how-to-copy-files-directories-linux) - [Intel Max 1100 GPUs 1 system. 2 GPUs. Amazing performance.](https://phoenixnap.com/bare-metal-cloud/gpu-servers) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-hybrid-cloud-mobile.svg)HYBRID CLOUD](https://phoenixnap.com/security/data-security-cloud) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/02-hybrid-cloud-overview.svg)Hybrid Cloud Overview](https://phoenixnap.com/cloud-services/hybrid-cloud-solutions) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/03-object-storage.svg)Object Storage S3 Compatible Storage Solution](https://phoenixnap.com/object-storage) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/04-bare-metal-cloud.svg)Bare Metal Cloud API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/05-alternative-cloud-provider.svg)Alternative Cloud Provider Overcome Public Cloud Limitations](https://phoenixnap.com/cloud-services/alternative-cloud-provider) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/06-backup-solutions.svg)Backup Solutions Veeam-Powered Services](https://phoenixnap.com/backup-restore) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/07-disaster-recovery.svg)Disaster Recovery VMware, Veeam, Zerto](https://phoenixnap.com/disaster-recovery-as-a-service-draas) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/08-veeam-cloud-connect.svg)Veeam Cloud Connect Backup and Replication](https://phoenixnap.com/backup-restore/veeam-cloud-connect) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/09-managed-backup-for-microsoft-365.svg)Managed Backup for Microsoft 365 Veeam-Powered Service](https://phoenixnap.com/backup-restore/microsoft-365-backup) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-network-mobile.svg)NETWORK](https://phoenixnap.com/network) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/02-network-overview.svg)Network Overview Global Network Footprint](https://phoenixnap.com/network) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/03-network-locations.svg)Network Locations U.S., Europe, APAC, LATAM](https://phoenixnap.com/network/locations) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/04-speed-test.svg)Speed Test Download Speed Test](https://phoenixnap.com/network/speed-test) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/01-learn-mobile.svg)LEARN](https://phoenixnap.com/kb) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/02-blog.svg)Blog IT Tips and Tricks](https://phoenixnap.com/blog/) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/04-resource-library.svg)Resource Library Knowledge Resources](https://phoenixnap.com/company/resource-library) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/05-glossary.svg)Glossary IT Terms and Definitions](https://phoenixnap.com/glossary/) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/06-events.svg)Events Let's Meet\!](https://phoenixnap.com/company/it-events) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/07-newsroom.svg)Newsroom Media Library](https://phoenixnap.com/company/press) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/08-developers.svg)Developers Development Resources Portal](https://developers.phoenixnap.com/) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/09-apis.svg)APIs Access Our Public APIs](https://developers.phoenixnap.com/apis) - [![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E)![](https://phoenixnap.com/kb/wp-content/uploads/2025/11/10-github.svg)GitHub Public Code Repositories](https://github.com/phoenixnap) [Home](https://phoenixnap.com/) » [KB](https://phoenixnap.com/kb/) » [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) » How to Copy Files and Directories in Linux # How to Copy Files and Directories in Linux ![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E) ![](https://secure.gravatar.com/avatar/8d4609e99e6aecc69ce049e18d45f033?s=200&d=mm&r=g) By [Vladimir Kaplarevic](https://phoenixnap.com/kb/author/vladimirk) Published: December 19, 2025 Topics: [commands](https://phoenixnap.com/kb/tag/commands), [linux](https://phoenixnap.com/kb/tag/linux) Copying [files](https://phoenixnap.com/glossary/what-is-a-file) and [directories](https://phoenixnap.com/glossary/what-is-a-directory) in [Linux](https://phoenixnap.com/kb/what-is-linux) is an essential administrative task. Copies are instrumental for backing up important files or transferring them to another location, for example, a [data storage](https://phoenixnap.com/kb/what-is-data-storage) device. The [cp command](https://phoenixnap.com/kb/cp-command) is useful for basic copying needs, while [rsync](https://phoenixnap.com/kb/rsync-command-linux-examples) excels at complex tasks, such as selectively copying specific files or creating system-wide backups. Learn how to copy files and directories in Linux using the **`cp`** and **`rsync`** commands. ![Guide for copying files and directories in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20799%20400'%3E%3C/svg%3E) ![Guide for copying files and directories in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-files-directories-linux.png) Prerequisites - A Linux system. - Access to a [command line](https://phoenixnap.com/glossary/command-line-interface-cli)/terminal window. ## How to Copy Files in Linux Using cp Command The **`cp`** command is the primary method for copying files and directories within a local Linux [filesystem](https://phoenixnap.com/glossary/filesystem). The basic command syntax is: ``` cp [option] [source] [destination] ``` The `source` is the file or directory you want to copy, while the **`destination`** represents the location where the copy should be placed. The `destination` can be a directory path or a new filename if the file needs to be [renamed](https://phoenixnap.com/kb/rename-file-linux). Use the listed **`cp`** command options below to specify different behaviors: | OPTION | DESCRIPTION | |---|---| | **\-v** | Displays additional information about the copying process. | | **\-p** | Forces the system to preserve source file attributes (modification time, access time, user ID (UID), group ID (GID), file flags, file mode, [access control lists (ACLs)](https://phoenixnap.com/kb/acl-network), and extended attributes (EAs)). | | **\-f** | If the destination file/directory exists, replaces it with the source. | | **\-i** | Prompts for confirmation before overwriting a file. | | **\-r** | Copies all files in a directory. | | ****\-u**** | Replaces files only if they satisfy the update condition. For example, when the destination file does not exist or when the source file is newer than the destination file. | ### How to Copy a Single File Enter the following command to copy a single file within the current working directory: ``` cp my_file.txt my_file2.txt ``` The system does not provide an output. Use the [ls command](https://phoenixnap.com/kb/linux-ls-commands) to confirm that the file has been copied. ![Copying files within the same directory in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%2070'%3E%3C/svg%3E) ![Copying files within the same directory in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-same-directory-linux2.png) By default, the **`cp`** command runs in the same directory you are working in. However, the same file cannot exist twice in the same directory. **Note:** Learn how to [check or change the working directory](https://phoenixnap.com/kb/python-change-directory) using the [cd command](https://phoenixnap.com/kb/linux-cd-command). You must rename the target file to copy it to the same location. You can add *\_old* to the name, or add a number or change the extension (e.g., **.bak** instead of **.txt**). **Note:** The **`cp`** command in Linux does not provide a warning before overwriting existing files. Use the **`–i`** option for the system to prompt you before overwiting a file. Enter the following command to copy a file from the current working directory to a different directory: ``` cp -v my_file.txt path/to/destination ``` Replace *path/to/destination* with the actual directory path. The **`-v`** option displays additional information about the copying process. ![Copying a single file to a different directory in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%2056'%3E%3C/svg%3E) ![Copying a single file to a different directory in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-different-directory-linux.png) The command fails if the destination directory does not exist because **cp** does not create directories. ![System failed to copy file in Linux because the destination directory does not exist.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%2068'%3E%3C/svg%3E) ![System failed to copy file in Linux because the destination directory does not exist.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/cp-command-new-directory-fail.png) **Note:** Find out how to create directories in Linux with the [mkdir command](https://phoenixnap.com/kb/create-directory-linux-mkdir-command). Use the following command to copy a single file to a different directory and rename it: ``` cp my_file.txt path/to/destination/my_file2.txt ``` To copy a file without having to change directories, specify a path for the source file and the destination directory: ``` cp -v ~/Documents/my_file.txt path/to/destination ``` Replace the example path in the command with the actual path on your system. ![Copying files in Linux using their full path.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%2050'%3E%3C/svg%3E) ![Copying files in Linux using their full path.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-to-another-directory-linux.png) In this example, the **`-v`** option was used to verify that the file was copied successfully. ### How to Copy Multiple Files To copy more than one file at a time, list each file to be copied before entering the destination directory: ``` cp my_file.txt my_file2.txt my_file3.txt path/to/destination ``` The system creates a copy of all three files in the destination folder. The wildcard (**`*`**) character allows users to specify files that share a string of characters. The following command finds all the files with the *.jpg* extension in the **`pictures`** directory and copies them into the **`destination`** folder: ``` cp ~/pictures/*.jpg path/to/destination ``` If one of the files or directories requires [root](https://phoenixnap.com/glossary/what-is-root-access) or higher-level permissions, use the [sudo command](https://phoenixnap.com/kb/linux-sudo-command) to elevate privileges temporarily. **Note:** Learn how to transfer files [between two Linux systems](https://phoenixnap.com/kb/linux-to-linux). ## How to Copy Directories in Linux Using cp Command To **copy an** **entire directory and its** [subdirectories](https://phoenixnap.com/glossary/what-is-a-subdirectory) **and files**, use the **`–r`** option. The following command copies all files and directories from the **`Documents`** directory to the **`new_destination`** directory: ``` cp -r ~/Documents path/to/new_destination ``` The **`-r`** option stands for recursive, which means "everything in that location." **Note:** As an alternative to copying directories, learn how to [move directories in Linux](https://phoenixnap.com/kb/move-directory-linux). ## Copying Files Using rsync Command The [rsync command](https://phoenixnap.com/kb/rsync-back-up-data) in Linux synchronizes or transfers data between two locations. Usage is similar to the **`cp`** command, but while **`cp`** only copies files locally. To transfer files and directories to remote systems, you can use [rsync over SSH](https://phoenixnap.com/kb/how-to-rsync-over-ssh). The tool saves [bandwidth](https://phoenixnap.com/glossary/what-is-bandwidth) and transfers files faster by [compressing](https://phoenixnap.com/glossary/file-compression) them and only transferring new or updated files. In addition, **`rsync`** creates a new directory if the final part of the destination path specifies a non-existent location. ### How to Copy a Single File Using rsync To copy one file to another directory on a local machine, type the source file's full path, followed by the destination directory: ``` rsync -av ~/Documents/my_file.txt ~/destination/backups/ ``` Replace the source path and */destination/backups/* destination from the example with your system's actual path and destination directory. ![Copy a file locally using rsync.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%20140'%3E%3C/svg%3E) ![Copy a file locally using rsync.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/rsync-save-file-local-directory.png) The **`-a`** option instructs **`rsync`** to preserve file [metadata](https://phoenixnap.com/glossary/metadata-definition) and other attributes such as [permissions](https://phoenixnap.com/kb/linux-file-permissions) and timestamps. The **`-v`** option provides detailed output about the file transfer process. ### How to Copy a Directory Using rsync In this example, **`rsync`** is used to copy the contents of the */home/phoenixnap/anaconda3/doc/config/* directory to */home/phoenixnap/backups/anaconda3/*: ``` rsync -av /home/phoenixnap/anaconda3/doc/config/ /home/phoenixnap/backups/anaconda/ ``` The trailing slash (**`/`**) at the end of the source and destination paths ensures you only copy the content of the source directory. Omitting the slash on the source directory creates a new subdirectory within the destination directory. ![Copying the content of a directory to a different directory using rsync.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%20150'%3E%3C/svg%3E) ![Copying the content of a directory to a different directory using rsync.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-directory-rsync.png) To prevent specific files from being copied, check out our guide on how to use [rsync to exclude files and directories](https://phoenixnap.com/kb/rsync-exclude-files-and-directories) from a data transfer. Conclusion You now know how to copy files in a local Linux filesystem. The **`cp`** and **`rsync`** commands are versatile and powerful tools for managing and backing up files, especially when combined with other [essential Linux commands](https://phoenixnap.com/kb/linux-commands). Was this article helpful? YesNo Contents - [How to Copy Files in Linux Using cp Command](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_Files_in_Linux_Using_cp_Command) - [How to Copy a Single File](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_a_Single_File) - [How to Copy Multiple Files](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_Multiple_Files) - [How to Copy Directories in Linux Using cp Command](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_Directories_in_Linux_Using_cp_Command) - [Copying Files Using rsync Command](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#Copying_Files_Using_rsync_Command) - [How to Copy a Single File Using rsync](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_a_Single_File_Using_rsync) - [How to Copy a Directory Using rsync](https://phoenixnap.com/kb/how-to-copy-files-directories-linux#How_to_Copy_a_Directory_Using_rsync) Subscribe to our newsletter [SUBSCRIBE](https://phoenixnap.com/developers-monthly-newsletter) Next you should read [![Guide for copying files and directories in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20799%20400'%3E%3C/svg%3E)![Guide for copying files and directories in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-files-directories-linux.png)](https://phoenixnap.com/kb/how-to-remove-files-directories-linux-command-line) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) [How to Remove (Delete) a File or Directory in Linux](https://phoenixnap.com/kb/how-to-remove-files-directories-linux-command-line) [![Different methods for creating files in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%20400'%3E%3C/svg%3E)![Different methods for creating files in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2024/07/create-file-linux.png)](https://phoenixnap.com/kb/how-to-create-a-file-in-linux) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) [Web Servers](https://phoenixnap.com/kb/category/web-servers) [How to Create a File in Linux Using Terminal/Command Line](https://phoenixnap.com/kb/how-to-create-a-file-in-linux) [![Using the grep command in Linux.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%20400'%3E%3C/svg%3E)![Using the grep command in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2024/02/grep-command-linux.png)](https://phoenixnap.com/kb/grep-command-linux-unix-examples) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) [How To Use grep Command In Linux/UNIX](https://phoenixnap.com/kb/grep-command-linux-unix-examples) [![SCP Command in Linux](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20800%20400'%3E%3C/svg%3E)![SCP Command in Linux](https://phoenixnap.com/kb/wp-content/uploads/2022/01/scp-command-in-linux.png)](https://phoenixnap.com/kb/linux-scp-command) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) [SCP Command in Linux {13 Examples}](https://phoenixnap.com/kb/linux-scp-command) CONTACT US [Get a Quote](https://phoenixnap.com/contact-us) [Support (1-855-330-1509)](tel:1-855-330-1509) [Sales (1-877-588-5918)](tel:1-877-588-5918) - [Colocation](https://phoenixnap.com/colocation) - [Phoenix](https://phoenixnap.com/colocation/phoenix) - [Ashburn](https://phoenixnap.com/colocation/ashburn) - [Amsterdam](https://phoenixnap.com/colocation/amsterdam) - [Atlanta](https://phoenixnap.com/colocation/atlanta) - [Belgrade](https://phoenixnap.com/colocation/belgrade) - [Singapore](https://phoenixnap.com/colocation/singapore) - [Shipping Instructions](https://phoenixnap.com/colocation/shipping-instructions) RECENT POSTS ["Invalid Reference Format" Error in Docker: How to Fix](https://phoenixnap.com/kb/docker-invalid-reference-format) [Python dict() Function Explained](https://phoenixnap.com/kb/python-dict) [Ansible get\_url Module: Download Files from URL](https://phoenixnap.com/kb/ansible-get-url) [Docker Desktop: Unexpected WSL Error](https://phoenixnap.com/kb/docker-desktop-unexpected-wsl-error) [How to Check if a File Exists in Python](https://phoenixnap.com/kb/check-if-file-exist-python) - [Servers](https://phoenixnap.com/servers/dedicated) - [Bare Metal Cloud](https://phoenixnap.com/bare-metal-cloud) - [Dedicated Servers](https://phoenixnap.com/servers/dedicated) - [Database Servers](https://phoenixnap.com/servers/database) - [Virtualization Servers](https://phoenixnap.com/servers/virtualization) - [High Performance Computing (HPC) Servers](https://phoenixnap.com/servers/high-performance-computing-hpc) - [Dedicated Streaming Servers](https://phoenixnap.com/servers/streaming) - [Dedicated Game Servers](https://phoenixnap.com/servers/dedicated-game-servers) - [Dedicated Storage Servers](https://phoenixnap.com/servers/storage) - [SQL Server Hosting](https://phoenixnap.com/servers/sql-server-hosting) - [Dedicated Servers in Amsterdam](https://phoenixnap.com/dedicated-servers-amsterdam-netherlands) - [Cloud Servers in Europe](https://phoenixnap.com/cloud-services/cloud-servers-europe) - [Big Memory Infrastructure](https://phoenixnap.com/bare-metal-cloud/big-memory-infrastructure) - [Buy Now](https://admin.phoenixnap.com/wap-pncpadmin-shell/orderForm?bmbPath=/order-form?currencyCode=usd) - [BMC portal](https://signup.bmc.phoenixnap.com/) CLOUD SERVICES - [Data Security Cloud](https://phoenixnap.com/security/data-security-cloud) - [Managed Private Cloud](https://phoenixnap.com/private) - [Object Storage](https://phoenixnap.com/object-storage) - [Solutions](https://phoenixnap.com/infrastructure-solutions) - [Disaster Recovery](https://phoenixnap.com/infrastructure-solutions/disaster-recovery-services) - [Web Hosting Reseller](https://phoenixnap.com/reseller-hosting) - [SaaS Hosting](https://phoenixnap.com/infrastructure-solutions/saas-hosting) COMPLIANCE - [HIPAA Ready Hosting](https://phoenixnap.com/compliance/hipaa-compliant-hosting) - [PCI Compliant Hosting](https://phoenixnap.com/compliance/pci-compliant-hosting) - [Privacy Center](https://phoenixnap.com/) - [Do not sell or share my personal information](https://phoenixnap.com/) NEEDS - [Disaster Recovery Solutions](https://phoenixnap.com/infrastructure-solutions/disaster-recovery-services) - [High Availability Solutions](https://phoenixnap.com/infrastructure-solutions/high-availability-solutions) - [Cloud Evaluation](https://phoenixnap.com/offers/cloud-evaluation-demo) INDUSTRIES - [Web Hosting Providers](https://phoenixnap.com/reseller-hosting) - [Legal](https://phoenixnap.com/infrastructure-solutions/legal-it) - [MSPs & VARs](https://phoenixnap.com/infrastructure-solutions/it-partners) - [Media Hosting](https://phoenixnap.com/infrastructure-solutions/media-hosting) - [Online Gaming](https://phoenixnap.com/infrastructure-solutions/online-gaming) - [SaaS Hosting Solutions](https://phoenixnap.com/infrastructure-solutions/saas-hosting) - [Ecommerce Hosting Solutions](https://phoenixnap.com/infrastructure-solutions/ecommerce-hosting) COMPANY - [About phoenixNAP](https://phoenixnap.com/about) - [IaaS Solutions](https://phoenixnap.com/company/iaas-provider) - [Customer Experience](https://phoenixnap.com/company/customer-experience) - [Platform](https://phoenixnap.com/cloud-services/platform) - [Schedule Virtual Tour](https://phoenixnap.com/phoenix-data-center-virtual-tour) - [Open Source Community](https://phoenixnap.com/company/open-source-community) - [Resource Library](https://phoenixnap.com/company/resource-library) - [Press](https://phoenixnap.com/company/press) - [Events](https://phoenixnap.com/company/it-events) - [Careers](https://techjobs.dev/jobs/) - [Promotions](https://phoenixnap.com/promotions) - [Contact Us](https://phoenixnap.com/contact-us) - [Legal](https://phoenixnap.com/cs/legal/) - [Privacy Policy](https://phoenixnap.com/infrastructure-solutions/legal-it/eu-u-s-data-privacy-framework-program-eu-u-s-dpf-compliant-privacy-policy) - [Terms of Use](https://phoenixnap.com/cs/legal/aup.html) - [DMCA](https://phoenixnap.com/cs/legal/dmca.html) - [GDPR](https://phoenixnap.com/gdpr) - [Sitemap](https://phoenixnap.com/sitemap) - [Blog](https://phoenixnap.com/blog) - [Resources](https://phoenixnap.com/company/resource-library) - [Knowledge Base](https://phoenixnap.com/kb) - [IT Glossary](https://phoenixnap.com/glossary) - [GitHub](https://github.com/phoenixnap) - [RFP Template](https://phoenixnap.com/company/it-resources/data-center-rfp-template) © 2025 phoenixNAP \| Global IT Services. All Rights Reserved.
Readable Markdown
[Home](https://phoenixnap.com/) » [KB](https://phoenixnap.com/kb/) » [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) » How to Copy Files and Directories in Linux ![](https://secure.gravatar.com/avatar/8d4609e99e6aecc69ce049e18d45f033?s=200&d=mm&r=g) Topics: Copying [files](https://phoenixnap.com/glossary/what-is-a-file) and [directories](https://phoenixnap.com/glossary/what-is-a-directory) in [Linux](https://phoenixnap.com/kb/what-is-linux) is an essential administrative task. Copies are instrumental for backing up important files or transferring them to another location, for example, a [data storage](https://phoenixnap.com/kb/what-is-data-storage) device. The [cp command](https://phoenixnap.com/kb/cp-command) is useful for basic copying needs, while [rsync](https://phoenixnap.com/kb/rsync-command-linux-examples) excels at complex tasks, such as selectively copying specific files or creating system-wide backups. Learn how to copy files and directories in Linux using the **`cp`** and **`rsync`** commands. ![Guide for copying files and directories in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-files-directories-linux.png) Prerequisites A Linux system. Access to a [command line](https://phoenixnap.com/glossary/command-line-interface-cli)/terminal window. How to Copy Files in Linux Using cp Command The **`cp`** command is the primary method for copying files and directories within a local Linux [filesystem](https://phoenixnap.com/glossary/filesystem). The basic command syntax is: The `source` is the file or directory you want to copy, while the **`destination`** represents the location where the copy should be placed. The `destination` can be a directory path or a new filename if the file needs to be [renamed](https://phoenixnap.com/kb/rename-file-linux). Use the listed **`cp`** command options below to specify different behaviors: OPTION DESCRIPTION **\-v** Displays additional information about the copying process. **\-p** Forces the system to preserve source file attributes (modification time, access time, user ID (UID), group ID (GID), file flags, file mode, [access control lists (ACLs)](https://phoenixnap.com/kb/acl-network), and extended attributes (EAs)). **\-f** If the destination file/directory exists, replaces it with the source. **\-i** Prompts for confirmation before overwriting a file. **\-r** Copies all files in a directory. ****\-u**** Replaces files only if they satisfy the update condition. For example, when the destination file does not exist or when the source file is newer than the destination file. How to Copy a Single File Enter the following command to copy a single file within the current working directory: The system does not provide an output. Use the [ls command](https://phoenixnap.com/kb/linux-ls-commands) to confirm that the file has been copied. ![Copying files within the same directory in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-same-directory-linux2.png) By default, the **`cp`** command runs in the same directory you are working in. However, the same file cannot exist twice in the same directory. You must rename the target file to copy it to the same location. You can add *\_old* to the name, or add a number or change the extension (e.g., **.bak** instead of **.txt**). **Note:** The **`cp`** command in Linux does not provide a warning before overwriting existing files. Use the **`–i`** option for the system to prompt you before overwiting a file. Enter the following command to copy a file from the current working directory to a different directory: Replace *path/to/destination* with the actual directory path. The **`-v`** option displays additional information about the copying process. ![Copying a single file to a different directory in Linux.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-different-directory-linux.png) The command fails if the destination directory does not exist because **cp** does not create directories. ![System failed to copy file in Linux because the destination directory does not exist.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/cp-command-new-directory-fail.png) **Note:** Find out how to create directories in Linux with the [mkdir command](https://phoenixnap.com/kb/create-directory-linux-mkdir-command). Use the following command to copy a single file to a different directory and rename it: To copy a file without having to change directories, specify a path for the source file and the destination directory: Replace the example path in the command with the actual path on your system. ![Copying files in Linux using their full path.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-file-to-another-directory-linux.png) In this example, the **`-v`** option was used to verify that the file was copied successfully. How to Copy Multiple Files To copy more than one file at a time, list each file to be copied before entering the destination directory: The system creates a copy of all three files in the destination folder. The wildcard (**`*`**) character allows users to specify files that share a string of characters. The following command finds all the files with the *.jpg* extension in the **`pictures`** directory and copies them into the **`destination`** folder: If one of the files or directories requires [root](https://phoenixnap.com/glossary/what-is-root-access) or higher-level permissions, use the [sudo command](https://phoenixnap.com/kb/linux-sudo-command) to elevate privileges temporarily. How to Copy Directories in Linux Using cp Command To **copy an** **entire directory and its** [subdirectories](https://phoenixnap.com/glossary/what-is-a-subdirectory) **and files**, use the **`–r`** option. The following command copies all files and directories from the **`Documents`** directory to the **`new_destination`** directory: The **`-r`** option stands for recursive, which means "everything in that location." Copying Files Using rsync Command The [rsync command](https://phoenixnap.com/kb/rsync-back-up-data) in Linux synchronizes or transfers data between two locations. Usage is similar to the **`cp`** command, but while **`cp`** only copies files locally. To transfer files and directories to remote systems, you can use [rsync over SSH](https://phoenixnap.com/kb/how-to-rsync-over-ssh). The tool saves [bandwidth](https://phoenixnap.com/glossary/what-is-bandwidth) and transfers files faster by [compressing](https://phoenixnap.com/glossary/file-compression) them and only transferring new or updated files. In addition, **`rsync`** creates a new directory if the final part of the destination path specifies a non-existent location. How to Copy a Single File Using rsync To copy one file to another directory on a local machine, type the source file's full path, followed by the destination directory: Replace the source path and */destination/backups/* destination from the example with your system's actual path and destination directory. ![Copy a file locally using rsync.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/rsync-save-file-local-directory.png) The **`-a`** option instructs **`rsync`** to preserve file [metadata](https://phoenixnap.com/glossary/metadata-definition) and other attributes such as [permissions](https://phoenixnap.com/kb/linux-file-permissions) and timestamps. The **`-v`** option provides detailed output about the file transfer process. How to Copy a Directory Using rsync In this example, **`rsync`** is used to copy the contents of the */home/phoenixnap/anaconda3/doc/config/* directory to */home/phoenixnap/backups/anaconda3/*: The trailing slash (**`/`**) at the end of the source and destination paths ensures you only copy the content of the source directory. Omitting the slash on the source directory creates a new subdirectory within the destination directory. ![Copying the content of a directory to a different directory using rsync.](https://phoenixnap.com/kb/wp-content/uploads/2023/12/copy-directory-rsync.png) To prevent specific files from being copied, check out our guide on how to use [rsync to exclude files and directories](https://phoenixnap.com/kb/rsync-exclude-files-and-directories) from a data transfer. Conclusion You now know how to copy files in a local Linux filesystem. The **`cp`** and **`rsync`** commands are versatile and powerful tools for managing and backing up files, especially when combined with other [essential Linux commands](https://phoenixnap.com/kb/linux-commands). Was this article helpful? YesNo
Shard39 (laksa)
Root Hash8557101678125738839
Unparsed URLcom,phoenixnap!/kb/how-to-copy-files-directories-linux s443