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