Wednesday 19 September 2012

Lubuntu: Making Friends With Terminal

If you have no interest in your Lubuntu computer beyond using it for regular tasks (e.g. email, web, photo-editing) then you can stick to using graphical user applications that you pick from the system menu. That's fine! There is really no point in making your life more difficult than it is already!

 

However, if you want to look a little deeper into the workings of your system, there is no better place to start than at the terminal.


Why on earth would you need to use low level commands like "cd", "ls" and "mv" if you have a very capable GUI file manager, such as PCManFM?

Well, most of the time you would try to steer clear of "the dark side" and use a GUI app. But what if your system is broke and it wont boot to the desktop? You might be able to edit files and bring the poor old dear back to life via the command line interface, if only you knew how!


So if you are still with me, go to the accessories menu and start LXTerminal.

On my machine, when I start the terminal, the initial screen looks like this:-


This means I'm user "steve" at machine "Steve-Dell-D600" and the current directory is ~ (which indicates my "home" directory: /home/steve).
The "$" (dollar symbol) is my command prompt.

Change Current Directory

I can change the current directory with the command "cd" by using appropriate "arguments" (the tricky bits after the command, which are separated from the command by a space).

For example, I can go to my "Documents" directory by using:-



But this will only work if I'm in the parent directory (e.g. if I'm in /home/steve and the Documents directory is /home/steve/Documents)

To get to a directory from anywhere, I need to provide the full path after cd like this:-




I should also remind you at this point about one of the most annoying and unnecessary features of Linux:-
 that Linux files and directories names are case sensitive
(...who the hell needs separate folders for: music, Music, MUSIC & muSic anyway?)

There are also a few creepy codes you can use to save wearing out your finger prints. Try each of these in turn and see what happens:-
cd ..
cd -
cd ~

(.. = change to parent directory, - = last directory & ~ = your Home directory)

Let's Make A List

Another useful command is the "list" command. When used on its own, it will list the files & directories in the current directory.
So in your terminal type: ls


The more observant among you may have noticed that the list is colour-coded (at least using LXTerminal it is!). I'll leave you to work out the colour scheme.

And here is the most useful command of all, try this:-
man ls

You will find that many commands and applications include a manual (...thank god something in Linux has proper documentation!). You can move up and down this manual page with the up/down arrow keys, and you can close the manual by hitting the "q" key.

Try this with one of your installed GUI applications, for example:-
man firefox

Assuming its installed, you should see the manual showing command line options for Firefox. Once again its case sensitive, so your app name has to be exactly right...  ...Hey! Its not my fault!

Lets go back to the command prompt, as I have a few more things to say about ls (yes, yes... hit q key if still reading a manual...do try to keep up!).

Also Available In DOS

Its possible to alias commands in Linux, so just try typing:-
dir

...yes, I know its a DOS command, but you will often find this alias is included in Linux as another way to run ls.

And if you need a real list to print out or email to someone, you can re-direct your command's output to a file:-
ls > MyFileList.txt

...or you can provide the full path:-
ls > /home/steve/MyFileList.txt

...this technique is also useful when asking for help on a forum, as you can easily cut/paste or attach this output into your post.

Other Things To List

There are other variants of ls that you will find useful.

Try this:-
lsusb

...interesting? Then use the "man lsusb" trick to find out more.

You may also care to try:-
lspci

...and:-
lsmod

Sleepy? You Should Be.

One other trick, and then I promise to shut up!

Linux maintains a command buffer. In your terminal, at the command prompt, hit the up arrow.

You should now see the previous command appear at the command prompt, which you can now run again by just hitting the "enter" key.

In fact, while at the command prompt, each time you hit the up arrow you are presented with the previous command. You can go right through the history of previous commands until you reach the end of the command buffer.

Talking of history, if you type:-
history

...your system will list all your previous commands, limited of course by the buffer size, which (being Linux) is naturally configurable by you.

And since your command buffer is a file, these historic commands will be available next time you start your computer.....

..........OK, OK, I'm going!

No comments:

Post a Comment