Thursday, 28th August 2008
The "mv" command has two functions. It can move a file from one directory to another, or change the name of a file.
This will rename the file current_project to march_project.
This moves the file called march_project one directory higher and into the accounting directory. Again be very careful, if the detination file already exists, it will be overwritten and you will lose all data that file contained.
$ mv -i march_project ../accounting
mv: overwrite '../accounting/march_project'? n
The "-i" option will make the mv command check to see if a file already exists and ask you to confirm you want to overwrite it. Enter 'y' for yes or 'n' for no.
Lets have a look at a few examples:
# moves the file into the psychology_due/ directory
$ mv project2.txt psychology_due/
# moves the file one directory higher
$ mv project1.txt ..
# moves the file up one directory and into the 2003 directory
$ mv project3.txt ../2003/
# moves all .txt files into the notes directory
$ mv *.txt notes/
Lets find out how to make and remove directories.