# cp command – How to Copy Files in Linux ?

## cp command in Linux –

The cp command in Linux is used to copy files and directories in Linux. To copy the content of the source file to the destination file we write

cp source.txt destination.txt

At this moment in our current directory we have two files fact.py and test.py.

Now, Let’s say I want to copy the contents of the fact.py file to test.py. For that we will write

cp fact.py test.py

Now we can use the cat command to see the content of the test.py file.

We can see that the contents of the fact.py file has been successfully copied to test.py

We can also copy multiple files into a directory, for that we use cp with a list of source files as the first arguments, and the destination directory as the last argument. Here, we copy the files file1.txt and file2.txt into the same directory.

cp file1.txt file2.txt my_directory/ 

Let’s go once step back and see what files and directories we have.

We can see that we have two folders python and java. Now suppose you want to copy the fact.py and test.py files which is inside the python folder to java folder. To do that we will write

cp python/fact.py python/test.py java/

Now we can see that both the files are copied to the java folder.

Rating: 1 out of 5.