This guide & cheatsheet – using simple memorable commands, not complex syntax – will make you not only faster at the Linux shell, but enjoy it too.
Copying over my old bashrc file to a new install (it lives in your /home/username folder) is the first thing I do because it speeds up and simplifies everything else .. especially for someone with a memory as bad as mine. So what is bashrc?
Here’s the thing: such is Linux, to make the most of it, we use the terminal a whole lot. Not that you have to – you can get away without, but that’s like drinking non-alcoholic beer. Hic.
To make the command line experience way faster, less dour, more powerful, even fun, we edit the bashrc file.
.. and prompted, give the password you created at the Ubuntu installation stage, if any.
Scroll to the bottom of the file and paste whatever you fancy from below, modifying the aliases to suit you. I’ve made comments beside the “###heading” for each section to clue you in:-
###My Most Basic Aliases .. these ones are useful to everyone
alias ebrc="nano ~/.bashrc"
alias ebrcupdate="source ~/.bashrc"
#open software repositories
alias repos="gksudo gedit /etc/apt/sources.list"
#update software source index
alias update="sudo aptitude update"
#Ubuntu version detail
alias ver="cat /etc/lsb-release"
#safe upgrade Linux OS
alias upgrade="sudo aptitude safe-upgrade"
#full upgrade Linux OS
alias fupgrade="sudo aptitude full-upgrade"
alias install="sudo aptitude install"
alias remove="sudo aptitude remove"
#RAM and SWAP detail in MBs
alias free="free -m"
#detail list of current dir
alias ll="ls -lha"
###Local Web Server .. just to give you an idea of the power of bashrc (3 commands in 1 here)
alias n2r="sudo /etc/init.d/nginx stop && sleep 2 && sudo /etc/init.d/nginx start"
###Network .. this example executes a script
#mount dirs from a file server (called PETE) as selected in $Pete/etc/exports (an sh file), to /mnt/PETE/xxx
###Wiki .. this one backs up a local db
alias someDBdump="sudo mysqldump someDB -uroot -p > /home/username/www/_dbs/someDB.sql"
###Remote Hosts .. these play with a remote server
#access some remote host
alias remote="ssh -p 1234 188.8.131.52"
#access some folder
alias uploads="cd /some/folder"
#copy remote db to local
alias dbdumpcp="scp -P 1234 email@example.com:/home/username/Backup/www/data/someSite/db.sql /home/username/Backup/data/db.sql"
###SOCKS proxy .. these anonomise my browsing with a single word
alias proxy1="ssh -p 1234 -D 5678 firstname.lastname@example.org"
alias proxy2="ssh -p 8765 -D 4321 email@example.com"
###Sync to PDA .. well, that'll be a sync then!
#Start FinchSync SVR
#alias sync="java -jar /home/olly/finchsync/finchsync.jar -nogui"
#Stop FinchSync SVR
#alias syncoff="java -jar /home/olly/Apps/FinchSync/finchsync.jar -stopserver"
#Start FinchSync Admin
#alias finchsync="java -jar /home/olly/finchsync/finchsync.jar"
###My Functions .. not a command but a function. Below makes Terminal colorful. Different colors differentiate machines to help prevent errors. Hmmn, there's only 1 here .. I should get more into functions!
#add color & formatting to CLI
export PS1="[e[35;1m]u[e[0m][e[32m]@h[e[32m]w [e[33m]$ [e[0m]"
The way these work is pretty self-explanatory but, to break down an example, this one is the shortcut to open this file, bashrc, for when we want to add more cool ‘cuts:-
alias ebrc="nano ~/.bashrc"
- alias ebrc tells bashrc we’re issuing an alias directive, and that the alias itself will be “ebrc” (it could be mostly anything you like)
- = well, it’s an equal sign, obviously!
- “nano ~/.bashrc” is the quoted, properly syntaxed command we would normally provide
So, instead of issuing nano ~/.bashrc, now all we need type is ebrc.
That won’t work though, until we restart bashrc, by typing:-
As you may have seen, I’ve even shortcut the command to restart bashrc. Having set an alias to restart bashrc – ebrcupdate – and restarted bashrc one last time with it’s regular restart command, source ~/.bashrc), thereafter I type ebrcupdate.
You may imagine, this bash thing is darnedly handy, especially when maneuvering about remote servers where you also have a jazzed up bashrc. I log into the server for this site, for example, with this command:-
And if I want to open my SOCKS proxy, depending on where I want to pretend to be, I just type:-
.. or ..
How handy is that? Especially for a bloke like me who, like I say, can barely remember the, er .. can’t recall what I was gonna say there.
Got a personal favorite, or ten? Please share. I’ll add the ones that aren’t shortcuts to Viagra online.
Set up Koala .. tweak it to perfection … & maximize productivity … for work & play.
That’s what the Karmic Koala Bible does, stepped out in easy copy/paste guides.
From Linux initiates to intermediates, here’s what you need.
- Intro: Install & Perfect Ubuntu 9.10
- Ubuntu Desktop vs Server Edition?
- Plan Hard Drive Partition Strategy
- HOW-TO Install Ubuntu 9.10
- apt-get v aptitude v Synaptic v Software Ctr
- Terminal Alias Shortcuts with bashrc
- Add The Best Software Repositories
- Safe-Upgrade 9.10 System & Packages
- Update Latest 9.10 Hardware Drivers
- Speed Up 9.10 by Disabling Services
- Optimise 9.10 SWAP with Swappiness
- Restore 9.10 ‘home’ Folder from Backup
- SAVE TIME! Permanent Partition Mount
- TWEAK File Management Preferences
- Custom Keyboard Application Shortcuts
- Use Windows Key with Ubuntu 9.10
- HACK-PROOF 9.10 Anti-Virus & Firewall
- HOW-TO Disable Annoying System Beep
- Top 9.10 Software Picks by Category
- Add Application Launcher to Panel
- Remember Running Applications on Reboot
- Emulate Virtual OSes with VirtualBox