In this tutorial, you will learn three tips for file copy in linux terminal using three different ways.
THREE DIFFERENT WAYS
- Linux provides three different options to COPY A TEXT FILE in the terminal. They are:
- Using cp command
- Using cat command
- Using pipe with tee command
1. Copy File using cp command
- This is how to copy file in linux using cp command
- This command is used to copy the contents of an old text file to the target file.
Syntax
cp src file target file
Here, src file is an old file and target file is a new file.
Output
2.Copy File using cat command
- This command is used to copy the contents of an old text file to the target file with help of greater than symbol > (output redirection)
Syntax
cat src file > target file
- Here, src file is an old file and target file is a new file.
- The symbol > is called as output redirection in linux shell which is used to send an output data from one command to another command / file.
Output
3. Copy File using tee command
- This command is used to copy the contents of an old text file to the target file using the pipe (|)
- In linux terminal, the pipe is a connector of two or more commands which means that the output of one command can be given as the input of another command.
- In linux terminal, pipe is identified using the special symbol |
Syntax
cat src file | tee target file
- Here, src file is an old file and target file is a new file.
- Cat command is displaying the file content and pipe will send the result of cat command to another file which will be saved using the tee command.
- It is noted that the output data can be displayed in the terminal during the use of tee command.
Output