Part 1: Linux Overview
Tux
Official Mascot of Linux Kernel
"Some people have told me they don't
think a fat penguin really embodies
the grace of Linux, which just tells me
they have never seen a angry penguin
charging at them in excess of
100mph. They'd be a lot more careful
about what they say if they had." Linus Torvalds
1
Before Linux
In 80s, Microsofts DOS was the dominated OS for
PC
Apple MAC was better, but expensive
UNIX was much better, but much, much more
expensive. Only for minicomputer for commercial
applications
People was looking for a UNIX based system, which
is cheaper and can run on PC
Both DOS, MAC and UNIX were proprietary, i.e., the
source code of their kernel is protected
No modification is possible without paying high
license fees
Brief History of GNU/Linux
1985 Free Software Foundation (FSF) founded by
Richard Stallman. Along with other programmers
creates the tools needed to make a UNIX compatible OS
1985 Professor Andy Tannenbaum creates a UNIX like
operating system based on System V Unix for the IBM
PC & PC/AT computers. It is called Minix.
1989 Richard Stallman releases GPL and GNU software
but lacks a free kernel.
1991 Building on the concepts in Minix, Linus Torvalds
(Finnish college student) develops Linux along with help
from other users on the web.
3
What Linux is
Strictly speaking Linux refers to the kernel
GNU/Linux more accurately describes the Operating
System. Linux Kernel combined with GNU utilities and
libraries
Distribution GNU/Linux bundled with other applications.
Examples Red Hat Linux, Debian, Ubuntu, Suse,
Knoppix, etc.
Distributions can be compiled and maintained by an
individual or corporation. Can be small (single floppy
disk) or span several CD/DVDs.
[Link] for more information
4
What is a Distribution?
A Linux distribution (or distro) is a complete Linux
operating system: a collection of free and sometimes
non-free software created by individuals, groups and
organization from around the world and having the Linux
kernel at its core.
Companies such as Red Hat, SuSE, MandrakeSoft, as
well as the Gentoo project, compile the software and
provide it as a complete system ready to install and use.
(wikipedia)
Linux Distributions
Red Hat (Enterprise) Linux is probably the largest commercial Linux vendor.
Focus on stability and long term support. Red Hat sponsors a community
version (Fedora) which undergoes a more rapid development cycle.
Ubuntu based on Debian Linux. Ubuntu claims to be most popular desktop
version. Many applications and excellent update mechanism contribute to
its sucess. Revenue is created by selling technical support.
Puppy This distribution is small enough to be loaded entirely in RAM. This
frees up the CD/DVD drive for other uses. Configuration can be saved to a
file between reboots.
Debian GNU/Linux
OpenLinux (Caldera)
Red Hat
Slackware
SuSE
TurboLinux
Directory Tree
(root)
When you log on the Linux OS
using your username you are
automatically located in your
home directory.
Important subdirectories inside the root
directory
/bin : Important Linux commands available to the average user.
/boot : The files necessary for the system to boot. Not all Linux
distributions use this one. Fedora does.
/dev : All device drivers. Device drivers are the files that your Linux
system uses to talk to your hardware. For example, there's a file in
the /dev directory for your particular make and model of monitor,
and all of your Linux computer's communications with the monitor
go through that file.
/etc : System configuration files.
/home : Every user except root gets her own folder in here, named
for her login account. So, the user who logs in with linda has the
directory /home/linda, where all of her personal files are kept.
/lib : System libraries. Libraries are just bunches of programming
code that the programs on your system use to get things done.
8
Important subdirectories inside the root
directory
/mnt : Mount points. When you temporarily load the contents of a
CD-ROM or USB drive, you typically use a special name under
/mnt. For example, many distributions (including Fedora) come, by
default, with the directory /mnt/cdrom, which is where your CDROM drive's contents are made accessible.
/root : The root user's home directory.
/sbin : Essential commands that are only for the system
administrator.
/tmp : Temporary files and storage space. Don't put anything in
here that you want to keep. Most Linux distributions (including
Fedora) are set up to delete any file that's been in this directory
longer than three days.
/usr : Programs and data that can be shared across many systems
and don't need to be changed.
/var : Data that changes constantly (log files that contain
information about what's happening on your system, data on its way
to the printer, and so on).
9
Linux Shell
whoami
pwd
ls
Shell interprets the command and
request service from kernel
Similar to DOS but DOS has only one
set of interface while Linux can select
different shell
Bash, Tcsh, Zsh
Kernel
Bourne Again shell (Bash), TC shell
(Tcsh), Z shell (Zsh)
Different shell has similar but different functionality
Bash is the default for Linux
Graphical user interface of Linux is in fact an application program work on
the shell
10
Connecting to a Unix/Linux
system
Open up a terminal:
Connecting to a Unix/Linux
system
Open up a terminal:
The prompt
The current directory (path)
The host
UNIX command line tricks
Shell glob
# mkdir /tmp/moved
# mv * /tmp/moved
# cp /tmp/moved/* .
Filename Completion (tcsh, bash)
# ls /tmp/m<TAB>
Command line history (tcsh)
history
CTRL-P and CTRL-N, down/up arrows
!previous Runs the previous command beginning
with the word previous.
13
Help!
Whenever you need help with a command
type man and the command name
Help!
Help!
Help!
Unix/Linux File System
NOTE: Unix file names
are CASE SENSITIVE!
/home/mary/
/home/john/portfolio/
The Path
Command: pwd
To find your current path use pwd
Command: cd
To change to a specific directory use cd
Command: cd
~ is the location of your home directory
Command: cd
.. is the location of the directory below
current one
Command: ls
To list the files in the current directory use ls
Command: ls
ls has many options
-l long list (displays lots of info)
-t sort by modification time
-S sort by size
-h list file sizes in human readable format
-r reverse the order
man ls for more options
Options can be combined: ls -ltr
Command: ls -ltr
List files by time in reverse order with long listing
General Syntax: *
* can be used as a wildcard in unix/linux
Command: mkdir
To create a new directory use mkdir
Command: rmdir
To remove and empty directory use rmdir
Creating files in Unix/Linux
Requires the use of an Editor
Various Editors:
1) nano / pico
2) vi
3) emacs
Editing a file using pico or nano
Type pico or nano at the prompt
Editing a file using pico
To save use ctrl-x
Displaying a file
Various ways to display a file in Unix
cat
less
head
tail
Command: cat
Dumps an entire file to standard output
Good for displaying short, simple files
Command: less
less displays a file, allowing
forward/backward movement within it
return scrolls forward one line, space one
page
y scrolls back one line, b one page
use / to search for a string
Press q to quit
Command: head
head displays the top part of a file
By default it shows the first 10 lines
-n option allows you to change that
head -n50 [Link] displays the first 50
lines of [Link]
Command: head
Heres an example of using head:
Command: tail
Same as head, but shows the last lines
File Commands
Copying a file: cp
Move or rename a file: mv
Remove a file: rm
Command: cp
To copy a file use cp
Command: mv
To move a file to a different location use mv
Command: mv
mv can also be used to rename a file
Command: rm
To remove a file use rm
Command: rm
To remove a file recursively: rm r
Used to remove all files and directories
Be very careful, deletions are permanent
in Unix/Linux
File permissions
Each file in Unix/Linux has an associated
permission level
This allows the user to prevent others from
reading/writing/executing their files or
directories
Use ls -l filename to find the permission
level of that file
Permission levels
r means read only permission
w means write permission
x means execute permission
In case of directory, x grants permission to
list directory contents
File Permissions
User (you)
File Permissions
Group
File Permissions
The World
Command: chmod
If you own the file, you can change its permissions with
chmod
Syntax: chmod [user/group/others/all]+[permission] [file(s)]
Below we grant execute permission to all:
Running a program (a.k.a. a
job)
Make sure the program has executable
permissions
Use ./ to run the program
Running a program: an example
Running the sample perl script hello_world.pl
Ending a program
To end a program use ctrl-c. To try it:
Command: ps
To view the processes that youre running:
Command: top
To view the CPU usage of all processes:
Command: kill
To terminate a process use kill
Input/Output Redirection
(piping)
Programs can output to other programs
Called piping
program_a | program_b
program_as output becomes program_bs input
program_a > [Link]
program_as output is written to a file called [Link]
program_a < [Link]
program_a gets its input from a file called [Link]
A few examples of piping
A few examples of piping
Command: wc
To count the characters, words, and lines
in a file use wc
The first column in the output is lines, the
second is words, and the last is characters
A few examples of piping
Command: grep
To search files in a directory for a specific
string use grep
Command: diff
To compare to files for differences use
diff
Try: diff /dev/null [Link]
/dev/null is a special address -- it is always
empty, and anything moved there is deleted
ssh, scp
ssh is used to securely log in to remote systems, successor to telnet
ssh [username]@[hostname]
Try:
ssh yourusername@localhost
Type exit to log out of session
Scp is used to copy files to/from remote systems, syntax is similar to
cp:
scp [local path] [usernme]@[hostname]:[remote file path]
Try:
scp [Link] yourusername@localhost:[Link]
Programming on Linux
Tools needed:
vi, gcc, gdb, make
Some important directories
/usr/include/ and its subdirectories
/lib/ , /usr/lib
64
Vi
2 modes
Input mode
ESC to back to cmd mode
Command mode
Cursor movement
h (left), j (down), k (up), l
(right)
^f (page down)
^b (page up)
^ (first char.)
$ (last char.)
G (bottom page)
:1 (goto first line)
Swtch to input mode
a (append)
i (insert)
o (insert line after
O (insert line before)
Delete
dd (delete a line)
d10d (delete 10 lines)
d$ (delete till end of line)
dG (delete till end of file)
x (current char.)
Paste
p (paste after)
P (paste before)
Undo
u
Search
/
Save/Quit
:w (write)
:q (quit)
:wq (write and quit)
:q! (give up changes)
65
Compiler
GCC
GNU C Compiler (GCC)
Richard Stallman, founder of the GNU Project
for more info, read An Introduction to GCC.
66