How to copy files via terminal?

1) By using -i for interactive you will be asked if you would like to replace the file:

cp -i /home/levan/kdenlive/untitelds.mpg /media/sda3/SkyDrive/

or you can use -b to create a backup of your file:

cp -b /home/levan/kdenlive/untitelds.mpg /media/sda3/SkyDrive



2) Same as the above:

cp (-i or -b) /media/sda3/SkyDrive/untitelds.mpg /home/levan/kdenlive



3) Use -R for recursive and -i for interactive:

cp -Ri ~/MyFolder /sda3/



4) This last one can be done via the mv command, move is like cutting:

mv -i ~/MyFile ~/OtherFolder/MyFile

if you want to move a directory, use:

mv -Ri ~/MyDirectory ~/OtherDirectory/

When ~/Dropbox/RECENT/ is your current directory:

cp input.txt SORT/

And I want to copy input.txt with another name in my current directory.

Again with ~/Dropbox/RECENT/ as current directory:

cp  input.txt newname.txt

Existing filenames can be auto-completed using TAB.

Long version of the same copy command (when you are not in ~/Dropbox/RECENT/):

cp /home/$USER/Dropbox/RECENT/input.txt /home/$USER/Dropbox/RECENT/SORT/

I put a / behind every directory. If SORT does NOT exist a cp will also create a file named SORT making you think something went wrong. Adding the / will have cp error out and not copy the file.


Use the cp command.

Copying a file something.txt to file folder: use cp something.txt folder/

Copying a file something.txt to the current directory as something2.txt: use cp something.txt something2.txt

ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l
total 8
drwxrwxr-x 2 ubuntu ubuntu 4096 Mar 12 21:53 Folder1
-rw-rw-r-- 1 ubuntu ubuntu   14 Mar 12 21:52 something.txt
ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l Folder1/
total 4
-rw-rw-r-- 1 ubuntu ubuntu 14 Mar 12 21:53 something.txt
ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l
total 8
drwxrwxr-x 2 ubuntu ubuntu 4096 Mar 12 21:54 folder
-rw-rw-r-- 1 ubuntu ubuntu   14 Mar 12 21:52 something.txt
ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l folder/
total 0
ubuntu@ubuntu-T100TA:~/TestFolder$ cp something.txt folder/
ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l folder/
total 4
-rw-rw-r-- 1 ubuntu ubuntu 14 Mar 12 21:55 something.txt
ubuntu@ubuntu-T100TA:~/TestFolder$ cp something.txt something2.txt 
ubuntu@ubuntu-T100TA:~/TestFolder$ ls -l
total 12
drwxrwxr-x 2 ubuntu ubuntu 4096 Mar 12 21:55 folder
-rw-rw-r-- 1 ubuntu ubuntu   14 Mar 12 21:55 something2.txt
-rw-rw-r-- 1 ubuntu ubuntu   14 Mar 12 21:52 something.txt