The Linux Operating System - Tonga Institute of Higher

Download Report

Transcript The Linux Operating System - Tonga Institute of Higher

Tonga Institute of Higher Education
The Linux Operating System
Lecture 1:
Introduction and
Working with
Linux
What is Linux?
●
●
●
Linux is an operating system that evolved from a
kernel created by Linus Torvalds when he was a
student at the University of Helsinki.
To say that Linux is an operating system means that
it's meant to be used as an alternative to other
operating systems like MS-DOS, the various versions
of MS Windows, Mac OS, Solaris and others. Linux is
not a program like a word processor and is not a set
of programs like an office suite.
It is a different way to run your computer. Instead of
letting Microsoft control how you work, you can let
Linux give you another option.
A history of Linux
●
●
●
When Linus Torvalds was studying at the
University of Helsinki, he was using a version of
the UNIX operating system called 'Minix'.
Linus and other users sent requests for
modifications and improvements to Minix's
creator, Andrew Tanenbaum, but he felt that
they weren't necessary.
That's when Linus decided to create his own
operating system that would take into account
users' comments and suggestions for
improvements.
The Start of Free Software
●
●
●
●
This philosophy of asking for users comments and
suggestions and using them to improve computer
programs was not new.
Richard Stallman, a professor in America, had been
advocating just such an approach to computer
programming and use since the early 1970's.
He was a pioneer in the concept of 'free software.'
He left his school in 1984 and founded GNU. The
goal of GNU was to produce software that was free
to use, distribute and modify.
Linus Torvalds' goal 6 years later was basically the
same: to produce an operating system that took
into account user feedback.
What did Linus actually make?
●
●
●
When Linus first starting working on his new
operating system he built the “kernel” first. The
focal point of any operating system is its 'kernel'.
Without going into great detail, the kernel is what
tells the processor what to do when your program
wants to do something. It is the like a policeman
directing traffic. If a car wants to get to the other
side of the road, it has to ask the policeman first.
The policeman will then tell the car that it can go.
The kernel acts in the same way by controlling
programs and letting them use the processor. So,
without a kernel, an operating system doesn't exist.
But also, without programs, a kernel is useless.
The meeting of great minds
●
●
●
In 1991, Richard Stallman and Linus Torvalds
found out about each other and realized that
they both had what the other wanted.
So, because they were so far apart they used
the Internet (which was just starting out and
was very small) to exchange ideas and code.
The Internet in reality let Linux be created and
also played a big role in its future development,
because people all over the world were able to
learn about it.
Linux is Introduced
●
●
●
So with a bunch of programs from GNU and the
kernel of Linux, Linus released the first version
and asked people on the Internet if they wanted
to help build an operating system.
Many responded, and at first they were people
with extensive computer programming
backgrounds. They helped to write drivers for
hardware, necessary programs for an operating
systems and anything else they decided they
needed on the computer.
This was when Linux became known as an
operating system for computer professionals only,
but today it is quite easy to install and use.
Why is Linux Succeeding?
●
●
●
●
Linux has proven to be a tremendously stable and versatile
operating system, particularly as a network server.
When Linux is deployed as a web server or in corporate
networks, its down-time is almost negligible. There have been
cases when Linux servers have been running for more than a
year without re-booting.
Its cost effectiveness has sold it more than anything else. Linux
can be installed on a home PC as well as a network server for a
fraction of the cost of other companies' software packages.
More reliability and less cost - it's ideal.
This is because it is completely free. You can download the
entire operating system and all the programs you want free of
charge
So what is Linux really?
●
●
●
●
Linux is an operating system that is based on the UNIX
operating system which has been around for 30 years.
The big difference is that UNIX needed special
hardware to run and it cost a lot of money.
Linux's big advantage is that it has been remade to run
on any type of computer hardware, including the
inexpensive Intel processors.
This opened the door to letting everyone have the
power, security and flexibility of a UNIX operating
system, on their own network
How do you get Linux?
●
●
●
There are a number of ways to get Linux.
If you have a lot of time, you can download the
ISO images (CD images that you can burn onto
CDs). Most distributions are 2-3 CDs, which is
about 1-2 gigabytes of data. There are websites
all around the world dedicated towards letting
people download these files
You can also purchase the CDs from a company
like RedHat. Although they let people download
their software for free, they also will sell the
software with support and documentation
What can we use it for?
●
●
●
●
Linux works well as a server or a workstation.
There are programs that let a Linux machine
run web, ftp, mail, SQL, firewall and Novell
servers among many others.
It is also easily used for programming, graphics
and audio/video processing among many others
Because it's stable, secure, and the code is
open source, more and more people are using
it on a daily basis for a wide range of
applications
Working with Linux
●
●
●
●
Linux is a true multi-user system, which means that many users
can be working with the same computer at the same time.
There are two types of users, the root user and everyone else.
The root is the superuser of the system. This is the user that
can do anything he wants.
But root is actually more like the 'janitor' of the Linux system.
Root has the keys to everything, he can shut off the lights, shut
off the heat, lock you out of the building; he has to clean up
the system and in the end make sure everything runs. And the
most important thing about being a janitor - he sees
everything.
Root
●
●
●
Since root can do anything he wants, he also has to
be careful about what he does. One wrong move,
one file deleted that should not be, and the whole
system might crash and not be able to start again.
Generally, you should only use root when you really
need to. If there is some system administration
task that needs to be done, you will have to use
root, but then you should switch back.
This is to protect your computer from yourself
The other users
●
●
●
●
●
You'll be working as one of those other users most
of the time.
Other users can have whatever user name they
want, as long as there is no spaces or strange
characters.
So now that you have a user name what can you
do?
If you're not at the physical computer, you'll have to
log in using a remote client program.
Once you have logged in, then you will see a
command line interface (CLI) in front of you
Telnet and SSH
●
●
●
To log into a Linux computer, you'll need a remote
connection program.
For a long time the only option was telnet, but
people soon realized that telnet was very insecure
because it sent all it's data over the network
unencrypted and anyone could see it. That means
anyone can see your password
SSH is the secure version of telnet. It encrypts all
data before it is sent so no one can look at it. Most
Linux computers don't even allow people to use
telnet anymore.
Using a remote client program
●
●
●
So now that we want to use the program we need to give
the program the name of the “host” we want to log into.
The host is the name of the computer on the network. If
you know the computer's IP address, you can also use that.
Telnet Example
> telnet website.com
Trying 72.138.35.44...
Connected to website.com.
Escape character is '^]'.
Red Hat Linux release 8.0 (Psyche)
Kernel 2.4.18-14 on an i686
login:
After the login – the shell
●
●
When you're running Linux and start to type things
on that black screen, you are using a shell.
This command line interface is really just a program
that sends what you type to the operating system
kernel to tell it what to do. All operating systems
will use some type of shell to get commands from
the keyboard to the computer.
What to do in the shell
●
●
●
●
●
●
So the way that you use Linux is by typing commands into
the shell.
Commands are just programs that you run and help you see
information or will perform a task.
We're going to look at the most important commands, the
ones that you will use all the time firstly.
The first one we should look at is 'cd'. MS-DOS users will be
familiar with this. cd will get you in and out of directories.
Example: cd /
This will get you into the 'root' or main directory. It is the
first directory in the Linux system.
The 'ls' command
●
Now that you have changed directories, you'll want to see
what's in them.
●
The ls command will list everything in a directory.
●
Example: ls
●
You can also see what's in other directories by passing 'ls'
an argument. That means you will type the name of the
program, then a space, then you will type an argument. For
ls, it will be the name of a directory
●
Example: ls /bin
●
Example: ls /etc
●
Example: ls /home/user
Example: ls ..
Notice that you can also change into a directory and then
list what is inside of it.
Some Shortcuts on Linux
●
●
●
●
There are a few things to make life easier for
people who need to type all day.
If you press the up arrow, it will show you the last
command you typed into the shell. If you keep
pressing up, it will show you the entire history
If you just want to see the entire history, try typing
history into the shell. You'll get a list of
commands you typed.
Another handy tool is if you are typing the name of
a directory or file, you can type part of it and then
press the tab key and Linux will fill in the rest
Using options with commands
●
●
●
An option is an argument that's passed to a program
that will make the program run a little differently.
For example, typing: ls -l will give you more
detailed information about the contents of a directory.
Try this: First let's go to the “/usr” directory by typing
–
●
cd /usr then type:
ls -l
You will see more information, like dates, some
numbers, letter combinations, it'll say 'root' a lot. You'll
see mainly sub-directories here. The /usr directory
contains files and programs meant to be used by all of
the users on the system.
Text editing in Linux
●
●
●
A big reason people want computers is to do
text editing and word processing.
Linux has a number of many full-featured
word processors when you're using the
graphical version.
If you have just logged in with a terminal
and still want to do text editing, you will
need a text editor, a word processor without
all the extra stuff word processors put in
Text Editor: vi
●
●
●
Many people claim the program called “vi” is the
most popular text editor.
This is a program that comes from UNIX. There is a
more recent version called 'vim' which means 'vi
improved'. The problem with 'vi' or 'vim' is that a lot
of people don't like it. You have to remember a lot
of key combinations to do stuff that other text
editors will do for you more easily.
The other problem is that sometimes you need to
use 'vi' to edit a file, so it's good to learn a few
simple commands to get by.
Working with 'vi'
●
●
●
To start the program, at your prompt, type:
vi file1
“file1” is an argument that is passed to the vi
program. It tells vi to open a file called “file1”
Your file will be named differently, so you will put
whatever file name you need there. Remember to
use spaces between the program and the
arguments that you are sending to the program
Working with 'vi'
●
●
After you open a file you'll see a line of squiggly
lines down the left side and the name 'file1' at the
bottom and [new file]
To write something, you have to press ESC and the
'i' key (i for insert). Even if you don't press 'ESC-i' it
usually gets the idea that you want to type
something and lets you do it after a few keystrokes.
You should get used to the 'ESC-i' keys so you don't
end up writing 'ar John' instead of 'Dear John'.
Working with 'vi'
●
●
●
●
●
Press ESC + 'i' then type: hello vi
To save this file, you would press ESC then the colon key
':' then 'w' (write)
To save the file and quit vi, you would press ESC, the
colon key ':' then 'wq' (write, quit)
To quit without saving, press ESC, ':' then 'q'. Vi may
protest if you've written something and you don't want to
save it. If you press ESC ':' 'q!' with an exclamation point,
vi will accept it and not save your changes.
This is the most vi you'll need for the majority of things. It
can be quite difficult to learn, so we'll use another text
editor to do most of the work we need to do
Pico
●
●
●
●
●
●
Pico is a friendly text editor that is pretty easy to get the
hang of.
To use it, type pico and then the name of the file you
want to open, or the name of the file you want to create.
If you don't type a name after pico, it will open a window
and then when you want to save it will ask for a name
Once opened up, you will be able to type automatically.
To save a file, press Ctrl and O at the same time (Ctrl-O).
This will save the file and keep the window open
To save and exit, press Ctrl-X.
Pico will ask you to make sure you want to do something
every time you do it, which is good so that you don't
make mistakes
Shells in Linux
●
●
●
●
A shell is just a way for your computer to receive commands.
The most common shell used for working in Linux is the
'bash' shell.
The most common commands a computer receives are ones
to copy files, move files around, list files and delete files.
Popular operating systems have perfected this to such a
degree that they have graphic interface programs to do all
this for you just by moving the mouse around and clicking on
a few buttons.
Linux has these programs too, but anybody who's seriously
thinking of using Linux on a day-to-day basic should be
familiar with the commands that you type in by hand. This is
a way to have more power over your computer
Frequently Used Commands
'ls' command
●
●
●
Typing 'ls' will list the contents of a directory with
just information about file names.
You can use 'ls a*' to list the names of all the files
that begin with the letter 'a' and so on down
through the alphabet.
Normally we'll want to add on some parameters
(those -[letter] combinations) so that we'll get
some more detail
Frequently Used Commands
Using 'ls -l'
●
If you type ls -l into your shell you will see
something like,
-rw-r--r-- 1 bob users 103824 Jul 10 12:01 file.gif
●
●
The first part, those letters, are file permissions, which
we will discuss shortly.
The next one shows that you've got 1 file. The next one
that it belongs to the user, 'bob'. The next one shows
what group owns the file. The numbers are the size of
the file in bytes. You have the date and when it was
created or modified or copied there. Lastly, you have
the name of the file, file.gif
Other parameters with ls
●
●
ls -l -t will give you a listing according to the
time with the newest ones appearing first in the
list.
You don't need to separate the parameters either.
'ls -l -t' and 'ls -lt' are the same thing. If you want
the oldest to appear first, try: ls -ltr
–
The 'r' is for reverse order.
●
There are a couple of parameters in capitals that
you may want to use.
ls -lS will list your files from biggest to smallest.
●
ls -lSr will reverse this order.
●
●
You can also use a wildcard with ls that says to list
anything that matches a certain pattern.
Less and tail
●
●
●
To see what is inside a file, you can of course use a
text editor, and then make sure you don't type any
keys, but Linux has some other programs to help
you view what's in a file
The program 'less' will display a file and let you
scroll back and forth through it. Good if you want to
see a file from start to end. In your shell, just type:
– less name-of-file
The program 'tail' will show you the last few lines in
a file. This is good if a file is being updated
continually and you want to see what is being
added only to the end. In your shell, just type:
– tail name-of-file
Getting familiar with 'cp'
●
●
●
●
'cp' is used copy a file from one place to another
place or from one name to another name.
To copy it into another place, we'll want another
directory to copy it into, so we can make a new
directory, by typing in the shell
– mkdir myfolder
Then to copy a file into that directory, we can use,
– cp file myfolder
Then we will have two copies of the file, one in the
current directory and one in the directory called
myfolder.
More 'cp' uses
●
●
There are many other ways we can use cp as
well
If you want to copy an entire directory to
another directory
–
●
If you want to copy a file to another name
–
●
cp -r /home/user/a/ /home/user/b/
cp file1 file1copy
If you copy and overwrite anything that has
the same name, and you don't want to be
asked about it each time
–
\cp -rf /home/user/a/ /home/user/b/
The 'mv' command
●
●
●
●
The 'mv' or move command has two functions in
Linux. It is good for renaming files and it is also
good for moving files to different directories.
To rename a file with mv, try using
– mv old-file new-file
To move files into a new place, like another
directory, try
– mv file1 file2 file3 /home/user/a
You can also use the wildcard to help you move a
lot of files
– mv file* /home/user/a
Making and Removing Directories
●
●
●
We've seen how to make a directory, you use a
program called mkdir and pass it the name of a
new folder
– mkdir new-folder
To remove a directory, first you must remove
everything in it. Then you can use the command
– rmdir old-folder
So to remove everything in a directory, you'll use
the rm command, short for remove. You just pass it
the names of the files you want removed and
they're gone
Removing files
●
●
●
●
●
●
So when we want to remove a file, type into your shell
– rm file1 file2 file3
You can also use the wildcard with remove, to save
yourself some typing
– rm file*
If you want to delete everything in a directory
– rm *
Notice it asks you if you want to delete everything. To
just make it delete everything, we can use: \rm -f *
This is a pretty dangerous way to do things, because it
won't ask you if you want to delete everything.
A good way to delete everything on a computer:
– \rm -rf /
Using pipes
●
●
●
A pipe is a way to use two or more programs
together with each other. That means we will “pipe”
or send the output from one program to the input
of another program.
The way to use a pipe in linux is with the '|'
symbol. That's not an I or an l. It's a the character
you get when you press shift and '\' at the same
time.
So what can we use it for? Example: what if you
type ls in a folder and the files are too many to see
on a screen. We can use the program less to show
us the files one screen at a time: To use
– ls /usr/bin | less
Getting more information
●
●
You know how to use a few simple commands, but what if
you need to find out more information?
Usually most programs will have a built-in help screen. If we
were using a program called “prog1” there's a good chance
we would find a help screen if we typed
–
●
prog1 -h
Another way to get more information is to use the man
program. This is a program that saves documentation about
other programs. So we could type:
–
–
●
prog1 --help OR
man cp
man ls
We would then get information about cp or ls.
Finding more stuff
●
●
●
●
●
A lot of Linux distributions will come with a program
called 'locate'
This program keeps a database of all the files on
the computer and so when you use locate like:
locate tonga
It will search through it's database very quickly and
find anything that had the name tonga in either a
filename or a directory.
The program also needs to update it's database, so
sometimes new files won't be included until the
database is updated again.
To update the database, you type the command:
updatedb
Becoming a power user
●
●
There are literally thousands of programs and
commands that a Linux user can use. To remember
all of them or even know what all them do would
almost be impossible. We'll look at a few more
commands that will be interesting and give you a
little more sense of how Linux works and what you
can do with it.
The 'who' command. A program called who will tell
you everyone who is working on a system. You can
check to see if your friend is logged in or not and
even chat with him after. Just type the command –
who
Using '>' and '>>'
●
●
These two commands will redirect output
from a program into a file.
The '>' will take output from a program and
write it to a file. If a file is already there, it
will delete what is inside:
–
●
Example: ls /usr/bin/ > directory_list
The '>>' will append to the end of a file
something. For example, the program 'date'
will output the date and time. To add this to
the end of a file you were working on, try
–
date >> homework.txt
Who, what, where
●
'whoami' will tell you the username you are
using
–
●
'whereis' is a nice command for finding other
commands or programs.
–
●
Type: whoami
Example: whereis pico
'which' is another tool for locating programs
'which' is similar to 'whereis'. It will give you
the location of a program
–
Example: which pico
Echo and wc
●
'echo' is a program that will output anything
you type to it, (sort of like an echo). This
might be good if you don't want to open a
text editor, you can just echo something and
pipe it into a new file
–
●
Example: echo hello world > new-file
'wc' is a program that will count number of
lines, number of words and number of
characters in a file
–
Example: wc new-file
–
Output: 1
2
12 new-file
More commands
●
The command 'last' will show you who last logged into
the computer and from where
–
●
The command 'df' will show how much more space is
left on your harddrive
–
●
Example: df
The command 'free' will show you how much RAM you
have on your computer and how much is being used
–
●
Example: last
Example: free
The command 'top' will show you the programs that are
using the most memory and most of the processor on
the computer at the current time.
–
Example: top
Seeing processes
●
●
●
●
●
The command 'ps' is used to show processes running
on a system.
To see all the programs running on the system by all
the users, try
– ps -aux
To see all the programs you are running on the system,
try
– ps -x
If you are running a program and want to stop it, you
can use the command 'kill'
First you find the process id from by using the ps
program. Then you would use the kill command, like
– kill 30430
Example: ps -aux
[root@linux root]# ps -aux
USER
PID %CPU %MEM
rpc
558
0.0
0.1
rpcuser
577
0.0
root
658
root
VSZ
RSS TTY
STAT START
TIME COMMAND
1484
416 ?
S
May30
0:00 portmap
0.2
1528
580 ?
S
May30
0:00 rpc.statd
0.0
0.1
1328
416 ?
S
May30
0:00 /usr/sbin/apmd -p
697
0.0
0.4
3276 1172 ?
S
May30
0:01 /usr/sbin/sshd
lp
737
0.0
0.3
4956
804 ?
S
May30
0:00 lpd Waiting
root
752
0.0
0.3
4016
988 ?
S
May30
0:00 /bin/sh /usr/bin/
mysql
784
0.0
0.4 30648 1040 ?
S
May30
0:00 /usr/libexec/mysq
root
800
0.0
0.6
5108 1704 ?
S
May30
0:03 sendmail: accepti
smmsp
809
0.0
0.5
4924 1520 ?
S
May30
0:00 sendmail: Queue r
Summary
●
●
You should now have a good understanding
of how to use Linux as a user. You can create
and edit files, move them around, copy and
delete them. You should also be able to use
other commands with arguments and know
how to find some information about your
system.
If I were to say that most of the programs
on a system are in the /usr/bin directory, you
should be able to see what is inside it and try
out other programs.