DEV Community

Javier Alvarado
Javier Alvarado

Posted on

More intuitive shell commands

Recently I experimented with an idea to create natural language shell commands. Some of the shell commands can be unintuitive and a little hard to remember, so I decided to use aliases to make them easier to remember.

I'm on macOS, so I'm using zsh for my shell. However, the snippet below should work in bash as well (you would have to add the snippet to your ~/.bashrc or ~/.bash_profile file instead).

I added the following code snippet to my ~/.zshrc file.

alias help='man'
alias show='less -S'
alias view='less -S'
alias create='touch'
alias copy='cp -iv'
alias move='mv -iv'
alias rename='mv -iv'
alias delete='rm -iv'
Enter fullscreen mode Exit fullscreen mode

After adding these aliases and opening a new terminal tab or window, I was able to start using them. Here are some examples of commands you can use:

show index.html
create index.html
copy index.html about.html
move index.html folder-name
rename folder-name other-folder-name
delete index.html
Enter fullscreen mode Exit fullscreen mode

Goals

I had 2 goals in mind while creating these aliases. The first was to make the command names a little more intuitive, without making them too long. The other goal was to add in options that would make the commands a little more user-friendly. For example, the -i option makes the copy, move, rename, and delete commands interactive to prevent users from accidentally overwriting or deleting files.

Notes

I noticed a couple of things while making these aliases. The first is that a couple of commands have 2 aliases. For example, I wasn't sure whether show or view would be a better alias for the less command, so I added both. The mv command is used to move and rename files, so I created 2 aliases to correspond with these 2 actions.

I also realized the help command doesn't work with these aliases (so something like help show doesn't work, for example). The one exception is help help, which does bring up the man page for the man command.

Learn more about the shell

If you want to learn more about using the terminal and shell, you can visit my website Simple Dev. You can learn about the shell, Git, and web technologies like HTML and CSS.

Top comments (0)