|Spare Time Labs 2.0|
PIC CDC ACM
Fun with HC08
Java Goes Native
Gas Fired Furnace
Down Memory Lane
25.10.2004 / Kusti
Linux 101 (for Dummies)This is a very brief introduction to Linux that I wrote to amuse myself.
(Actually this is notes to self so I do not need to look this up from the web every time I need it!)
Teletype and Other Arcane Stuff
Traditionally Unix based system are based on command line interface used over a terminal connection. Even if it all runs in a single PC. This is very powerfull but for those born into GUI enviroments it can be a bit intimidating and it has some features that are based on ancient computer history. Things that nobody bothers to explain.
Incidentally, this is part of University 101 - Computer Usage, worth one credit. If you know 1/10th of what's on this page, you'll pass. I did.
Back in the good old days, when I was in my early teens, computers were used via a terminal called Teletype. It was basically an electric typewriter where you punched keys to enter commands into the computer and the computer hammered (literally) it's output to roll paper. What is still significant from this old interaction model is that computer output was and still is static. So if you list the contents of a directory , and then delete a file, the listing stays the same, unless you take another listing. Not like a modern GUI window which tries to be WYSIWYG. (Ok, Windows does a bad job at this but just keep pressing that F5/refresh button...)
An other rudiment is that because output and input at 110 bps was slow and NOISY (try shouting RAT-TAT-TAT-TAT to get a feel of it) you wanted to minimize the number of characters used, hence most Unix descendants have very terse command names and output formats.(Yes, 110 bps is 110 bits/second or about 10 characters/second or to give you some perspective my WLAN is 500 000 times faster! Those were the days, and yet its only a quarter of a centry ago.)
So the main interaction model in Linux is a terminal session using a 'glass teletype'. You type in commands and watch the outpour of characters on the terminal. A session begins when you log into a Linux system and ends when you log off. It is usually possible to open multiple sessions by launching the terminal window multiple times. This can be very usufull as it is like working on multiple computers at the same time.
Of Files and Directories
All large systems, which today means any system, have thousands of files. On this laptop that I'm writing this on I have about 100.000 files. So obviously you want to organize them some how so that you can find anything at all. So the files are organized into directories that can contain further directories and/or files. This is called hierarchical file system. (Pity that the QDOS that Bill bought back in the old days and that later became known as MS-DOS did not have a file hierarchy, not to mention long file names. If he had bought something deacent, like OS-9, boy would we all have been saved from a lot of headache.)
Unlike Windows, Linux uses no drive letters, such as 'C:' to refer to disks. In Linux everything is a directory. The top most directory is equivalent to the drive letter. In Cygwin, which pretends to be a Linux but runs on Windows, the windows 'C:' disk is refered to as directory '/cygdrive/c'. And the root of Cygwin directory tree looking from Windows side is (usually) 'C:/cygwin', under which you find 'home', 'bin', 'etc' ...
File and directory names can contain all kinds of letters but it is best to use names that only use english lowercase letters and digits plus maybe dashes and underlines. Especially you should avoid names with spaces (' ') in them. They will make your life miserable. Names that begin with period '.' are not usually visible in directory listings which is why the many operating system tools store configuration data into files beginning with '.'. Or actually it is the other way round, because tools store info into those files they are hidden.
Names are case sensitive in Linux whereas in Windows they are not. This can be very confusing if you are testing something, say a web page, in Windows and it works but does not work when you upload it to the server which is most likely a Linux box.
Each session has current directory assosiated with it. What this means in Finglish is that if you do not specify (in a command) otherwise it is assumed that you are refering to the current directory. By having multiple sessions it is easy to work in multiple directories because in effect every terminal window has its own current directory.
Here are the most common commands that are used to work with (current) directories.
PathsFiles and directories are referd to by path names.
There are relative and absolute path names. A relative pathname begins with a letter and it refers to a file or directory that is in the current directory or a subdirectory of current directory. An absolute path name begins with a slash and specifies the full 'path' from the highest level of the file system to the file/directory in question.
The current directory can be referenced as '.' and the parent directory of the current directory as './..' and so on.
Every user, based on their username, has a special directory called home directory. Immediatelly after login current director is set to your home directory. The home directory can be referenced as '~' in a path.
The asterisk ('*') can be used as a wild card in most situations when specifying files on a command line.
There are conventions in Linux world on how to organize the file hierarchy. There is nothing to enforce these conventions but most system are organized along these lines.
Here are some often used directories:
Working with FilesHere are the most common commands that you need to work with files.
Getting HelpMost commands list a short description of their usage and possible argumenst i.e. parameters when given the parameter --help. For example:
Commands, Scripts and ShellsIn Linux all commands are actually small programs that you run. You run them by typing their names to the command interpreter which the in-crowd calls 'shell'. There are quite a few shells around but most resemble each other. In Cygwin the shell (which is just another program) is called 'bash'.
In DOS/Windows you can store commands into batch files that end with the name extension '.BAT' which allows you to execute those commands by typing the file name. In effect creating more commands out of existing commands. This is often called scripting and the the files that contain commands are called , you guessed it, scripts.
In Linux any text file is a potential script. When you type a file name the shell checks if the file is marked executable and if it
is it will execute the commands in that file. A nice example of this is the way GNU tools are configured. You usually configure them
by going to the directory that contains the source code and type
To make a file executable (for everybody) you use the chmod command, like this:
To see if a file is executable and other stuff use:
Pipes and more (or less)Most Linux commands read in some text or parameters and then produce and output some text. It is possible to redirect both the input and output of a program. You do that with '<inputfilename' for input and with '>outputfilename' for output. For example, if you want to create a list of all files in your current directory and store it into a text file use:
Using Grep as a FilterLots of people love
Simply (very simply) put
Anyway, here are some usefull grep's :
Following is a way to list all '*.java' files and the directories in which they are starting recursively from current directory:
Finding (in) filesTo find a file containing a certain word use:
Counter intuitively and unfortunatelly the following DOES NOT work:
If you want search all files of certain type in current directory and sub directories you need to use:
Finds 'this' in any '*.c' file.
Following gibberish executes
Unpacking FilesA lot of things in the Linux world are distributed as tar (aka tarball) files which are compressed with
Most Linux/Free software is delivered in source code format.
This is a way too complex subject, but amazingly a lot of GNU based Free software actually
can be installed and compiled by going to top level directory of the source distribution
and entering following: