Doctor Bob
Linux Topic Search
TOURBUS
HOME PAGE
SAVVY
CONSUMER
FREE TECH
SUPPORT

LINUX FILES

How Do I Copy and Rename Linux Files?

Copying Files

Copying files under Linux is similar to copying files under DOS. Here's an example using the cp (copy) command:
$ cp goulash recipes/hungarian
$ cp stuff stuff.bak

The first example copies the goulash file from the current directory and stores it in your recipes/hungarian directory. The second example creates a file called stuff.bak in the current directory that is identical to the source file stuff.

Note: The cp command will overwrite files with the same name without warning. To be prompted before overwriting, use the -i flag, like so:

$ cp -i goulash recipes/hungarian
cp: overwrite recipes/hungarian/goulash (y/n)?

Renaming Files

Use the mv command to rename a file or move it to another directory, like so:

$ mv stuff junk
$ mv junk trashcan

The first example renames the file stuff as junk, and the second moves the file junk into a directory called trashcan.

Note: The mv command will wipe out files without warning. To be prompted before overwriting, use the -i flag, like so:

$ mv -i stuff junk
mv: overwrite junk (y/n)?

Previous Lesson: Displaying Linux Files
Next Lesson: Creating Files and Directories

[ RETURN TO INDEX ]

Comments

sheemul     (08 Feb 2010, 05:03)
Excellent !!
m3m3     (19 Feb 2010, 09:40)
I used the steps below but I dont seem to manage to work it out , I get this message" no such file or directory" & the file is right infron of my eyes!!
do I have to change the directory to somewhere else??
Bob Rankin     (19 Feb 2010, 10:32)
Perhaps the target folder does not exist?
m3m3     (20 Feb 2010, 05:29)
I checked that & it was there.
Is there any other error I could have done??
is there any other thing I must consider??
Bob Rankin     (22 Feb 2010, 05:27)
What is the exact command you are entering?
Dennis     (01 Mar 2010, 03:36)
$ mv stuff junk
$ mv junk trashcan

How the system knows not to rename "junk" with name "trashcan",as it does in first case, but to move it in directory.
Bob Rankin     (01 Mar 2010, 06:43)
If trashcan did not exist as a directory, it *would* rename junk.

*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 

Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.