What Is Linux?

Linux is a free implementation of the Unix operating system written by Linus Torvalds. Techically, linux refers to a single file called the kernel. The operating system, also called Linux (but sometimes called GNU/Linux to avoid confusion) includes Linus's kernel plus many programs written by the Free Software Foundation. The Free Software Foundation (known as FSF or GNU) is controlled by Richard M. Stallman (also known as RMS by uber geeks).

If you know your way around Unix, you know your way around Linux.

There are numerous books, FAQ's and Internet documents on Unix, so I won't get into the details. The best thing to do is to ask a friend if you're truly lost. I'll highlight the main points of what you need to get started.

You received a login and password for the Mathematics Computer Lab system. To log into the computer, enter your login name at the

login:

prompt. Your login is probably the first letter of your first name followed by your last name. Enter your password at the

password:

prompt. At this point, you should be staring at the unix prompt, which may (or may not) look something like:

lifshitz%

Now What?

What you're staring at is not so different from a DOS prompt. There are a few basic commands that you'd need to know to get started. Here they are:

ls list a file in your current directory ls list all the files in directory cp copy to rm delete mv rename as mv move into directory mkdir make a new directory called

That's pretty much it. There are tons of small details which you'll pick up as you get familiar with Linux. For example, if you type

rm ...

you'll delete all the files listed after the rm command. You'll pick these things up as you go along. Linux was written by programmers who were mostly concerned with making Linux stable, useful and fast to use. Anything that you think is a good idea has already been implemented under Linux.

There are other things that you'll have to know, like how to use the vi/vim editor or how to compile your programs. But these are covered in other tutorials I've written.

Directory Structure

You'll have to be familiar with the Linux directory structure to do anything useful. The directory structure is similar to DOS, so if you know DOS, you're set. The directory structure is hierarchial. The top directory is called the "root" directory and is called / (the forward slash). Below it are other directories, for example, bin is a directory in the root directory:

/bin

and ls is a file in bin:

/bin/ls <-- ls is a file inside of the bin directory
^ ^
| |
| |
| +-- bin is inside the root directory
|
+-- / is the root directory

The only thing that's a bit confusing is that the slash / is a separator between directories and files, except when its at the beginning. When / is at the beginning, it stands for the root directory.

As one last example, the document I'm typing is on my home computer. It is:

/home/p/TA/basic_linux

home is a directory in the root directory. p is a directory in home. TA is a directory in p. And basic_linux is a file in p. When you specify a file using all the directories, starting at /, it's called a "pathname". So one way of specifying basic_linux is either by it's name:

basic_linux

or by its full pathname:

/home/p/TA/basic_linux

There are two files in every directory:

. means your current directory

.. means the directory before the current directory.

So to be perverse, here are two more ways to refer to basic_linux:

./basic_linux

../TA/basic_linux

since . here means /home/p/TA (the current directory) and .. means /home/p (the directory above the current directory. Can you see why the following also refers to basic_linux?

../../../home/p/../p/TA/./basic_linux

If you can understand this, then you're definitely doing well!

You can find out what directory you're currently in by typing

pwd

at the prompt. Try it. Now try typing

cd ..

Now type "pwd" again and see if it prints what you'd expect.

Directories or Files?

If you type ls, you may see something like:

MP3
notes
Mail
nsmail
News
personal
Office51
pinochle.html
a.out
pppdman
anint.nb
spherical_expanding_box.nb

believe it or not, some of these are files and some are directories. That's because in Unix (and Windows too) directories are actually files. Special files, but still files. How can you tell which ones are files and which are directories? Type ls -F. You'll see something like:

MP3
notes/
Mail/
nsmail/
News/
personal/
Office51/
pinochle.html
a.out*
pppdman
anint.nb
spherical_expanding_box.nb

Anything with a * is an executable, something you can run. Anything followed by a / is a directory. Everything else that you'll see is a normal file. Moral to the story is use "ls -F" instead of just "ls".

You can also get clues by the filename suffix. Under Unix, suffixes aren't as tightly bound to filetypes as they are under Windows (technically not true anymore. If you run GNOME under Linux, they ARE as tightly bound as they are under Windows). This means that index.html doesn't necessarily have to be a web page, but chances are VERY good that it is. With the exception of GNOME, filename suffixes are hints to the user, not the application. If you're totally stumped by what exactly a file is, you can use the "file" command. I'll illustrate:

# file pppdman

pppdman: International language text

# file a.out

a.out: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped

# file admin

admin: directory

The # in this example is my prompt.

Running Executables

Just like DOS, Linux commands like ls and cp are programs that reside on the computer. Most of the main system commands (like ls and cp) reside in /bin. So when you type "ls" you're actually running an executable named ls in the /bin directory. During this course, you'll be writing programs, and these are executables too (once you compiled them). In fact, in principle, your programs will be very much like the ls and cp executables. They'll just do different things.

To run an executable, simply type its name. Like you do with ls. An important question is: How does the computer know where to look for the executable? How does the computer KNOW that ls is located in /bin? After all, Linux has to know where ls is in order to run it. This is a highly non trivial problem. My computer, a small home PC, contains 61486 directories.

There are two ways Linux looks for your executable. The first way is if you specify a full pathname. So, if you type

/bin/ls or /usr/sbin/useradd

Linux will look for the ls executable in /bin and the useradd executable in /usr/sbin. By the way, if you type

./ls or ./useradd

then that's equivalent to specifying a full pathname since . means "the current directory". In this case, Linux will look for ls and useradd in your current directory.

If you DON'T give a full pathname, like:

ls or useradd

then Linux looks for the executable in your PATH. PATH is a variable which is very similar to the PATH variable in DOS. PATH holds a bunch of directories separated by colons. Type

echo $PATH

on my system, I get:

# echo $PATH /usr/bin:/bin:/usr/X11R6:/usr/X11R6/bin:/sbin:/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/lib/java/bin:/var/lib/dosemu:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde/bin:/usr/lib/pgsql/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin/share:/usr/local/sbin:/usr/local/games:/usr/local/pgi/linux86/bin:/root/Office51/bin:.

yours probably won't be so long. When I type "ls", Linux looks for an executable name "ls" first in /usr/bin. If it doesn't find "ls" there, it'll look in /bin. If it doesn't find "ls" in /bin, Linux will look in /usr/X11R6. And so on. It'll keep going down the list till it hits the last directory in the PATH, which is "." (see that?). And remember, . means your current directory.

Suppose you write a program, compile it and now you have an executable named "integrate" in your current directory. To run it, simply type its name. If you see something like:

# integrate

bash: integrate: command not found

then it means one of two things:

1- integrate is not in your current directory

2- integrate IS in your current directory, but . isn't in your PATH.

Type "ls" to make sure integrate is in your current directory. If it isn't, use cd to change into the directory containing integrate.

If integrate is in your current directory, then you have to do one of two things:

1- Specify the full pathname for integrate. For example,

./integrate or /home/mydirectory/integrate 2- Add . in your PATH.

To add . in your PATH, simply type:

PATH=$PATH:.

and you're good to go.

Making Your Changes Permanent

Everytime you log into Linux, it runs a file called .bash_profile. Suppose you want to permanently add . to your PATH. Add the following line to .bash_profile:

PATH=$PATH:.

Suppose you always want to type ls but have it do ls -F instead. Add the following line to .bash_profile:

alias ls='ls -F'

Questions or comments should be directed to the author, Peter Jay Salzman, at p@dirac.org. My homepage is www.dirac.org.