Many a time, overenthusiastic beginners to the Linux world tend to try out various things a la Windows, and end up crashing the system.
Even more often, while trying to configure your display driver to run Compiz (aka Desktop Effects), you end up crashing Linux’s GUI server (called “X”).
Even if you’ve not screwed up your system, you can jump over to the console by pressing Ctrl+Alt+F1.
When you do this, you’re brought to a scary looking command prompt: (in this example, using Ubuntu)
The command prompt:
Ubuntu 8.10 (hostname) tty1
Where (hostname) is the name of the computer you specified during the installation. When you find yourself confronted with this screen, don’t panic.
Our helpful guide will tell you how to go about using the Linux command line.
Important note! Linux commands are CASE SENSITIVE – and all those mentioned in this guide are meant to be typed in the lower case. However, our WordPress theme thinks differently, capitalising the first letter of every command.
Again – the commands are in lower case. Ignore our theme’s capitalization!
Login on the command line
At the login prompt, type in your username and your password, each followed by “Enter”.
(Note: while typing in your password, you will not recieve any visual feedback.)
Once you login, you will see a prompt that looks like this:
…followed by a blinking cursor. What this means is that the console is ready to accept commands from the user.
From here, all you need to do is type in commands!
Wait, what’s is all this text?
First of all, you need to understand what you’re looking at. What you see in front of you – the black screen and the text – is the console. On this console, a program called the shell is running. That’s the one that’s displaying the prompt, the string of characters preceding the cursor. You have to type in your commands at this prompt (ok, there’s nowhere else you could possibly type them ).
Once you’ve finished typing a command, press Enter. This tells the shell to evaluate your command and execute it.
The name of the shell that Ubuntu uses is BASH.
Understanding the prompt
user refers to the username you used to login.
hostname is the name of your computer.
~ refers to the directory the shell is currently in (see below).
and finally, $ is the user prompt symbol. (Superusers get a # symbol)
The tilde (~) is the symbol used to represent a user’s home directory (typically /home/username).
As you change the path of the shell using the cd command (see below), the ~ on the prompt will change to reflect the current directory.
While in your shell, first try typing in ls and then pressing enter. You’ll see something like this:
Desktop Bliss2.jpg Desktop GNUstep Pages
W32 somefile kernel.config
The command ls lists out all the files in the current directory to the console.
Of course, being in your home directory all the time is no use. Use the cd command to switch from your current directory to another one.
The syntax is like this: cd followed by either the absolute path to the directory you want to change to, or it’s relative path.
For example, I want to switch to the folder “Desktop”, which is inside my home folder (see output of ls above). I type in the following:
user@hostname:~$ cd Desktop
I’m back to the prompt, but notice how the prompt has changed to accomodate the new directory. This kind of changing is using relative paths.
If you want to change to a directory that’s not inside the current directory, you’ll have to type out the full (absolute) path. Note that ~ can always substitute /home/username.
user@hostname:~$ cd /usr/lib/
Using ls and cd, you can browse your whole filesystem from the command line!
To delete files, use the command rm. Say you want to delete the file “example.txt” in the current directory – you would just type:
To copy file1 to file2, use the cp command. Just type
cp file1 file2
Killing a command
Suppose you type in a command, and it doesn’t seem to be doing or responding to anything. Just kill it with a Ctrl+C. This should bring you back to the shell prompt.
This works for most commands, since Ctrl+C sends it a kill signal. However, some programs may choose to ignore the kill signal, in which case you’ll have to resort to other means
Running a program as root
In order to run a particular command as root (administrator), you shoud prefix sudo to your command.
For example, the poweroff command requires root privileges to run, so you run it like this:
user@hostname:~$ sudo poweroff
[sudo] password for user:
System is going down for poweroff NOW!
Of course, this command is going to switch off your system
Finding out about a command using man
man is a really useful little program that allows you to read the documentation for a particular command or topic in the system manual pages.
For example, to find out how to run ls and to learn all it’s command line options, just type in man ls.
This open the ls documentation. Scroll through this with the arrow keys. To quit man, just press q.
Do more with the command line
Of course, this is not all you can do. Before GUIs came out, people were only using the command line to work their systems. But that doesn’t make it obsolete – even AFTER the GUI came out, people (including myself) still use the command line to do things!
Once you get the hang of it, you’ll find that it’s much faster and easier to use that a bulky GUI. The initial learning curve is what puts people off, though.
Don’t be put off! The command line is actually a lot of fun – and the only way to learn to operate it properly is to play around with it extensively, break things, and set them right again. Have fun with it!
And if you find something important we should have mentioned, let us know in the comments!
Hi!, If you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!