I discovered the aliases function of bash scripting a few years ago and have been in love ever since. I believe it was aliases that helped me to see a real possibility for me to use and learn more bash scripting. I would like to share some of my .bash_aliases file and the functions within that I use regularly to maximize my time in the terminal.
Disclaimer: With respect to any function listed below which downloads data, it is your responsibility to stay withing the law of your local government. I do not take any responsibility for any law breaking actions which you may unwittingly commit as a subsequent result of this knowledge.
Downloads
alias ytmp3="yt-dlp –no-check-certificate -f140 -x –audio-format mp3 -o ‘%(title)s.%(ext)s’"
alias ytvid="yt-dlp –no-check-certificate -f mp4 -o ‘%(title)s.%(ext)s’"
alias getpdfs=’wget -r -nd –limit-rate=1m -A.pdf’
alias getmp3s=’wget -r -nd –limit-rate=1m -A.mp3′
alias getpics=’wget -r -nd -m -e robots=off –random-wait –continue –no-check-certificate –limit-rate=1m -A.jpg’
alias getweb=’httrack’
ytmp3
leveragesyt-dlp
to download the audio only from videos on Youtube into MP3 format. The script also names the file with the title of the video. Note that yt-dlp can also download entire playlists, which makes shorter work of procuring collections.ytvid
leveragesyt-dlp
to download the videos from Youtube into mp4 format. The script also names the file with the title of the video. Note that yt-dlp can also download entire playlists, which makes shorter work of procuring collections.getpdfs
leverageswget
with a server respecting rate limit to download PDFs recursively from a given URL.getmp3s
leverageswget
with a server respecting rate limit to download MP3s recursively from a given URL.getpics
leverageswget
with a server respecting rate limit to download JPGs recursively from a given URL.getweb
leverages ‘httrack’ to download entire website for offline use.
File Utils
alias rss-sub=’nano ~/.newsboat/urls’
alias aliases=’less ~/.bash_aliases’
alias filemap=’less ~/path/to/0-9.general/file.decimal.md’
alias deluge-clear=’rm ~/.config/deluge/cmd_line.hist1; touch ~/.config/deluge/cmdline.hist1′
alias renameall="rename y’/A-Z/a-z/’ ; rename y’/ /./’ ; rename y’/\/./’ *"
alias update-bash=’wget http://ipaddress/homeweb/configs/bash_aliases && mv bash_aliases .bash_aliases && source ~/.bashrc’
rss-sub
gives me quick access to the list of RSS feeds I subscribe to usingnewsboat
.aliases
gives me quick read-only access to my current .bash_aliases file.deluge-clear
deletes the cache of thedeluge
torrent client by removing and recreating its history file.renameall
is an alias I use nearly every single day. This alias leverages therename
command to rename files in a given directory to a format of my preference. This si great for downloaded files which have spaces within their names.update-bash
came into existance as I found my self wanting to transfer my .bash_aliases file to new machines as I build them. Since my machines havewget
I am able to leveragewget
to grab the file from the web server for the first go around. There after I can use this alias to employ my latest version. What is not shown here is the cron job that runs from my primary machine every few hours and sends my .bash_aliases file to the web server.
Directories
alias 0=’cd ~/path/to/0-9.general’
alias 10=’cd ~/path/to/10-19.computer’
alias 20=’cd ~/path/to/20-29.documents’
alias 28=’cd ~/path/to/20-29.documents/28.personal’
alias 30=’cd ~/path/to/30-39.finance’
alias 40=’cd ~/path/to/40-49.research’
alias 50=’cd ~/path/to/50-59.hobbies’
alias 60=’cd ~/path/to/60-69.personal’
alias 70=’cd ~/path/to/70-79.media’
alias 80=’cd ~/path/to/80-89.development’
alias 90=’cd ~/path/to/90-99.writing’
- These are a sample of the aliases in which I have used the
cd
command to get into directories quickly from within a terminal session. As you can see I am loosely using the johnny decimal system to organize my files.
Remote Systems
alias plex=’ssh USERNAME@IPADDRESS’
- This is a sample of the format I use to connect to remote systems via SSH. I use aliases for this task in conjunction with ssh keys for effortless connection to my servers.
Remote directories
alias remotes=’sshfs USERNAME@IPADDRESS:/path/to/remote/files/ /path/to/local/folder; alias remotes=’sshfs USERNAME@IPADDRESS:/path/to/remote/files/ /path/to/local/folder;’
- The
remotes
alias allows quick mapping of several local directories to remote directories on the fly. I have since leveraged ssh keys and a variation of this script in a cron job to run at boot.
Applications
alias web=’lynx –accept_all_cookies https://duckduckgo.com‘
alias weather=’curl wttr.in/ZIPCODE’
alias rss=’newsboat -C ~/.newsboat/newsboat_config’
alias xlm=’curl rate.sx/xlm’
alias btc=’curl rate.sx/btc’
alias ada=’curl rate.sx/ada’
alias mhc=’lynx ~/path/to/mhc/MHC00000.HTM’
alias dict=’dict -d gcide’
alias ls=’ls –color=auto’
alias delugestart=’deluged && sleep 60 && deluge-console’
web
launches thelynx
terminal based browser and navigates to duckduckgo.com while accepting all cookies in the session.weather
provides the weather for my zip code.rss
launchesnewsboat
with all of my rss feeds.xlm
,btc', and
ada` provide a snapshot in time of crypto prices on these currencies.mhc
launches the complete Matthew Henry bible commentary within the lynx browser.dict
follwed by a word searches and displays the definition of that word from the dict dictionary server.ls
simply shadows the ls command with a preference.delugestart
launches the deluged daemon and then the console 60 seconds later. I added the 60 second sleep time because the console was not able to see the daemon prior.
System Maintenance
alias aptup=’sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y’
alias aptupd=’sudo apt update’
alias aptupg=’sudo apt upgrade’
alias aptin=’sudo apt install’
alias aptrm=’sudo apt rm’
alias aptauto=’sudo apt autoremove’
alias cacheclear=’cd ~/.cache/thumbnails && rm -r *’
alias clearlogs=’sudo journalctl –rotate && sudo journalctl –vacuum-time=2d’
aptup
, updates theapt
cache list, upgrades currently installed packages, and autoremoves packages no longer in use. I found that I was running these three commands in succession often, so this just made logical sense.aptupd
simply updates theapt
cache list.aptupg
upgrades existing packages with the current cache list.aptin
followed by a package name will install the package.aptrm
followed by a package name will remove the package.aptrm
automatically removes unused packages.cacheclear
clears the cache folder of thumbnails.clearlogs
clears thejournalctl
logs which can grow to take up valuable system space. I use this on my server .bash_aliases files as well.
Utilities
alias vpnip=’curl ifconfig.co/city && curl ip.me’
alias search=’sudo apt-cache search’
alias listapps=’for app in /usr/share/applications/*.desktop do echo "${app:24:-8}" done | less’
alias work=’nano -c’
alias changelog=’work ~/path/to/change.log’
vpnip
will show me my current WAN IP address at any given time. This can help me ensure I am connected to a VPN.search
will search through the apt-cache list for a package name. I could elaborate on this with a varible and grep in the futre.listapps
will generate a list of every package installed on my computer.work
launchesnano
with the line count option.changelog
is simply a Markdown file in which I track the changes I have made to my network.
Games
alias gameroom=’ssh gameroom@bitreich.org’
alias tron=’ssh sshtron.zachlatta.com’
gameroom
connects to a collection of terminal based games.tron
connects to an online tron lightcycle game in the terminal.
Caesar Ciphers Encode
The following two sections are simply Caesar ciphers using tr
. This makes short work of encoding a line of text or a file. The Caesar Cipher is not a secure method of encoding. However, it is super fun to use.
alias rot2="tr ‘c-za-bC-ZA-B’ ‘a-zA-Z’"
alias rot3="tr ‘d-za-cD-ZA-C’ ‘a-zA-Z’"
alias rot4="tr ‘e-za-dE-ZA-D’ ‘a-zA-Z’"
alias rot5="tr ‘f-za-eF-ZA-E’ ‘a-zA-Z’"
alias rot6="tr ‘g-za-fG-ZA-F’ ‘a-zA-Z’"
alias rot7="tr ‘h-za-gH-ZA-G’ ‘a-zA-Z’"
alias rot8="tr ‘i-za-hI-ZA-H’ ‘a-zA-Z’"
alias rot9="tr ‘j-za-iJ-ZA-I’ ‘a-zA-Z’"
alias rot10="tr ‘k-za-jK-ZA-J’ ‘a-zA-Z’"
alias rot11="tr ‘l-za-kL-ZA-K’ ‘a-zA-Z’"
alias rot12="tr ‘m-za-lM-ZA-L’ ‘a-zA-Z’"
alias rot13="tr ‘n-za-mN-ZA-M’ ‘a-zA-Z’"
alias rot14="tr ‘o-za-nO-ZA-N’ ‘a-zA-Z’"
alias rot15="tr ‘p-za-oP-ZA-O’ ‘a-zA-Z’"
alias rot16="tr ‘q-za-pQ-ZA-P’ ‘a-zA-Z’"
alias rot17="tr ‘r-za-qR-ZA-Q’ ‘a-zA-Z’"
alias rot18="tr ‘s-za-rS-ZA-R’ ‘a-zA-Z’"
alias rot19="tr ‘t-za-sT-ZA-S’ ‘a-zA-Z’"
alias rot20="tr ‘u-za-tU-ZA-T’ ‘a-zA-Z’"
alias rot21="tr ‘v-za-uV-ZA-U’ ‘a-zA-Z’"
alias rot22="tr ‘w-za-vW-ZA-V’ ‘a-zA-Z’"
alias rot23="tr ‘x-za-wX-ZA-W’ ‘a-zA-Z’"
alias rot24="tr ‘y-za-xY-ZA-X’ ‘a-zA-Z’"
alias rot25="tr ‘z-za-yZ-ZA-Y’ ‘a-zA-Z’"
Caesar Ciphers Decode
alias unrot2="tr ‘a-zA-Z‘ ‘c-za-bC-ZA-B’"
alias unrot3="tr ‘a-zA-Z’ ‘d-za-cD-ZA-C’"
alias unrot4="tr ‘a-zA-Z’ ‘e-za-dE-ZA-D’"
alias unrot5="tr ‘a-zA-Z’ ‘f-za-eF-ZA-E’"
alias unrot6="tr ‘a-zA-Z’ ‘g-za-fG-ZA-F’"
alias unrot7="tr ‘a-zA-Z’ ‘h-za-gH-ZA-G’"
alias unrot8="tr ‘a-zA-Z’ ‘i-za-hI-ZA-H’"
alias unrot9="tr ‘a-zA-Z’ ‘j-za-iJ-ZA-I’"
alias unrot10="tr ‘a-zA-Z‘ ‘k-za-jK-ZA-J‘"
alias unrot11="tr ‘a-zA-Z’ ‘l-za-kL-ZA-K’"
alias unrot12="tr ‘a-zA-Z’ ‘m-za-lM-ZA-L’"
alias unrot13="tr ‘a-zA-Z’ ‘n-za-mN-ZA-M’"
alias unrot14="tr ‘a-zA-Z’ ‘o-za-nO-ZA-N’"
alias unrot15="tr ‘a-zA-Z’ ‘p-za-oP-ZA-O’"
alias unrot16="tr ‘a-zA-Z’ ‘q-za-pQ-ZA-P’"
alias unrot17="tr ‘a-zA-Z’ ‘r-za-qR-ZA-Q’"
alias unrot18="tr ‘a-zA-Z’ ‘s-za-rS-ZA-R’"
alias unrot19="tr ‘a-zA-Z’ ‘t-za-sT-ZA-S’"
alias unrot20="tr ‘a-zA-Z’ ‘u-za-tU-ZA-T’"
alias unrot21="tr ‘a-zA-Z’ ‘v-za-uV-ZA-U’"
alias unrot22="tr ‘a-zA-Z’ ‘w-za-vW-ZA-V’"
alias unrot23="tr ‘a-zA-Z’ ‘x-za-wX-ZA-W’"
alias unrot24="tr ‘a-zA-Z’ ‘y-za-xY-ZA-X’"
alias unrot25="tr ‘a-zA-Z’ ‘z-za-yZ-ZA-Y’"
That’s all folks!