Aliases to make the mv and cp commands more user friendly (#snippet)

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="m…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

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!

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

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. ?


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2020-10-29T23:00:00+00:00) Aliases to make the mv and cp commands more user friendly (#snippet). Retrieved from https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/

MLA
" » Aliases to make the mv and cp commands more user friendly (#snippet)." Stefan Judis | Sciencx - Thursday October 29, 2020, https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/
HARVARD
Stefan Judis | Sciencx Thursday October 29, 2020 » Aliases to make the mv and cp commands more user friendly (#snippet)., viewed ,<https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/>
VANCOUVER
Stefan Judis | Sciencx - » Aliases to make the mv and cp commands more user friendly (#snippet). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/
CHICAGO
" » Aliases to make the mv and cp commands more user friendly (#snippet)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/
IEEE
" » Aliases to make the mv and cp commands more user friendly (#snippet)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/. [Accessed: ]
rf:citation
» Aliases to make the mv and cp commands more user friendly (#snippet) | Stefan Judis | Sciencx | https://www.scien.cx/2020/10/29/aliases-to-make-the-mv-and-cp-commands-more-user-friendly-snippet/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.