mv


The mv command is used to move a file or directory from one location to another location. You can also move multiple files.

The following example shows a listing of a directory, the move of file krsort.c to krsort.test.c within this directory, and a listing of the directory showing that the file has been moved:

 $  ls -l  total 168 -rwxr-xr-x   1 denise   users    34592 Oct 31 15:17 krsort -rwxr-xr-x   1 denise   users     3234 Oct 31 15:17 krsort.c -rwxr-xr-x   1 denise   users     2756 Oct 31 15:17 krsort.dos -rw-r--r--   1 denise   users     9922 Oct 31 15:17 krsort.q -rwxr-xr-x   1 denise   users    3085 Oct 31 15:17 krsortorig.c $  mv krsort.c krsort.test.c  $  ls -l  total 168 -rwxr-xr-x   1 denise   users  34592 Oct 31 15:17 krsort -rwxr-xr-x   1 denise   users  32756 Oct 31 15:17 krsort.dos -rw-r--r--   1 denise   users   9922 Oct 31 15:17 krsort.q -rwxr-xr-x   1 denise   users   3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x   1 denise   users   3085 Oct 31 15:17 krsortorig.c $ 

What if the destination file already exists? You guessed it, UNIX is more than happy to write over the destination file. Using the -i option, mv asks you to confirm overwriting a file before it does so. The following example shows an attempt to move krsort.test.c to krsortorig.c. The user is alerted to the fact that krsortorig.c already exists and chooses not to let the move take place:

 $  ls -l  total 168 -rwxr-xr-x   1 denise   users      34592 Oct 31 15:17 krsort -rwxr-xr-x   1 denise   users      32756 Oct 31 15:17 krsort.dos -rw-r--r--   1 denise   users       9922 Oct 31 15:17 krsort.q -rwxr-xr-x   1 denise   users       3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x   1 denise   users       3085 Oct 31 15:17 krsortorig.c $  mv -i krsort.test.c krsortorig.c  remove krsortorig.c? (y/n)  n  $  ls -l  total 168 -rwxr-xr-x   1 denise   users      34592 Oct 31 15:17 krsort -rwxr-xr-x   1 denise   users      32756 Oct 31 15:17 krsort.dos -rw-r--r--   1 denise   users       9922 Oct 31 15:17 krsort.q -rwxr-xr-x   1 denise   users       3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x   1 denise   users       3085 Oct 31 15:17 krsortorig.c $ 

Because the response was not in the affirmative , the move does not take place, and the original krsortorig.c remains intact.

mv - Move files and directories.

Options

 

-i

Interactive move whereby you are prompted to confirm that you wish to overwrite an existing file.

 

-f

Force existing files to be overwritten by files being moved if a conflict in file names occurs.

 

-p

Preserve permissions when moving.



HP-UX 11i Systems Administration Handbook and Toolkit
HP-UX 11i Systems Administration Handbook and Toolkit (2nd Edition)
ISBN: 0131018833
EAN: 2147483647
Year: 2003
Pages: 301

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net