Summary Linux command list
A command for moving files and directories. "mv" is an abbreviation for "move".
/home/hoge
$mv move source move destination
option | Description |
---|---|
-b | Back up files that will be overwritten or deleted |
-f | Overwrite without confirmation |
-i | Confirm in case of overwriting |
-n | Do not move if there is a file or directory with the same name in the move destination |
-u | Overwrite only if the move source is newer |
-v | View detailed information about the move |
The mv command basically overwrites, so if you add the -b option, it will back up the overwritten file.
Behavior when there is no option
/home/hoge/test
$ ls
test.txt ex.txt test.log
$ mv test.txt ex.txt
$ ex.txt test.log
Behavior when the -b option is attached
/home/hoge/test
$ ls
test.txt ex.txt test.log
$ mv -b test.txt ex.txt
$ ex.txt~ ex.txt test.log
Backup files have "~" after the file name.
It displays detailed information about the move. It is often used for checking when multiple files are moved.
/home/hoge/test
$ ls
test.txt ex.txt test.log
$ mv -v test.txt ex.txt test.log test2
`test.txt' -> `test2/test.txt'
`ex.txt' -> `test2/ex.txt'
`test.log' -> `test2/test.log'
$ ls
$ cd ../test2
$ ls
test.txt ex.txt test.log
mv command test.txt in the test directory You can navigate to it in the test2 directory with the name test2.txt.
/home/hoge/test2
$ ls
$ cd ../test
$ mv test.txt test2/test2.txt
$ cd ../test2
$ ls
test2.txt
Of course, it can be used as rename even in the same directory.
Why it can be used as a rename And why can the mv command move in an instant even with a large capacity of 1G? These two are actually interesting to look at the source of the mv command, so I will write them in another article.
pwd, mkdir, cd , cat, cp, ls, touch, less, mv, rm, ssh, man, ** Adding at any time **
We undertake various development and construction contracts and mentor work for beginners. If you are interested, please go to ** here **
Recommended Posts