Intro To 'mv' Command In Linux
2023-04-18 - By Robert Elder
I use the 'mv' command to move or rename files to rename a file or directory. I type 'mv' followed by the source file name followed by the new destination file name:
mv grocery-list.txt shopping-list.txt # 'grocery-list.txt' is now renamed to 'shopping-list.txt'
If you want to keep the same file name, but change the file's location instead, then you only need to specify the directory name in the destination:
mv todo-shopping.txt /home/robert/important/
ls /home/robert/important/ # The output should now include 'todo-shopping.txt'.
If you're not careful you could overwrite an existing file with the 'mv' command. That's why I use the '-n' flag to prevent this from happening:
cat grocery-list.txt # Shows my grocery list
cat important-notes.txt # Shows my important notes.
mv -n grocery-list.txt important-notes.txt
ls # Both files should still be present.
cat important-notes.txt # Shows that 'important-notes' was NOT overwritten by the grocery list.
And that's why the 'mv' command is my favourite Linux command.
![]() A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
![]() $20.00 CAD |
![]() A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
![]() The Most Confusing Grep Mistakes I've Ever Made
Published 2020-11-02 |
![]() Use The 'tail' Command To Monitor Everything
Published 2021-04-08 |
![]() Using A Piece Of Paper As A Display Terminal - ed Vs. vim
Published 2020-10-05 |
![]() An Introduction To Data Science On The Linux Command Line
Published 2019-10-16 |
![]() An Overview of How to Do Everything with Raspberry Pi Cameras
Published 2019-05-28 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|