My favorite bash aliases

October 25, 2017 · 5 mins read

I use bash in my terminal. I know that ZSH is now the fashionable shell, but bash is installed by default on Mac and Linux machines and it’s simple and basic. So it’s perfect for my use, and that’s what matters.

I always create aliases and helper functions for everything in bash. Here’s a list of some of my favorites.

Source code editor alias

I installed the alias of my source code editor. You’ll sometimes see sbl. It’s the alias for Sublime text. Feel free to replace this alias by the alias of your editor like atom for Atom or code for Visual Studio Code for example.


Useful alias for bash commands:

alias ls='ls -aGFh'
alias ll='ls -l'
alias rm='rm -i'
alias ne='emacs'


I always create aliases to access quickly and easily to my dev folders like:

alias dev='cd ~/dev'


I create aliases for accessing to system features like hosts, bash profile and git configuration.

alias profile='subl ~/.bash_profile'
alias resource='source ~/.bash_profile && echo "✅ Done"'
alias hosts='sudo sbl /etc/hosts'
alias gitconfig='subl ~/.gitconfig'

Because I’m on Mac, I created aliases to access easily to my iCloud Drive:

alias ic='cd ~/Library/Mobile\ Documents/com~apple~CloudDocs'
alias icd='cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/Documents'


Aliases for git commands:

alias g='git'
alias gi='git init'
alias gs='git status'
alias ga='git add -A .'
alias grh="git reset --hard"
alias gc='git commit -am'
alias push='git push'
alias gl='git log --oneline --decorate --color'
alias pull='git pull'
alias gd='git diff'
alias gb='git branch'
alias gf='git fetch'

Quick update

Ok, shame on me 🙈, but sometimes you want to quickly update your repo using git:

# Quick add, commit and push on origin branch with Git
function gq {
    git add .
    git commit -m "Quick update"
    git push origin master


Aliases to launch a PHP server:

alias serve='php -S index.php'
alias servep='php -S -t public public/index.php'


Aliases for Composer, the dependency manager for PHP:

alias cc='composer clear-cache'
alias cu='composer update'
alias ci='composer install'
alias cdo='composer dump-autoload -o'


Some useful aliases for Laravel framework:

alias art='php artisan'
alias log='tail -n0 -f storage/logs/laravel.log'


If you use Laravel Valet and you want to fast check your local websites:

alias vls='valet links'


Jekyll is my favorite tool for creating static website. That’s why I created aliases to build and serve my Jekyll websites:

alias jn='jekyll new'
alias jb='bundle exec jekyll build'
alias js='bundle exec jekyll serve'
alias jsd='bundle exec jekyll serve --drafts'
alias jbw='bundle exec jekyll build --watch'


Bash functions for you servers:

Update a server

If you want to update a server:

function update-server {
    echo -e '\033[1m\033[32mUpdating server...\033[0m'
    ssh -t [email protected] -p 1234 'sudo apt-get update; sudo apt-get upgrade; sudo apt autoremove';
    echo -e '\033[1m\033[32m✅ Done\n\033[0m'

Replace [email protected] -p 1234 by your server user, ip address and port.

Local MySql backup on iCloud Drive

Sometimes, I want to backup my local MySQL databases on iCloud Drive. I created a backup folder on iCoud Drive to put the saved databases inside. Then I launch this command:

function backup {
    folder="/Users/clement/Library/Mobile Documents/com~apple~CloudDocs/backups"
    filename="$(date +%Y%m%d)-backup"
    mysqldump -u root -p --all-databases --single-transaction > "$folder/$filename.sql"
    echo -e '\033[1m\033[32m✅ MySql backup done\n\033[0m'

Replace clement in the folder variable by your Mac username.

Quickly deploy a website using Git

You want to quickly deploy your website using git on your server? Try this:

function deploy {
  echo -e '\033[1m\033[36m\nDeploy your website\n\033[0m'
  ssh -t [email protected] -p 1234 'cd /var/www/website; git pull origin master;'
  echo -e '\033[1m\033[32m✅ Done\n\033[0m'

Replace [email protected] -p 1234 by your server user, ip address and port. Replace /var/www/website by your website path.

I hope you’ll find these bash aliases and functions useful, even if they are simple. But, you know, less is more 😉.

Clément Barbaza
Business owner, consultant, developer and project manager.

Like what I do ? Hire Appstraction and we can work together.