mv - move and rename files and directories
mv command examples
mv command is a basic Unix command for moving and renaming files and directories.
As you can see on the screenshot above, mv command can be used to move files from one directory to another, or to simply rename places.
Naturally, both moving and renaming can be done at the same time - mv
will figure out what’s required to ensure a file with one path becomes relocated into file with another path.
Let’s first setup a few test files (named try1
, try2
and try3
in this example):
… and a few test directories (named dir1
and dir2
):
Moving files from one directory to another
Now let’s try moving some files. First command moves try1
file into dir2
.
Second command moves try2
into dir1
.
Renaming files with mv
Now let’s rename try3
into try33
:
Moving AND renaming file with mv
Let’s now move try2
file back from dir1
subdirectory into current directory, but also rename it into newtry2
at the same time.
As you can see, there’s nothing left in dir1
subdirectory, because mv
moved the file from it, and new file is called newtry2
now.
See Also
mv command examples
mv command is a basic Unix command for moving and renaming files and directories.
As you can see on the screenshot above, mv command can be used to move files from one directory to another, or to simply rename places.
Naturally, both moving and renaming can be done at the same time - mv
will figure out what’s required to ensure a file with one path becomes relocated into file with another path.
Let’s first setup a few test files (named try1
, try2
and try3
in this example):
… and a few test directories (named dir1
and dir2
):
Moving files from one directory to another
Now let’s try moving some files. First command moves try1
file into dir2
.
Second command moves try2
into dir1
.
Renaming files with mv
Now let’s rename try3
into try33
:
Moving AND renaming file with mv
Let’s now move try2
file back from dir1
subdirectory into current directory, but also rename it into newtry2
at the same time.
As you can see, there’s nothing left in dir1
subdirectory, because mv
moved the file from it, and new file is called newtry2
now.