How to copy one file contents to another file in Linux

www.‮ual‬tturi.com
How to copy one file contents to another file in Linux

To copy the contents of one file to another file in Linux, you can use the cat command and the > operator. Here is an example of how to do this:

cat source.txt > destination.txt

This command will copy the contents of the file source.txt to the file destination.txt. If the destination.txt file does not exist, it will be created. If the file exists, its contents will be overwritten.

You can also use the tee command to copy the contents of a file to multiple destination files. For example:

cat source.txt | tee destination1.txt destination2.txt

This command will copy the contents of the file source.txt to both destination1.txt and destination2.txt.

Note that these commands will not preserve file ownership and permissions. If you want to preserve these attributes, you can use the cp command instead. For example:

cp -a source.txt destination.txt

This command will copy the file source.txt to destination.txt, preserving the file ownership, permissions, and other metadata.

Created Time:2017-10-28 21:39:01  Author:lautturi