Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

W W W . L I N U X D O T . O R G

Newbie's Linux Manual
Command Tutorial #4: cp, mv & rm
by Laurence Hunter
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
cp - copy
Examples:

cp -r a b
Copy the entire contents of directory a into directory b.


cp a.txt backup
Copy the file a.txt across to the directory backup.


cp a.txt backup/a_bk.txt
Copy the file a.txt across to the directory backup and rename it a_bk.txt at the same time. If the file backup/a_bk.txt already existed then it will be overwritten without warning.


cp -i a.txt backup/a_bk.txt
The same as above but asks for confirmation before overwriting an existing file.


cp a b c d
In the above form, every parameter but the last - are the files to copy, and the last parameter - is the directory to copy the files too.

Note:

When copying more than one file you can't rename it at the same time.

mv - move

mv is a clever little command that will either move a file (mv file directory), or rename it (mv oldfilename newfilename).


mv a b c work/reports
Move the files a, b, and c into the directory work/reports.


mv -i a b c work/reports
The same as above, but asks for confirmation before overwriting any existing files.


mv a.txt b.txt
Rename the file a.txt - b.txt.

rm - remove

rm a b c
Remove the files a, b and c.


rm -i a b c
The same as above, but asks for confirmation before removing each file - very important when removing files using wildcards!


rm -r work/reports
The r stands for "recursive" meaning every file and directory, in the directory work/reports will be removed, without warning - so be careful!

[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Homepage | The Last 5 Days | The Daily Linux News | The Linux Bits | Newbie's Linux Manual
The Best Linux Sites | Linux Book Reviews | A Windows Vendetta?
Diary of a Linux Newbie | Diary of an Open Source Newbie
The Linux Forum | Just For Fun
Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy!
© MM Linuxdot.org | Webmaster | Manual's Copyright Terms