Linux Basics

What is Linux?

Linux is a free open-source multi-user multi-threaded operating system with excellent reliability and security. It is based on Unix and in most respects is considered to work like Unix. The core part of the operating system was created by Linus Torvalds, a Finnish computer science student, in the mid-1990s. He was looking for a way to learn Unix system administration and other versions of Unix work-alikes, such as Minnix, did not suit his requirements.

What is Open Source Software?

Linux and the Unix-like utilities used with it are generally distributed under a licence created by Richard Stallman and the the Free Software Foundation (http://www.fsf.org) called the GNU General Public License or GPL. This license has several interesting features.

You should read the actual GNU General Public License yourself.

How is the Linux filesystem arranged?

Since Linux is based on Unix, it is not surprising that its filesystem is also based on Unix. The following directories are commonly found on Linux systems and some commentary is provided about their typical content:
/bin
Programs available to all users (see also /usr/bin and /usr/local/bin).
/boot
Linux Kernel and other files needed to start the operating system.
/dev
Virtual directory created at boot time to identify existing or potential devices for a system. All hardware in Unix/Linux is treated as a file. This simplifies programming.
/etc
Configuration files. These are mostly text files which may be edited to change the behavior of the system and its programs.
/home
Home directories for ordinary users. The root user's files are stored in /root.
/lib
Shared libraries used by several programs.
/mnt
Mount points for external filesystems. /mnt/cdrom is commonly used for CD-ROM filesystems.
/opt
Place to install some local programs. Used by StarOffice.
/proc
Virtual directory created at boot time to store information about running processes and installed hardware. It contains many files which can be read (/proc/cpuinfo for example).
/root
Root user's home directory.
/sbin
Programs primarily used by the root user. Some items, like /sbin/ifconfig, have limited use by ordinary users.
/tmp
Temporary directory. Any user may write files to it. However, only the user who creates a file may alter or delete it, except root of course who can do just about anything.
/usr
Programs which may be specific to a given distribution or local to a specific machine. Subdirectories include /usr/bin, /usr/sbin, /usr/lib, /usr/local/bin, etc.
/var
Active and dynamic directory containing logfiles, process ID files, incoming email, web pages (by default), MySQL databases, etc.
/www
Non-standard directory on many Linux systems to store web pages.

What is the boot sequence for Linux?

When a machine is first turned on, it performs a power-on self-test (POST) which checks for memory and key devices. The hardware then looks at the first boot device (CD-ROM, floppy, first hard drive) for bootable software.

If this is the first hard drive, it looks in a special sector called the Master Boot Record (MBR) for information on the way the drive is partitioned and a boot loader which tells it where bootable software may be found.

On most Linux systems, the common boot loaders are LILO (the Linux Loader) and GRUB (the Grand Unified Boot Loader). It is also possible to use the Windows boot loader or a 3rd party application like SystemCommander. The boot loader allows the user to select which operating system will be used during the boot sequence. A default value is usually selected after a short delay if no choice is made by the user.

After the Linux kernel is loaded (/boot/vmlinuz) the system examines the /etc/inittab file for instructions on the run level to be used and other key settings. There are seven run levels on Linux systems and their definition varies from distribution to distribution. On a Red Hat system, the following values are used:

Run LevelDescription
0Halt. Shuts down system and turns off power.
1Single User. Starts system and runs as root user.
2Multi-user without Network File System.
3Full Multi-user. Use this most of the time.
4not defined
5Full Multi-user with X-window login.
6Reboot. Shut down system and restart.

After the run level is identified, symbolic links to files in /etc/rc.d/init.d from /etc/rc.d/rcX.d (where X is the run level number) are executed in alphabetical order to start or stop (kill) server programs. The ntsysv program is helpful to specify which programs are turned on at boot.

The final file to be processed is /etc/rc.d/rc.local which may contain statements to be executed before a login screen is available at the console or remote connections are permitted.

What are some common Linux commands?

Linux commands are generally similar to or identical to Unix commands. Here are some useful ones which you may want to look at.
ls
List the files or directories. (ls -la /etc).
pwd
Print working directory.
cd
Change directory. (cd public_html).
whoami
Display current effective username.
who am i
Display information about effective username, server, connection.
w
Display list of users logged in to system and current activity.
cat filename
Display content of filename to standard output (usually the screen). (cat /etc/hosts).
more filename
Display content of filename to standard output one screen at a time. (less command is better).
less filename
Display content of filename to standard output with full scrolling capabilities along with vi-style search and line jumps.
cp oldname newname
Copy a file from oldname to newname. Original file is preserved.
mv oldname newname
Move a file from oldname to newname. Original file is removed after copy. May be used to rename a file.
rm filename
Remove (delete) a file.
grep word filename
Display lines which contain word from filename.