CMSC 104, Version 8/06 L03OperatingSystems.ppt Operating Systems and Using Linux Topics • What is an Operating System? • Linux Overview • Frequently Used Linux Commands Reading None.
Feb 13, 2016
CMSC 104, Version 8/06 1L03OperatingSystems.ppt
Operating Systems and Using Linux
Topics
• What is an Operating System?• Linux Overview• Frequently Used Linux Commands
Reading
None.
CMSC 104, Version 8/06 2L03OperatingSystems.ppt
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 3L03OperatingSystems.ppt
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 4L03OperatingSystems.ppt
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 5L03OperatingSystems.ppt
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 6L03OperatingSystems.ppt
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 7L03OperatingSystems.ppt
Linux Overview
• Files and Filenames• Directories and Subdirectories• Frequently Used Commands
CMSC 104, Version 8/06 8L03OperatingSystems.ppt
Files
• A file is a sequence of bytes.• It can be created by
o a text editor (xemacs or pico)o 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 9L03OperatingSystems.ppt
Linux Filenames
• Restrictionso May not contain blanks or other reserved characters.o Have a maximum length (however, make your
filenames long enough to be useful and short enough to type without making a mistake.
o 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 10L03OperatingSystems.ppt
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 11L03OperatingSystems.ppt
Directories (con’t)
/afs/umbc.edu/users/j/d/jdoe28
junk recipes notes
pies cookies CMSC104
apple peach choc_chip
CMSC 104, Version 8/06 12L03OperatingSystems.ppt
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 13L03OperatingSystems.ppt
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 14L03OperatingSystems.ppt
Subdirectories
• Are used for organizing your files• For example,
o make a subdirectory for CMSC104o make subdirectories for each project
CMSC104
project1 project2 . . . project8
CMSC 104, Version 8/06 15L03OperatingSystems.ppt
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 16L03OperatingSystems.ppt
Pathnames
• Pathnames that start at the beginning (and start with a /): /afs/umbc.edu/users/j/d/jdoe28are 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 17L03OperatingSystems.ppt
Permissions
• Files and directories have permissions.• There are three sets of permissions for
three groups:o Read, write, execute (or, if a directory, access)o User, group, other
• You are the user, and can set and change permissions.
CMSC 104, Version 8/06 18L03OperatingSystems.ppt
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 19L03OperatingSystems.ppt
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 20L03OperatingSystems.ppt
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 21L03OperatingSystems.ppt
man (cont’d)
• Example:[burt@linux1 ~]$ man -k passwd
htpasswd htpasswd (1) - Create and update user authentication fileskpasswd 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 passwordsaslpasswd2 saslpasswd2 (8) - set a user's sasl password
v5passwd v5passwd (1) - change a user's Kerberos password
CMSC 104, Version 8/06 22L03OperatingSystems.ppt
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 23L03OperatingSystems.ppt
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 24L03OperatingSystems.ppt
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 25L03OperatingSystems.ppt
pwd
• Print the current working directory.• Helpful when you forget where you are.• Has no options or arguments.
CMSC 104, Version 8/06 26L03OperatingSystems.ppt
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 27L03OperatingSystems.ppt
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 28L03OperatingSystems.ppt
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 29L03OperatingSystems.ppt
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 30L03OperatingSystems.ppt
cp
• This allows you to create a new copy of an existing file.
• Two mandatory arguments, source and destination.o Source is the name of the existing file.o 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 31L03OperatingSystems.ppt
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 32L03OperatingSystems.ppt
mv
• This allows you to rename a file and/or move it to a new location.
• Two mandatory arguments, source and destination.o Source is the name of the existing file.o Destination is the new name and/or location for
the existing file.• At completion, there is only one file.
CMSC 104, Version 8/06 33L03OperatingSystems.ppt
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 34L03OperatingSystems.ppt
rm (cont’d)
• The argument(s) are a list of files to remove.• Options include:
o -i interactive, ask first (UMBC has set this as the default)
o -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 35L03OperatingSystems.ppt
mkdir
• Used to create a new directory.• Argument(s) is/are the name(s) of the new
directory(ies).
CMSC 104, Version 8/06 36L03OperatingSystems.ppt
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.