next up previous contents
Next: Copying Files Up: Moving and Copying Previous: Moving and Copying

Moving Files and Relative Paths

To move files around between directories or rename them we use the mvgif command. This command takes the name of the source file and the name of the destination as parameters. Say we want to move our file 'e' in the programs directory to the directory above (recall the directory above is denoted by '..'):

$ls -F
e   f*
$mv e ..
$ls -F
f*
$ls -F ..
a          b          c          data/      
e          junk/      programs/
$

Let us now move the file 'e' in the directory above our current directory into the 'data' directory. At this point we will start using relative paths. Relative paths are a method of accessing a file that is not in our current directory. Recall that '..' is the directory above the current directory. File and directory names are always separated by a '/'. If we look at our directory structure in figure gif, say we want to give the relative path for the file 'o'. If we are in the start directory the path would be 'data/personal/o', from the directory data it would be 'personal/o', from the directory personal it would just be 'o', from the directory 'junk' or 'programs' it would be '../data/personal/o'. Say we want to give the relative path to the file 'k' from the 'personal' directory, we have to go up two directories and down into the 'junk' directory, this will give the relative path '../../junk/k'. Now remember we are in the 'programs' directory:

$mv ../e ../data
$cd ..
$ls -F
a          b          c          data/      junk/      programs/
$ls -F data
e          g          h          i          personal/
$

Now let us move the file back to the 'programs' directory and call it 'd':

$mv data/e programs/d
$ls -F data
g          h          i          personal/
$ls -F programs
d   f*
$

There is one restriction on the mv command; it can only move files on a physical disk, but not across disks. When the mv command fails it is always wise to check if you tried moving files between physical disks.



Mark O. Stitson
Wed Sep 25 10:45:32 BST 1996