Operating Systems and Using Linux Topics What is an Operating System? Linux Overview

advertisement
Operating Systems and Using Linux
Topics
• What is an Operating System?
• Linux Overview
• Frequently Used Linux Commands
Reading
None.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
1
What is an Operating System (OS)?
• A computer program
• Performs many operations, such as:
• Allows you to communicate with the computer
(tell it what to do)
• Controls access (login) to the computer
• Keeps track of all processes currently running
• At this point, your main concern is how to
communicate with the computer using the OS
CMSC 104, Version 8/06
L03OperatingSystems.ppt
2
What Is A Process?
• A process is a task or program that you
have requested the operating system do on
your behalf.
• That process is given an identifying number,
called a PID (process ID).
CMSC 104, Version 8/06
L03OperatingSystems.ppt
3
How Do I Communicate With the Computer
Using the OS?
• You communicate using the operating
system’s user interface.
• Graphical User Interface (GUI) –
Microsoft Windows, Linux KDE
• Command-driven interface - DOS,
UNIX, Linux, Microsoft Command Prompt
• We will be using the Linux operating
system, which is very similar to UNIX.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
4
How Do I Communicate With the Computer
Using the OS? (con’t)
• When you log in to the Linux system here, a user
prompt will be displayed:
linux#[1]% _
where # is the number of the Linux server that you have
connected to. You may use any of the Linux servers.
• The number in the brackets will change as you work. It is
the “number” of the command that you are about to type.
• If this prompt is not on the screen at any time, you are not
communicating with the OS.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
5
User Prompt
• While the normal (or default) prompt is:
linux#[1]%
you can change this.
• To learn Linux well enough to do this, we recommend
that you take CMSC121, a one credit course.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
6
Linux Overview
• Files and Filenames
• Directories and Subdirectories
• Frequently Used Commands
CMSC 104, Version 8/06
L03OperatingSystems.ppt
7
Files
• A file is a sequence of bytes.
• It can be created by
o
o
a text editor (xemacs or pico)
a computer program (such as a C program)
• It may contain a program, data, a
document, or other information .
• Files that contain other files are called
directories (sometimes called folders).
CMSC 104, Version 8/06
L03OperatingSystems.ppt
8
Linux Filenames
• Restrictions
o
o
o
May not contain blanks or other reserved characters.
Have a maximum length (however, make your
filenames long enough to be useful and short enough to
type without making a mistake.
Are case sensitive.
• It is best to stick with filenames that contain letters
(uppercase or lowercase), numbers, and the
underscore ( _ ) for now.
• Filenames that start with a period are hidden files,
so that when see the files in a directory, they don’t
show up.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
9
Directories
• Directories contain files or other directories
called subdirectories. They may also be
empty.
• Directories are organized in a hierarchical
fashion, or directories can contain other
directories.
• They help us to keep our files organized.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
10
Directories (con’t)
/afs/umbc.edu/users/j/d/jdoe28
junk
recipes
pies
apple
CMSC 104, Version 8/06
notes
cookies
peach
CMSC104
choc_chip
L03OperatingSystems.ppt
11
Directories (con’t)
• One example is to have a directory for
CMSC104.
• Inside you could have a directory for each
project, and whatever.
• Rule of Thumb: Never have more files in
one directory than fits on the screen when
you list them.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
12
Directories (con’t)
• Your home directory is where you are located
when you log in (e.g., /afs/umbc.edu/users/j/d/jdoe28).
• The current directory is where you are located at
any time while you are using the system.
• Files within the same directory must be given
unique names.
• Paths allow us to give the same name to different
files located in different directories.
• Each running program has a current directory and
all filenames are implicitly assumed to start with the
name of that directory unless they begin with a
slash.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
13
Subdirectories
• Are used for organizing your files
• For example,
o
o
make a subdirectory for CMSC104
make subdirectories for each project
CMSC104
project1
CMSC 104, Version 8/06
project2
...
L03OperatingSystems.ppt
project8
14
Moving in the Directory Tree
• . (dot) is the current directory.
• . . (dot-dot) is the parent directory.
• Use the Linux command cd to change
directories.
• Use dot-dot to move up the tree.
• Use the directory name to move down.
• Use the complete directory name (path
name) to move anywhere.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
15
Pathnames
• Pathnames that start at the beginning (and start
with a /):
/afs/umbc.edu/users/j/d/jdoe28
are called absolute pathnames.
• Pathnames can be shorted, so that if jdoe28 is the
current directory and we have a file in that
directory call schedule, we can edit it with just the
filename (a relative pathname):
pico schedule
CMSC 104, Version 8/06
L03OperatingSystems.ppt
16
Permissions
• Files and directories have permissions.
• There are three sets of permissions for
three groups:
o
o
Read, write, execute (or, if a directory, access)
User, group, other
• You are the user, and can set and change
permissions.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
17
Frequently Used Linux Commands
• passwd, man, lpr
• pwd, ls, cat, more, cd, cp, mv, rm
• mkdir, rmdir
• ctrl-c, ctrl-z
References:
• Linux man pages
• Links from the 104 homepage
• Books and the Internet
CMSC 104, Version 8/06
L03OperatingSystems.ppt
18
Linux Command Format
• Fromat: cmd options arguments
• Options and arguments are optional.
• Options start with - or - • Options are different for each command.
• Arguments are different for each command.
• When in doubt, look up the command in the
on-line help, man.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
19
man
• On-line help.
• Argument is the command you wish to have
help for.
• Option –k is most common, which looks for
a description that contains the argument.
• When the description of a command takes
more than one screen to display, press the
space bar for more information and q to
quit.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
20
man (cont’d)
• Example:
[burt@linux1 ~]$ man -k passwd
htpasswd
htpasswd (1) - Create and update user authentication
files
kpasswd
kpasswd (1) - change a user's Kerberos password
mkpasswd
mkpasswd (1) - generate new password, optionally
apply it to a user
passwd.nntp passwd.nntp (5) - passwords for connecting to remote
NNTP servers
saslpasswd
saslpasswd (8) - set a user's sasl password
saslpasswd2 saslpasswd2 (8) - set a user's sasl password
v5passwd
v5passwd (1) - change a user's Kerberos password
CMSC 104, Version 8/06
L03OperatingSystems.ppt
21
passwd
• Used to change your password.
NAME
passwd - update a user's
authentication tokens(s)
SYNOPSIS
passwd [-k] [-l] [-u [-f]] [-d] [-n mindays] [-x
maxdays] [-w warndays] [-i inactivedays] [S] [username]
CMSC 104, Version 8/06
L03OperatingSystems.ppt
22
lpr
• Used to print something on the printer.
• You must pay per page.
• Pick up your print-out at ECS-019.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
23
cd
• Change directory.
• With no argument, it will take you back to
your home directory.
• With a argument, it will set that directory to
be your current working directory, assuming
you have permission to access the
directory.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
24
pwd
• Print the current working directory.
• Helpful when you forget where you are.
• Has no options or arguments.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
25
ls
• Lists the names of files in a directory.
• Arguments are name(s) of file(s) and/or
director(ies).
• Normally, when you specify a directory, you
get the contents of the directory.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
26
ls Options
• -a all (including hidden files)
• -d just show the directory, not the files in the
directory
• -F classify files as ordinary, directory (/), or
executable (*)
• --color classify with color
• -l long format
• -r show in reverse order
• -R recursive, show the contents of all
subdirectories.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
27
cat
• Used to display the contents of a file.
• If there is too much to fit on the screen, the
first part scrolls off and leaves only the last
screenful.
• Argument is the name of a file or files.
• Useful option is –n (or –number) to show
the line numbers.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
28
more
• More shows a screen full of a file at a time.
SYNOPSIS
more [-dlfpcsu] [-num] [+/ pattern] [+ linenum] [file]
DESCRIPTION
More is a filter for paging through text one
screenful at a time. This version is especially
primitve. Users should realize that less(1)
provides more(1) emulation and extensive
enhancements.
• Less is a similar command with more features.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
29
cp
• This allows you to create a new copy of an
existing file.
• Two mandatory arguments, source and
destination.
o
o
Source is the name of the existing file.
Destination is the name for new file.
• If you change the contents of the new file,
you do not change the contents of the old
file.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
30
ln
• Allows you to create two names for one file
by “linking” them, similar to a shortcut in
Microsoft Windows.
• Two mandatory options are the source and
destination, just like for cp.
• If you change the new version, you change
the old version.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
31
mv
• This allows you to rename a file and/or
move it to a new location.
• Two mandatory arguments, source and
destination.
o
o
Source is the name of the existing file.
Destination is the new name and/or location for
the existing file.
• At completion, there is only one file.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
32
rm
• Allows you to remove or delete a file.
• Normally, once a file is removed, it is gone
forever!
• (UMBC has changed this and it moves the
file to a backup directory, where you can
recover it, if necessary. However, this is not
a long-term option!)
CMSC 104, Version 8/06
L03OperatingSystems.ppt
33
rm (cont’d)
• The argument(s) are a list of files to remove.
• Options include:
o
o
-iinteractive, ask first (UMBC has set this as the default)
-r
recursive, delete the files in the subdirectories
and the subdirectories.
• NOTE: rm –r directory will remove directories that
are not empty!
CMSC 104, Version 8/06
L03OperatingSystems.ppt
34
mkdir
• Used to create a new directory.
• Argument(s) is/are the name(s) of the new
directory(ies).
CMSC 104, Version 8/06
L03OperatingSystems.ppt
35
Wildcard Characters
• You will find wildcard characters useful
when manipulating files (e.g., listing or
moving them).
• The wildcard characters are * and ?
• ? is used to represent any single character.
• * is used to represent 0 or more characters.
CMSC 104, Version 8/06
L03OperatingSystems.ppt
36
Download