pavement

Mv

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(Expanded the article on the mv command)
 
Line 1: Line 1:
mv -- move. The equivalent of "rename", since on unix systems, a file's full location is the same thing as it's name.
+
{{System-Commands}}
  
Use:
+
The '''mv''' command is used to ''move'' files around the file system.  It can also be used to rename files.
samizdata# mv /home/dave/myfile /tmp/myfile
+
moves ''myfile'' from /home/dave/ to the /tmp/ directory
+
  
==Common Flags==
+
== Moving file(s) ==
 +
 
 +
The obvious use for the mv command, as it's name implies, is to move files from one location on a file system to another, both to and from locally attached or network share file systems.  Some examples:
 +
 
 +
# mv /usr/home/bob/song.ogg /use/home/bob/mymusic/
 +
 
 +
This will simply move the file 'song.ogg' (a sound file) from the Bob's user directory into his dedicated directory called 'mymusic'.  This could also be done from the directory itself, using what is known as relative paths:
 +
 
 +
# cd /usr/home/bob
 +
# mv song.ogg mymusic/
 +
 
 +
Similar to many file system commands it is possible to use [[wildcards]] as a parameter.  For example:
 +
 
 +
# cd /usr/home/bob
 +
# mv *.ogg  mymusic/
 +
 
 +
Which will move all files ending in '.ogg' into the 'mymusic' directory, whether there was one or more such sound files.
 +
 
 +
== Renaming file(s) ==
 +
 
 +
The other use for the mv command is to rename files.  This is because there is no 'rename' command as found on other operating systems (Microsoft's DOS, for example, uses the command 'ren' to rename files separate from the 'move' command to move files).  The mv command will rename a file when only two filenames are provided, without a directory path, for example:
 +
 
 +
# cd /usr/home/bob
 +
# mv song.ogg heavymetaltrack.ogg
 +
 
 +
This simply renames the file 'song.ogg' to 'heavymetaltrack.ogg'.
 +
 
 +
== Command switches ==
  
 
  -v verbose
 
  -v verbose
Line 11: Line 36:
 
  -n no-overwriting existing files -- cancels any previous -f switches
 
  -n no-overwriting existing files -- cancels any previous -f switches
 
  -f force -- cancels out any previous -i or -n switches
 
  -f force -- cancels out any previous -i or -n switches
 +
 
[[Category:System Commands]]
 
[[Category:System Commands]]

Latest revision as of 14:27, 10 May 2008

The Mediawiki system (the 'software' that runs this site) capitalises all articles. Please note that commands on most UNIX and Unix-like systems are entered in lower case. As an example the article documenting the Ln command would be issued from the command line as 'ln'.

The mv command is used to move files around the file system. It can also be used to rename files.

[edit] Moving file(s)

The obvious use for the mv command, as it's name implies, is to move files from one location on a file system to another, both to and from locally attached or network share file systems. Some examples:

# mv /usr/home/bob/song.ogg /use/home/bob/mymusic/

This will simply move the file 'song.ogg' (a sound file) from the Bob's user directory into his dedicated directory called 'mymusic'. This could also be done from the directory itself, using what is known as relative paths:

# cd /usr/home/bob
# mv song.ogg mymusic/

Similar to many file system commands it is possible to use wildcards as a parameter. For example:

# cd /usr/home/bob
# mv *.ogg  mymusic/

Which will move all files ending in '.ogg' into the 'mymusic' directory, whether there was one or more such sound files.

[edit] Renaming file(s)

The other use for the mv command is to rename files. This is because there is no 'rename' command as found on other operating systems (Microsoft's DOS, for example, uses the command 'ren' to rename files separate from the 'move' command to move files). The mv command will rename a file when only two filenames are provided, without a directory path, for example:

# cd /usr/home/bob
# mv song.ogg heavymetaltrack.ogg

This simply renames the file 'song.ogg' to 'heavymetaltrack.ogg'.

[edit] Command switches

-v verbose
-i prompt before overwriting existing files 
-n no-overwriting existing files -- cancels any previous -f switches
-f force -- cancels out any previous -i or -n switches
Personal tools