🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 80 (from laksa191)

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

🚫
NOT INDEXABLE
CRAWLED
6 months ago
🚫
ROBOTS BLOCKED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffFAILdownload_stamp > now() - 6 MONTH6.5 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.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/
Last Crawled2025-10-02 01:27:27 (6 months ago)
First Indexed2019-01-22 18:21:33 (7 years ago)
HTTP Status Code200
Meta TitleHow to copy one file contents to another file in Linux - nixCraft
Meta DescriptionExplains how to copy one file contents to another file using the cp command in Linux operating system bash shell/terminal session.
Meta Canonicalnull
Boilerpipe Text
I ‘m a new Linux system user and don’t know much about the Ubuntu terminal. So, I have a file named data.txt. How do I copy data.txt file contents to another file called data.backup.txt in RHEL or CentOS Linux? How do I duplicate files in a Linux-based computer before I modify the original file? You need to use the cp command . It is used to copy files and directories. The copies become independent of the originals. Any subsequent change in one will not affect the other. This page shows how to use cp command to copy one file contents to another at bash shell. Let us see how to copy one file contents to another file in Linux using the CLI. Copy one file contents to another file in Linux The cp commands basic syntax is: cp file_name new_file_name cp [ options ] file_name new_file_name cp original_name new_name Please note that when a copy is made of a file, the copy must have a different name than the original. For example, the following is a valid example: cp file1 file2 However, the following would fail: cp nixcraft.txt nixcraft.txt Here is what cp would report: cp: 'nixcraft.txt' and 'nixcraft.txt' are the same file However, a file named nixcraft.txt could be copied with the same name into another directory: cp -v nixcraft.txt /tmp/ File names are case sensitive too. It means following example should work: cp nixcraft.txt NIXCRAFT.txt ls -l nixcraft.txt NIXCRAFT.txt Sample outputs: -rw-rw-r--. 1 vivek vivek 6 Jan 20 18 : 12 nixcraft.txt -rw-rw-r--. 1 vivek vivek 6 Jan 20 18 : 12 NIXCRAFT.txt Linux copy file to another file Let us create a new file in Linux named foo.txt: echo "This is a test" > foo.txt Next copy foo.txt as bar.txt, run: cp foo.txt bar.txt Verify it with help of ls command: ls -l foo.txt ls -l bar.txt To see cp command progress and verbose output, pass the -v command option to cp: cp -v foo.txt bar.txt Update the original foo.txt: echo "Another line" >> foo.txt Use the cat command to see both files: cat foo.txt cat bar.txt Copy content of one file to another file Say you want to copy all files from /home/vivek/project/ to /home/vivek/backups/, run: cp -av /home/vivek/project/ /home/vivek/backups/ Now, we can make changes in /home/vivek/project/ directory. Where, -a : Archive mode i.e. copy all files and directories recursively -v : Verbose mode -r : Recursive mode in Linux for cp command Conclusion Writing contents of a file to another file is easy in Linux. Simply use: cp -v filename newname For more information see cp command man page by typing the following man command / help command : man cp cp --help 🥺 Was this helpful? Please add a comment to show your appreciation or feedback . Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via RSS feed or email newsletter .
Markdown
[![nixCraft](https://www.cyberciti.biz/media/new/faq/2017/06/new-nixcraft-logo-cyberciti.biz_.png)](https://www.cyberciti.biz/faq/) [nixCraft](https://www.cyberciti.biz/) → [Howto](https://www.cyberciti.biz/faq/) → [Linux](https://www.cyberciti.biz/faq/category/linux/) → How to copy one file contents to another file in Linux # [How to copy one file contents to another file in Linux](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/) Author: Vivek Gite Last updated: March 28, 2022 [2 comments](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#comments) [![See all GNU/Linux related FAQ](https://www.cyberciti.biz/media/new/category/old/linux-logo.png)](https://www.cyberciti.biz/faq/category/linux/ "See all GNU/Linux related FAQ") I‘m a new Linux system user and don’t know much about the Ubuntu terminal. So, I have a file named data.txt. How do I copy data.txt file contents to another file called data.backup.txt in RHEL or CentOS Linux? How do I duplicate files in a Linux-based computer before I modify the original file? You need to use the [cp command](https://www.cyberciti.biz/faq/cp-copy-command-in-unix-examples/ "Unix Copy Command Examples [ cp command ]"). It is used to copy files and directories. The copies become independent of the originals. Any subsequent change in one will not affect the other. This page shows how to use **cp command to copy one file contents to another** at bash shell. Let us see how to copy one file contents to another file in Linux using the CLI. | Tutorial details | | |---|---| | Difficulty level | [Easy](https://www.cyberciti.biz/faq/tag/easy/ "See all Easy Linux / Unix System Administrator Tutorials") | | Root privileges | No | | Requirements | Linux terminal | | Category | [File Management](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#File_Management "See ALL other tutorials in 'File Management' category") | | OS compatibility | AlmaLinux • [Alpine](https://www.cyberciti.biz/faq/category/alpine-linux/ "See all Alpine Linux tutorials") • [Arch](https://www.cyberciti.biz/faq/category/arch-linux/ "See all Arch Linux tutorials") • [Debian](https://www.cyberciti.biz/faq/category/debian-ubuntu/ "See all Debian Linux tutorials") • [Fedora](https://www.cyberciti.biz/faq/category/fedora-linux/ "See all Fedora Linux Enterprise tutorials") • [Linux](https://www.cyberciti.biz/faq/category/linux/ "See all Linux distributions tutorials") • Mint • [openSUSE](https://www.cyberciti.biz/faq/tag/opensuse/ "See all openSUSE Linux Enterprise tutorials") • Pop!\_OS • [RHEL](https://www.cyberciti.biz/faq/category/redhat-and-friends/ "See all RHEL (Red Hat Enterprise Linux) tutorials") • Rocky • [Stream](https://www.cyberciti.biz/faq/tag/centos-stream/ "See all CentOS Stream Linux tutorials") • [SUSE](https://www.cyberciti.biz/faq/category/suse/ "See all SUSE Linux Enterprise tutorials") • [Ubuntu](https://www.cyberciti.biz/faq/category/ubuntu-linux/ "See all Ubuntu Linux tutorials") • WSL | | Est. reading time | 3 minutes | ## Copy one file contents to another file in Linux The cp commands basic syntax is: ``` cp file_name new_file_name cp [options] file_name new_file_name cp original_name new_name ``` Please note that when a copy is made of a file, the copy must have a different name than the original. For example, the following is a valid example: `cp file1 file2` However, the following would fail: `cp nixcraft.txt nixcraft.txt` Here is what cp would report: ``` cp: 'nixcraft.txt' and 'nixcraft.txt' are the same file ``` However, a file named nixcraft.txt could be copied with the same name into another directory: `cp -v nixcraft.txt /tmp/` File names are case sensitive too. It means following example should work: Sample outputs: ``` -rw-rw-r--. 1 vivek vivek 6 Jan 20 18:12 nixcraft.txt -rw-rw-r--. 1 vivek vivek 6 Jan 20 18:12 NIXCRAFT.txt ``` ## Linux copy file to another file Let us [create a new file in Linux](https://www.cyberciti.biz/faq/create-files-in-linux-unix-from-bash/) named foo.txt: `echo "This is a test" > foo.txt` Next copy foo.txt as bar.txt, run: `cp foo.txt bar.txt` Verify it with help of ls command: To see cp command progress and verbose output, pass the -v command option to cp: `cp -v foo.txt bar.txt` Update the original foo.txt: `echo "Another line" >> foo.txt` Use the [cat command](https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-cat-command-examples/ "cat Command in Linux / Unix with examples") to see both files: ![How to copy one file contents to another in Linux](https://www.cyberciti.biz/media/new/faq/2014/04/How-to-copy-one-file-contents-to-another-in-Linux.png) ## Copy content of one file to another file Say you want to copy all files from /home/vivek/project/ to /home/vivek/backups/, run: `cp -av /home/vivek/project/ /home/vivek/backups/` Now, we can make changes in /home/vivek/project/ directory. Where, 1. `-a` : Archive mode i.e. copy all files and directories recursively 2. `-v` : Verbose mode 3. `-r` : Recursive mode in Linux for cp command ## Conclusion Writing contents of a file to another file is easy in Linux. Simply use: `cp -v filename newname` For more information see [cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html) command man page by typing the following [man command](https://bash.cyberciti.biz/guide/Man_command "Man command - Linux Bash Shell Scripting Tutorial Wiki")/[help command](https://bash.cyberciti.biz/guide/Help_command "help command - Linux Bash Shell Scripting Tutorial Wiki"): 🥺 Was this helpful? Please add [a comment to show your appreciation or feedback](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#respond "Please add your comment below ↓ to show your appreciation or feedback to the author"). [Vivek Gite](https://www.vivekgite.com/) is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via [RSS feed](https://www.cyberciti.com/atom/atom.xml "Get nixCraft updates using RSS feed") or [email newsletter](https://newsletter.cyberciti.com/subscription?f=1ojtmiv8892KQzyMsTF4YPr1pPSAhX2rq7Qfe5DiHMgXwKo892di4MTWyOdd976343rcNR6LhdG1f7k9H8929kMNMdWu3g "Get nixCraft updates using Email"). 2 comments… [add one](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#respond) - Shaker Raju Aug 12, 2015 @ 12:54 Another option is [↩](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#comment-931808) [∞](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#comment-931808 "permalink to this comment") - Layer8 user May 13, 2017 @ 1:02 I paste the contents of one file into another file using cat in Linux: `cat my_file > new_file` I paste and append the contents of one file into another file using cat too on Linux: `cat my_file >> new_file` [↩](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#comment-931809) [∞](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#comment-931809 "permalink to this comment") Leave a Reply[Cancel reply](https://www.cyberciti.biz/faq/how-to-copy-one-file-contents-to-another-file-in-linux/#respond) Use HTML \<pre\>...\</pre\> for code samples. Your comment will appear only after approval by the site admin. Next FAQ: [How To Upgrade To a Newer Version of Ubuntu 14.04 LTS](https://www.cyberciti.biz/faq/howto-upgrade-to-ubuntu-14-04-from-ubuntu-13-10-or-12-04/) Previous FAQ: [How to end task with PID in Linux](https://www.cyberciti.biz/faq/how-to-end-task-with-pid-in-linux/) 🔥 FEATURED ARTICLES - 1 [30 Cool Open Source Software I Discovered in 2013](https://www.cyberciti.biz/open-source/30-cool-best-open-source-softwares-of-2013/) - 2 [30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X](https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html) - 3 [Top 32 Nmap Command Examples For Linux Sys/Network Admins](https://www.cyberciti.biz/networking/nmap-command-examples-tutorials/) - 4 [25 PHP Security Best Practices For Linux Sys Admins](https://www.cyberciti.biz/tips/php-security-best-practices-tutorial.html) - 5 [30 Linux System Monitoring Tools Every SysAdmin Should Know](https://www.cyberciti.biz/tips/top-linux-monitoring-tools.html) - 6 [40 Linux Server Hardening Security Tips](https://www.cyberciti.biz/tips/linux-security.html) - 7 [Linux: 25 Iptables Netfilter Firewall Examples For New SysAdmins](https://www.cyberciti.biz/tips/linux-iptables-examples.html) - 8 [Top 20 OpenSSH Server Best Security Practices](https://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html) - 9 [Top 25 Nginx Web Server Best Security Practices](https://www.cyberciti.biz/tips/linux-unix-bsd-nginx-webserver-security.html) - 10 [My 10 UNIX Command Line Mistakes](https://www.cyberciti.biz/tips/my-10-unix-command-line-mistakes.html) 👀 /etc - ➔ [Linux shell scripting tutorial](https://bash.cyberciti.biz/guide/Main_Page "Linux Shell Scripting Tutorial Wiki") - ➔ [RSS/Feed](https://www.cyberciti.com/atom/atom.xml "Get updates using RSS feed") - ➔ [About nixCraft](https://www.cyberciti.biz/tips/about-us "About nixCraft") ©2002-2025 nixCraft • [Privacy](https://www.cyberciti.biz/tips/privacy "Privacy policy") • [ToS](https://www.cyberciti.biz/tips/disclaimer "Term of Service") • [Contact/Email](https://www.cyberciti.biz/tips/contact-us "Contact us via Email") • Corporate patron [Cloudflare](https://www.cyberciti.biz/tips/nixcraft-sponsors "Corporate patron")
Readable Markdownnull
Shard80 (laksa)
Root Hash1965753964674472280
Unparsed URLbiz,cyberciti!www,/faq/how-to-copy-one-file-contents-to-another-file-in-linux/ s443