LinuxMall.com Got Linux? CD Offer
Newbie's Linux Manual
Command Tutorial #3: 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

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

The Newbie's Linux Manual is reproduced on LinuxMall.com by permission. The Newbie's Linux Manual is written and maintained by Laurence Hunter. You can find much more of Laurence's work at his site: www.Linuxdot.org

© 1999 Linuxdot.org | Manual's Copyright Terms