Linux/Unix – Moving Files and Directories…

Use the mv (“move”) tool to move, or rename, a file or directory to a different location. It takes two arguments: the name of the file or directory to move followed by the path name to move it to. If you move a file to a directory that contains a file of the same name, the file is overwritten.

To move the file `notes’ in the current working directory to `../play’, type:

$ mv notes ../play

This command moves the file `notes’ in the current directory to `play’, a subdirectory of the current working directory’s parent. If a file `notes’ already exists in `play’, that file is overwritten. If the subdirectory `play’ does not exist, this command moves `notes’ to its parent directory and renames it `play’. To move a file or directory that is not in the current directory, give its full path name as an argument.

To move the file `/usr/tmp/notes’ to the current working directory, type:

$ mv /usr/tmp/notes .

This command moves the file `/usr/tmp/notes’ to the current working directory. To move a directory, give the path name of the directory you want to move and the path name to move it to as arguments.

To move the directory `work’ in the current working directory to `play’, type:

$ mv work play

This command moves the directory `work’ in the current directory to the directory `play’. If the directory `play’ already exists, mv puts `work’ inside `play’−−−it does not overwrite directories. Renaming a file is the same as moving it; just specify as arguments the file to rename followed by the new file name.

To rename the file `notes’ to `notes.old’, type:

$ mv notes notes.old 


Advertisements

About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on March 16, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: