Tips for general use of the command-line

I don’t claim to be a veteran command-line user, I still need to crack open the books when I want to write anything but a very basic script. However, like most Linux users, I often need to fire up a terminal to do something – whether it’s the desktop that has failed me, or that I just want that bit of extra speed. Here are some tips I’ve accumulated over my short time in the command-line. They are open to suggestions and opinions, I’m fairly open-minded about the whole thing (a clear indication that I haven’t been doing it for long!).

Never use apt-get, always use aptitude

Aimed at Debian/Ubuntu users. This is a hard habit to kick, but aptitude is much more user-oriented, the commands are nearly identical to apt-get, and most importantly it resolves dependencies more effectively both during installation and on removal of software. I started forcing myself by creating an alias in my session, sounds unproductive but it definitely helped me to remember which program I should be using.

Add the following line into your ~/.bash_aliases file: “alias apt-get=aptitude”.

Use Vim

At first glance, Vim (Vi-Improved) looks like the most clunky unproductive text editor ever devised, and to start with it is. However, if you persevere with it, the rewards are huge. The functionality behind Vim rivals most GUI text editors, and if you take time to learn the standard control keys (such as h,j,k,l for moving the cursor), you find it becomes much faster to use. Plus it starts instantly, like Windows Notepad on steroids.

Oh, and Emacs is nice too 😉 Though I feel Vi gets you further in the command-line, and it can be found everywhere.

Less is More

Whenever somebody instructs you to read a file using “more”, or pipe stdout to “more” for easier reading, replace all occurrences of “more” with “less”. Less gives you much more control over page operations, including the ability to scroll back up a page, and search the output for a string. The commands are an identical sub-set to Vim, so well worth learning.

Get screen

Not an essential, but extremely useful at times. Screen is a small program that allows you to essentially split a single terminal into a number of virtual ones. At first (apart from a splash-screen) it looks like it hasn’t done anything. However, run a program then press “Ctrl-a” followed by “c” and you have a brand new terminal to work on, no need to push the program into the background! Press “Ctrl-a” followed by “n” to cycle between the 2 virtual terminals at will. There is much more to screen, check out the manual. Excellent for when you’re running a PuTTY session!

Learn regex

If you want to do anything sophisticated with the command-line, chances are you’ll sometimes need to use regular expressions. This I agree messes with the head a bit, but mastering regex will allow you to use grep, sed, and countless other programs more effectively. A bit of a hypocritical tip, considering I’m still learning regex properly myself, but still a perfectly valid one in my opinion.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: