Skip to content

Instantly share code, notes, and snippets.

@jcastellanos926
Last active September 24, 2020 11:04
Show Gist options
  • Save jcastellanos926/55b78ba648b0a8250e95b045e5df7fd6 to your computer and use it in GitHub Desktop.
Save jcastellanos926/55b78ba648b0a8250e95b045e5df7fd6 to your computer and use it in GitHub Desktop.
Bash aliases

How to create .bash_aliases file

In order to keep ~/.bashrc file as clean as possible, we'll put our aliases into ~/.bash_aliases file. In some linux distributions, .bash_aliases file comes by default and it's already created. So first, let's check it out ~/.bashrc file and look for the following lines.

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
 
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

In case these lines aren't within the code, add them manually at the end of the file and execute source command to refresh the changes in our current session.

$ source ~/.bashrc

Now, let's create our ~/.bash_aliases file and add our bash aliases inside it.

$ touch ~/.bash_aliases
$ vi ~/.bash_aliases

I further recommend adding the following alias in order to update our aliases file.

# ea = Edit Aliases
alias ea='vi ~/.bash_aliases; source $HOME/.bash_aliases && echo "aliases sourced  --ok."'

These are some of the aliases I put into my .bash_aliases file:

# Edit aliases
alias ea='vi ~/.bash_aliases; source $HOME/.bash_aliases && echo "aliases sourced  --ok."'
 
alias work='cd ~/workspace'
alias m2='cd ~/workspace/magento2'
 
alias xclip="xclip -selection c"            # Put the content of the file on the clipboard
alias lstat='stat --format "%a  %U %G  %n"' # Shows file or directory permissions in numeric format

alias untar="tar -xvf"          # Unpack .tar files
alias untargz="tar -xzvf"       # Unpack .tar.gz files
alias untarbz2="tar -xjvf"      # Unpack .tar.gz2 files
alias untarxz="tar -xf"         # Unpack .tar.xz files
                                                            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment