notbanksy's blog

Web Design, Linux and other nonsense

Top Linux Terminal Tips

What’s the best thing about linux? For me, it’s the terminal, and I think it’s a real shame how so many people shy away from linux because they’re intimidated by the terminal, or command line interface (CLI). It’s such a waste, but I also understand, because it made me nervous too in the beginning. But once you get going, it’s actually much more fun than just pointing and clicking, and of course, you are giving yourself a ‘heducation’ at the same time, innit?

So here’s a few pointers to make your GUI-free experience beautiful!

//Time’s Arrow

How many of you have read Martin Amis’s ‘Time’s Arrow’? Well, it bears no relevance to this part of my post, other than to provide a catchy title, but if you must know, it’s about a German Holocaust doctor who experiences time in reverse. And, yes, at the end he does disappear up his mum’s ‘front pocket’… Anyway, take a peek at those arrow keys on your keyboard. When was the last time you used them? Well, you’re going to reclaim them today sunshine, because they are a terminal’s top attraction. Each time you type something into your terminal, linux records the command, and adds it to a list of previous commands up to 500 commands old, cleverly called ‘history’! You can view the contents of this history by simply typing:

history

You’re impressed; I can feel it from here. But it gets better. Press the up arrow, and the terminal will automatically call the next most recent command, and type it for you. You can press it as many times as you like until you find the command you’re looking for. When you find it, simply press enter to run it. If you go past it by accident, the down arrow scrolls through the commands in the other direction. Genius!

So where is this mysterious history file then? And how do I find out how many commands it stores? Simple – you can ask your terminal using these commands:

echo $HISTFILE
echo $HISTSIZE

The history file is located at: ~/.bash_history – that’s a file called .bash_history located in your home folder. The full stop (period) in front of the file name means it’s a hidden file which is why you can’t see it in your file manager.

//Keeping Tabs on the terminal

What’s that? ‘Well, the terminal does look quite cool I suppose, but I can’t really be bothered to do so much typing,’ you say? Check out that lovely key on your keyboard above caps lock, it’s called tab. And it’s your friend. Imagine, you’ve got this file in your home directory called best_jokes_ever_told_by_rabid-misogynists_anywhere.txt, and you want to send it to your mother in law’s machine in secret using ssh? But you can’t be bothered to type it? Fear not. Open a terminal, and move to your home directory:

cd ~

So you want to check the contents of the file first using cat, eh? No problem. Simply type:

cat be<now press tab>

Provided there are no other files beginning with the letters ‘be’ (linux is case sensitive by the way) the terminal will automatically fill in the rest of the filename for you. This works will folders too, and is directory independent. You can cd to /opt/lampp/htdocs/my_new_website/version2 in just a few keystrokes. Give it a try – it’s ruddy fantastic!

//Installing software

If you’ve been using linux for a while, you will have probably come across a piece of software that you want, which doesn’t have a package installer for your flavour of linux. Instead, there’s just a dark and forboding link to a tar.gz file…. Take courage, my friend, for manual installation of software is not nearly as hard as it looks. A few simple commands, and you’re in business. Assuming that you’ve downloaded appIwantToUse.tar.gz into your home directory:

tar xvf appIwantToUse.tar.gz

Tar will extract the files contained in the tar.gz (which is just like a zip file, only better :p) into a folder with the same name (excluding the .tar.gz suffix). Next, you need to change into the new directory (folder)

cd appIwantToUse

Then follow these simple steps to install your app:

./configure this runs the configuration script from the current directory

make this compiles the application

su this logs you in as the root user so that you have the correct permissions to install (you will need to type your password)

make install this installs the program

And that’s it!

//A few other brilliant must know commands:

cd directory_name – change current directory to directory_name
ls – list all files and folders in the current directory
ls -a – list all the files and folders including hidden files and folders in the current directory
ls -al – list all the files and folders including hidden in the current directory as a long list
touch filename – create a new file called filename in the current directory
mkdir directoryname – create a new directory in the current directory
ps -A – list all running processes
kill process_id – kill a process by declaring its ID as shown in ps -A
whereis <filename> – search for files/ folders

And finally, if you’re unsure what a particular command does, you can consult the manual – type:
man command

Stay tuned to notbanksy’s blog for more terminal madness soon!


Filed under: linux , ,

One Response

  1. ElanMan says:

    Very useful post !b.
    I agree that the terminal can seem pretty daunting at first but once you’ve got the basic commands under your belt, it does become much faster to use than a gui.
    whereis is probably the most useful one for me. Always forgetting where certain files are :(

Leave a Reply

What’s notmrsbanksy up to?

Oh man! She's gone and set herself up as a dog rescue! Mostly saving pound dogs (UK) from being put down. Once Loved Dog Rescue.


She also lists UK pound dogs on her site Pound dog rescue link.


Boson has a new home!

Boson has a new home

WOOF!