Sample Bash Codes to Increase Productivity with Command Line


Here is a collection of my bash commands in /home/username/.bash_aliases

Change Bash Aliases

alias edit-bash="sudo nano /home/username/.bash_aliases"

alias reload-bash="source /home/username/.bash_aliases"


# Edit preferences for nano
alias edit-nano="sudo nano /etc/nanorc"

Change to Dropbox User Session

alias dropbox-user="su -l dropbox -s /bin/bash"

SSH to Server

alias server="ssh username@ -p 22"

Files and Directories

# Sort by file size
alias lsize="ls --human-readable --size -1 -S --classify"
# Get File Size
alias get-size="du -hs / | sort -h"
# Copy File with Progress Bar
alias rsync="rsync -avzh --progress"
# Change directories and view contents
cl() {
# if no DIR given, go home
if [ $# -lt 1 ]; then
builtin cd "${DIR}" && ls -F --color=auto


# Show journalctl log for the specified program from 1 minute ago
j() { journalctl -u "$1" --since "1 minute ago"; }

# Same as above
journal() { journalctl -u "$1" --since "1 minute ago"; }


alias restart="systemctl restart"
alias status="systemctl status"
alias start="systemctl start"
alias stop="systemctl stop"

List Ports

alias lsports="sudo lsof -i -P -n | grep LISTEN"
alias ports="sudo netstat -plant"

alias open-ports="sudo nmap -sT -O localhost"
alias tcp-ports="sudo nmap -sT -O localhost"
alias udp-ports="sudo nmap -sU -O localhost"

Docker Compose

# Navigate to Docker Compose file location and then run below bash alias
alias restart-docker="sudo docker-compose down && docker-compose up -d"

Apt Package Manager

alias update="sudo apt-get update"
alias upgrade="sudo apt-get upgrade"
alias install='sudo apt-get install'
alias uninstall="sudo apt-get remove"

Pi-hole Update for Lighttpd

alias update-pihole="pihole -up && sudo sed -ie 's/= 80/= 8089/g' /etc/lighttpd/lighttpd.conf && /etc/init.d/lighttpd restart"

alias update-pihole="pihole -up && echo -e '\n\033[0;32mIf Pi-hole dashboard is not working, check /etc/lighttpd/lighttpd.conf to make sure server.port=8089 and then restart lighttpd by running \"/etc/init.d/lig
httpd restart\". Also include under AUTHORIZED_HOSTNAMES in /var/www/html/admin/scripts/pi-hole/php/auth.php \033[0m \n'"


alias edit-telegraf="sudo nano /etc/telegraf/telegraf.conf"
alias goto-telegraf="cd /etc/telegraf"
alias goto-telegrafd="cd /etc/telegraf/telegraf.d"


alias edit-nginx="sudo nano /etc/nginx/sites-enabled/reverse"
alias restart-nginx="sudo systemctl restart nginx"

Home Assistant

alias stop-hass="sudo systemctl stop home-assistant@homeassistant"
alias start-hass="sudo systemctl start home-assistant@homeassistant"
alias status-hass="sudo systemctl status home-assistant@homeassistant"
alias restart-hass="sudo systemctl restart home-assistant@homeassistant"
alias edit-hass="cd /home/homeassistant/.homeassistant && sudo nano /home/homeassistant/.homeassistant/configuration.yaml"

alias goto-hass="cd /home/homeassistant/.homeassistant"

alias goto-auto="cd /home/homeassistant/.homeassistant/automations && ls -la"


alias edit-frigate="sudo nano /opt/frigate/config.yml"

alias restart-frigate="cd /opt/frigate && sudo docker-compose down && sudo docker-compose up"


alias tr-restart='sudo /etc/init.d/transmission-daemon reload'
alias tr-stop='sudo /etc/init.d/transmission-daemon stop'
alias tr-start='sudo /etc/init.d/transmission-daemon start'

SAMBA smbd

alias edit-samba="sudo nano /etc/samba/smb.conf"
alias restart-samba="sudo systemctl restart smbd"


alias edit-cron='crontab -e'
alias edit-crontab='crontab -e'

Go to Directory

# List of shortcuts to frequent directories
alias downloads='cd /downloads'
alias movies='cd /movies'


# Update NFS export locations after making changes to /etc/exports
alias update-nfs='exportfs -arv'


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.