Babak K. Shandiz
Babak K. Shandiz's Blog

Babak K. Shandiz's Blog

Living in the Shell #12; mv (Move/Rename Files/Directories)

Living in the Shell #12; mv (Move/Rename Files/Directories)

Babak K. Shandiz's photo
Babak K. Shandiz
·Dec 11, 2021·

1 min read

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 under Documents/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 to target-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
 
Share this