Living in the Shell #12; mv (Move/Rename Files/Directories)
Babak K. Shandiz
Posted on December 11, 2021
mv
š§³
Moves/renames files or directories.
ā ļø Default behavior is to overwrite destination files.
Rename a single file
cd ~ && mv .bashrc .bashrc-renamed
Move a single file into a directory
cd ~ && mv .bashrc Documents
Note that the
Documents
directory should exist.
Move a single file onto a specific new path (filename)
cd ~ && mv .bashrc Documents/.bashrc-moved
Move a whole directory
mv my-src-dir ~/Documents/my-dest-dir
ā ļø Note that if
my-dest-dir
already exists,my-new-src
will be moved under it; i.e., you would have your files underDocuments/my-dest-dir/my-src-dir
Create backup for existing destination files -b
cd ~ && mv -b .bashrc Documents/.bashrc-moved
Move by wildcard selection -t
cd ~ && mv -t target-dir *.zip *.txt
Moves all
.zip
and.txt
files totarget-dir
directory.
Set to ask for overwriting -i
cd ~ && mv -i .bashrc Documents
Set to keep existing files (no overwrite) -n
cd ~ && mv -n .bashrc Documents
š šŖ š
š©
Babak K. Shandiz
Posted on December 11, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.