The mv
command in Linux, which stands for “transfer,” is likely one of the maximum continuously used instructions throughout the Linux surroundings.
The essential use of the mv
command comes to relocating information and directories from one location to any other throughout the gadget’s construction.
An extra noteworthy characteristic of the mv
command is its talent to rename information and directories. Necessarily, while you ‘transfer’ a record to another filename inside the similar listing, you’re successfully renaming it.
Listed below are many ways to make use of the mv
command:
1. Transfer a Report
The fundamental syntax for shifting a record is mv supply vacation spot
.
Instance:
To transport a record named record.txt
from the present listing to any other listing, you could possibly use:
mv record.txt /trail/to/listing/
2. Rename a Report
You’ll rename a record via shifting it to a brand new identify in the similar listing.
Instance:
To rename a record named record.txt
to newfile.txt
, you could possibly use:
mv record.txt newfile.txt
3. Transfer A couple of Information
You’ll transfer more than one information directly via specifying more than one supply information.
Instance:
To transport file1.txt
, file2.txt
, and file3.txt
to a listing, you could possibly use:
mv file1.txt file2.txt file3.txt /trail/to/listing/
4. Transfer Directories
You’ll transfer directories in the similar approach as information.
Instance:
To transport a listing named dir
to any other listing, you could possibly use:
mv dir /trail/to/listing/
5. Rename Directories
You’ll rename directories in the similar approach as information.
Instance:
To rename a listing named dir
to newdir
, you could possibly use:
mv dir newdir
6. Interactive Mode
If you wish to be brought about sooner than overwriting information, you’ll be able to use the -i
(or --interactive
) possibility.
Instance:
mv -i record.txt /trail/to/listing/
7. Do No longer Overwrite Current Information
If you do not need to overwrite current information within the vacation spot, you’ll be able to use the -n
(or --no-clobber
) possibility.
Instance:
mv -n record.txt /trail/to/listing/
Renaming information in Linux: mv
vs. rename
Each mv
and rename
let you rename information, however they function in several techniques and feature other makes use of.
mv
mv
is basically used to transport information and directories from one position to any other, however it may also be used to rename information and directories. It’s simple and simple to make use of. You merely kind mv
, the present identify of the record, after which the brand new identify you wish to have the record to have.
Instance:
mv oldname.txt newname.txt
On the other hand, if you want to rename more than one information or wish to use patterns for renaming, mv
will also be relatively restricted and won’t meet your wishes and that is the place rename
is available in.
rename
rename
is extra subtle Linux command and is designed in particular for renaming information. It’s tough as a result of it could possibly use Perl common expressions to rename information in bulk.
Instance:
If you wish to rename all .txt information to .bak information in a listing, it’s essential to achieve this with one rename
command:
rename 's/.txt$/.bak/' *.txt
This command replaces the .txt extension with .bak for all textual content information within the present listing.
In conclusion, mv
is modest and helpful for renaming unmarried information or shifting information from one position to any other, whilst rename
is extra tough and higher for renaming more than one information directly, particularly when patterns or common expressions are concerned.
The publish How you can Use mv in Linux seemed first on Hongkiat.
WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-mv/