What are your favourite aliases?

JasKinasis

Super Moderator
Staff member
Gold Supporter
Joined
Apr 25, 2017
Messages
1,861
Reaction score
2,719
Credits
16,092
The idea of this thread is to post your favourite aliases from your .bashrc.

Section 1 - What is an alias?
If you already know what an alias is, feel free to skip this section and check out section 2 containing my aliases, or just go ahead and post some of your favourite aliases.

But if you don't know what aliases are, I will explain. Please read on.....

Aliases allow you to create convenient shortcuts for common commands - to save you some typing, and/or to prevent you having to remember a lot of different commands/switches etc.

So if there are any really long commands that you use often. Instead of having to type the whole command, you can open up your .bashrc file and set up an alias instead. Or if it is just something you will be using in the current terminal session, you can just set up a temporary alias using the built-in alias command.

Whether you set a temporary alias for the current terminal session, or set a permanent one in your .bashrc file. The syntax to set up an alias is:
Code:
alias alias_name='/your/commands/and -options -go -here'

As a practical example:
ls
is a command that everybody uses in the terminal and there are lots of different options/switches that can be passed to ls that will allow you to see files listed in different ways. If you always want the output to appear in a certain way, you can set your preferences by setting up an alias for ls.

So if you always want ls to show all files, in the long-list format, with indicators at the end of file-names ( e.g. / for directories, * for executables), with human-readable file-sizes and you always want to see directories listed first; Then you could set the following alias:
Code:
alias ls='ls -alFh --group-directories-first'

Now whenever you type ls, the alias will be invoked and you will see the output in your desired format.
To invoke the original ls without using your alias, you can bypass the alias by typing:
Code:
\ls
That will ignore any aliases for ls and will directly run the ls command in /usr/bin/ instead.

Alternatively, if an alias is no longer required you can use the unalias command to remove it from the current terminal session, or you could remove it from your .bashrc file if it is a permanent one.
The syntax for the unalias command is:
Code:
unalias name_of_alias_to_remove



Section 2 - My favourite aliases:
OK, now you know what aliases are - here are a few of my favourites:


Re-read/Re-apply .bashrc
This is something I use a lot. Whenever I make changes to my .bashrc, I often want to apply them to any terminals I have open. So I have set-up the following alias:
Code:
alias reinit='. ~/.bashrc'
After making changes to my .bashrc, I can use the reinit alias to quickly apply the changes to the current terminal.


Remove backup files
As a vim user, I find that I often end up accumulating a lot of backup files. So I have set up a couple of aliases which I periodically use to remove unwanted backup files.
Code:
alias rmb='find ./ -type f -iname "*~" -delete &'
alias rmib='find ./ -type f -iname "*~" -exec rm -i {} \;'

rmb will recursively find and delete all files with names that end with the ~ character. Because of the & at the end of the command, find is ran in the background. That way I can continue working in the terminal while the find command finds and removes backup files.

rmib will recursively find all files with names that end with the ~ character and will interactively ask whether to remove each file it finds. Because this is an interactive command, I don't run it in the background.


Listen to internet radio-stations in the terminal
From looking at my avatar-pic, or reading my profile here you've probably guessed that I'm quite heavily into music.... And heavy music at that.

When working in the terminal I like to be able to listen to a bit of music. And I don't always want to interrupt my flow by firing up a GUI media player. So I've set up aliases for two of my favourite internet radio stations - Hard Rock Hell Radio and Neue Regel Radio:
Code:
alias HRH='cvlc http://andromeda.shoutca.st:9254 &> /dev/null &'
alias NRR='cvlc http://65.60.19.43:8600 &> /dev/null &'
With these aliases in place, I can listen to my favourite stations by issuing the HRH or NRR command in the terminal.

On execution of one of these aliases:
cvlc is started in the background and starts streaming the station I want to listen to.

All text output (error messages etc) is redirected to /dev/null using the &> redirection operator - so the running process never interrupts what I am doing.

When I'm finished listening, I use the jobs command to get the PID for vlc:
Code:
jobs -l

And then I use the kill command to kill it:
Code:
kill -15 {PID}
Note: the use of signal 15 (SIGTERM), which politely asks the process to end, rather than signal 9 (SIGKILL) - which will forcefully kill the process. See here for more info...

At some point, I'll probably get around to setting up an alias for that too! :)

Anywhoo, those are a few of my favourite aliases. What are yours?
 
Last edited:


As of late...
Code:
alias chrome.exe='sl'

So every time you try to fire up chrome, you get a steam locomotive scrolling across the screen? XD

sl.png
 
Since making my original post about aliases, I've solved my command-line media player woes.

Instead of firing off cvlc in my audio-related aliases (and then having to manually kill vlc in the terminal when finished listening) - I've started using cmus - which is actually a really good terminal based media player, which supports internet radio playback. Really lightweight and has a lot of functionality.

Whenever I'm using my PC, I usually have a few tmux* sessions open in various terminals - one for general stuff and others set up for specific projects/tasks.

In the script to set up my main, 'general' tmux session - I've added an extra pane running cmus. So whenever I start my primary tmux session, cmus is automatically ran in its own pane.

To facilitate playback and playlist management from ANY running terminal, I've set up some handy aliases for several cmus-remote commands.
e.g.
Code:
alias stop='cmus-remote -s'
alias play='cmus-remote -p;cmstat'
etc...
There are several others, but you get the idea.
cmstat is a script I wrote in my personal bin/ directory, which uses cmus-remote to get information about the currently playing track and then displays artist/track name information in the terminal.

I've also added some keybinds to dwm** which bind the {fn} + {media keys} to various cmus-remote commands. Allowing me to control playback when I don't have a terminal in focus - e.g. when viewing a GUI application in another tag***!

========================================================================
NOTES:
* - tmux is a terminal multiplexer, similar to GNU Screen - allowing you to control multiple terminal sessions from within a single terminal.
** - dwm is a simple tiling window manager written in C.
*** - Tags in dwm are a similar concept to workspaces/virtual desktops - but are not exactly the same.
========================================================================

Another handy alias I've added since my initial post:
Code:
alias bashr='vim ~/.bashrc;. ~/.bashrc'

Which allows me to quickly edit my .bashrc file and immediately apply the changes to the current terminal.

I've set up similar aliases to allow quick edits of configs for other applications like vim, tmux, conky etc etc...

Basically, I'm a lazy git. I'll do anything to make my life that little bit easier. Even if it only saves me from typing one or two extra characters in the terminal.... Scripts, cron-jobs, aliases, keybinds - whatever it takes - nothing is beneath me! XD
 
I don't have "favorite" aliases. When I wanna save the time of typing a long command, I create an alias but that's it - no favorites. The goal is to have the shortest alias for the longest command. For instance, for creating a backup of the browser's user data folder, I use just 2 characters alias.
I just shared my list in another topic but I think it wouldn't hurt to share it here as well. :)
 

Attachments

  • my-aliases.txt
    11.4 KB · Views: 371
One of the mods was going to merge threads, but hasn't so I will post here.
Code:
# Start gomuks Matrix Client
alias gomuks=/home/pi/Downloads/gomuks-linux-arm64

# Show open ports
alias ports='netstat -tulanp'

# Refresh .bashrc
alias bashrc="nano ~/.bashrc && source ~/.bashrc"

# become root #
alias root='sudo -i'
alias su='sudo -i'

# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; then
alias update='sudo apt update'
alias ainstall='sudo apt install'
alias apurge='sudo apt purge -y --autoremove'
alias upgrade='sudo apt full-upgrade'
alias aremove='sudo apt autoremove -y'
alias reboot='sudo reboot'
alias shutdown="sudo shutdown -P now"
fi

# APT User Commands
alias asearch='apt search'
alias afile='apt-file search'
alias apolicy='apt policy'
alias show="apt show"

# Create Python virtual environment
alias ve='python3 -m venv ./venv'
alias va='source ./venv/bin/activate'

# Ping Commands
# Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
alias pg="ping google.com -c 5"

# alias shotrcuts
alias raspi="sudo raspi-config"
alias clr="clear"
alias clrh="history -c -w ~/.bash_history"
alias df='df -H'
alias du='du -ch'

# ls Commands
## Colorize the ls output and human readable sizes ##
alias ls='ls --color=auto --human-readable -al' 

## Use a long listing format ##
alias ll='ls -la'

## Show hidden files ##
alias l.='ls -d .* --color=auto'

# Clipboard
alias cpy="xclip -selection clipboard"

# Calculator
alias bc="bc -l"

# Resume wget by default
alias wget="wget -c"

# ps Commands
alias ps="ps auxf"
# Get top process eating cpu
alias pscpu="ps auxf | sort -nr -k 3"
alias pscpu10="ps auxf | sort -nr -k 3 | head -10"

# Get top process eating memory
alias psmem="ps auxf | sort -nr -k 4"
alias psmem10="ps auxf | sort -nr -k 4 | head -10"

# Free and Used Ram
alias meminfo="free -m -l -t"
alias free="free -mt"
 
One of the mods was going to merge threads, but hasn't so I will post here.

I hadn't forgotten, but the site software had a bellyache. I can move Posts that are subsequent to #1 of a Thread with ease, but it stuck on yours as being the Original Poster of the Thread.

I should have updated you, my bad.

Wiz
 
Do you ever get annoyed annoyed with all of the output from the top command being left on-screen in the terminal after you've quit it?

If so, this alias allows you to run top in an "alternate" screen in the terminal. And then switches back to the original screen afterwards:
Bash:
alias top='tput smcup; top; tput rmcup'
So when you quit top - you don't see any of its output left on the screen.
 

Members online


Latest posts

Top