Published at
Updated at
Reading time

I added new aliases to my dotfiles after watching this video by "Tom on the internet".

Tom explains the -iv options of mv and cp, which led me to add these two aliases:

alias mv="mv -iv"
alias cp="cp -iv"

The one thing that confused me when I started using the terminal and shell environments was that most commands, by default, don't give much information on what's happening. And there is a reason behind this; if you're automating things and write shell scripts, you don't want to see hundreds of logs in your terminal. I don't write complex scripts, though. I use the terminal to start commands, create files, and move them around. That's it and is why I appreciated more information in my terminal.

Additionally, these commands take your instructions very seriously. ๐Ÿ™ˆ If you're moving, copy or rename a file to a target that already exists, it overwrites it. No questions asked. This behavior can lead to unintended file loss.

I added the above aliases to make the mv and cp command more user friendly, and I love it!

A verbose and safer mv

To move files, you usually use the mv command. I learned that it supports two flags that make it easier to use. Applying the -iv options to mv makes the command more verbose. It will also tell you and double-check if you want to overwrite another file.

# log more information to the terminal
mv one.txt two.txt                                                         
three.txt -> one.txt

# ask before overwriting a file
mv two.txt three.txt
overwrite three.txt? (y/n [n]) n
not overwritten

A verbose and safer cp

The same options apply to the cp command to copy files.

# log more information to the terminal
cp one.txt two.txt
one.txt -> two.txt

# ask before overwriting a file
cp two.txt three.txt                                                         
overwrite three.txt? (y/n [n]) n
not overwritten

I know that it can be dangerous to get used to these more verbose and safer commands. If you're in a remote shell, you might overwrite files because you are used to the safety net. That's your decision to make, and if you want to, you can choose different aliases.

In my case, I rarely deal with remote servers, so that's okay for me. ๐Ÿ™ˆ

Was this snippet helpful?
Yes? Cool! You might want to check out Web Weekly for more snippets. The last edition went out 14 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles