Linux Copy Files With cp Command

Copy Files With Linux

The 'cp' command can be used to copy files from one location to another. After a file is copied, there is the original file and the copied file.

Copying a File
The code below will copy the index.php file from the user directory into the current working directory which is user2

 root@vps [/home/user2]# cp /home/user/index.php ./  

Copying a File To a New Name
The code below will copy the oldfile file to a file named newfile

 root@vps [/home/user2]# cp -r oldfile newfile  root@vps [/]# cp -r newtest.txt newtest2.txt root@vps [/]# ls   

Both files newtest.txt and newtest2.txt now exist.