Using Unix
description
Transcript of Using Unix
Using UnixUsing Unix
GoalsGoals• Understand the roles of an Understand the roles of an
operating system.operating system.• Understand the difference Understand the difference
between command-line and GUI.between command-line and GUI.• Understand some basic Unix Understand some basic Unix
commands.commands.
What is an Operating What is an Operating System?System?
• It is software.It is software.• Controls the relationship Controls the relationship
between all applications and between all applications and hardware.hardware.
• Controls the relationship among Controls the relationship among applications.applications.
Command Line Operating Command Line Operating SystemsSystems
• Use letters with symbols, such as C:\>.
• Instructions must be typed. • High rate of error – typos!• Some examples of command line
operating systems include DOS and Unix.
GUI Operating SystemsGUI Operating Systems• GUI - Graphic User Interface• Include pictures with descriptive
words (icons)• Much easier to move the pointer with
the mouse and click on a picture, than to remember commands.
• Examples of GUI operating systems include Windows and MAC OS.
So, What Does an OS Do?So, What Does an OS Do?• Controls the INPUT, OUTPUT, and Controls the INPUT, OUTPUT, and
PROCESSING activities for the PROCESSING activities for the computercomputer
• High-quality O/S can make your High-quality O/S can make your computer more effective and computer more effective and efficient efficient
• A good OS makes the computer A good OS makes the computer easier to use.easier to use.
The Roles of an OSThe Roles of an OS
• A Traffic CopA Traffic Cop• A Communication SystemA Communication System• A Box of ToolsA Box of Tools• A Self-StarterA Self-Starter
A Traffic CopA Traffic Cop• Controls the resources of the Controls the resources of the
computer, including memory, file computer, including memory, file storage, and CPU. storage, and CPU.
• Multitasking (the ability for more Multitasking (the ability for more than one application to “run” at than one application to “run” at once) is possible on new once) is possible on new computers. computers.
A Communications SystemA Communications System• Helps all of the hardware Helps all of the hardware
components communicate with components communicate with each other. each other.
• Helps applications communicate Helps applications communicate with the hardware.with the hardware.
• Helps applications communicate Helps applications communicate with one another.with one another.
A ToolboxA Toolbox• Several utility programs are Several utility programs are
included with an O/S including included with an O/S including File Management, Memory File Management, Memory Management, and Networking Management, and Networking Tools.Tools.
A Self-StarterA Self-Starter• The OS takes over just after booting.The OS takes over just after booting.• Checks to see all hardware is present.Checks to see all hardware is present.• ““Hard Boot” – turning off the Hard Boot” – turning off the
computer and then back oncomputer and then back on• ““Soft Boot” – restarting the computer Soft Boot” – restarting the computer
without turning it off first.without turning it off first.
UnixUnix
• Developed by Bell Labs in 1969Developed by Bell Labs in 1969• Command-Line OSCommand-Line OS• Offered File Sharing Offered File Sharing • Offered Process-SharingOffered Process-Sharing
Introducing Unix CommandsIntroducing Unix Commands• Issue commands from a command Issue commands from a command
prompt:prompt:/:/:
• Unix is case sensitive!Unix is case sensitive!• Commands are typed in lowercase:Commands are typed in lowercase:cpcp (copy) is NOT the same as (copy) is NOT the same as CpCp or or CPCP
Unix ShellsUnix Shells• Unix has a number of shells which Unix has a number of shells which
help the user interact with the help the user interact with the Operating System Kernel (the main Operating System Kernel (the main program that stays resident in program that stays resident in memory and executes OS memory and executes OS commands).commands).
• Some shells include the Bourne shell, Some shells include the Bourne shell, Korn, Bash, TCSH and Csh.Korn, Bash, TCSH and Csh.
Command SyntaxCommand Syntax• Case sensitive! All commands Case sensitive! All commands
are lowercaseare lowercase• General Format:General Format:command [switches] arg1 arg2command [switches] arg1 arg2
Command Switch Arguments
Command ExampleCommand Example• Example:Example:ls –l *.htmlls –l *.html
Command
Switch
Argument
Correcting Typographical Correcting Typographical ErrorsErrors
• DEL key removes the character DEL key removes the character to the left (in some Telnet to the left (in some Telnet clients, BACKSPACE will also do clients, BACKSPACE will also do this)this)
• To erase:To erase:– C-w – Erases previous wordC-w – Erases previous word– C-u – Erases an entire lineC-u – Erases an entire line
Directory StructuresDirectory Structures• Unix paths begin with a forward Unix paths begin with a forward
slashslash• The initial forward slash (/) The initial forward slash (/)
represents the root directoryrepresents the root directory• Typically, only the system Typically, only the system
administer has full privileges to administer has full privileges to the root directorythe root directory
Directory PathsDirectory Paths• An absolute path begins at the An absolute path begins at the
root:root:/home/bhecker/public_html//home/bhecker/public_html/
• A relative path indicates location A relative path indicates location relativerelative to your present working to your present working directory:directory:../images/../images/
More on DirectoriesMore on Directories• The command The command pwdpwd will return the will return the
directory name in which you are directory name in which you are currently workingcurrently working
• The directory that represents The directory that represents your personal section of the your personal section of the server is called your home server is called your home directorydirectory
Directory NotationDirectory Notation• / / - represents a directory- represents a directory• /. /. – represents the current directory– represents the current directory• /../.. – represents the parent directory – represents the parent directory• /~ /~ - represents a user’s home - represents a user’s home
directorydirectory
Creating DirectoriesCreating Directories• Don’t use spaces in directory Don’t use spaces in directory
names.names.• Use _ (underscore character) or Use _ (underscore character) or
camelCasing to name directories.camelCasing to name directories.• Directory names are case Directory names are case
sensitive (usually in lowercase, sensitive (usually in lowercase, with camel casing).with camel casing).
Creating a DirectoryCreating a Directory• Use the mkdir command:Use the mkdir command:mkdir campingImagesmkdir campingImages
Command
Name of the directory
File & Directory PermissionsFile & Directory Permissions• ls –lls –l command will show full command will show full
details, including file name, details, including file name, owner name, modification date, owner name, modification date, size and permission sequence.size and permission sequence.
Unix PermissionsUnix Permissions• Permission sequence found at Permission sequence found at
the beginning of a directory the beginning of a directory listing (first 10 characters):listing (first 10 characters):
dd rwxrwx r-xr-x r-xr-x
Dire
ctor
yD
irect
ory
Ow
ner’s
O
wne
r’s
Perm
issi
ons
Perm
issi
ons
Gro
up’s
G
roup
’s
Perm
issi
ons
Perm
issi
ons
Wor
ld’s
W
orld
’s
Perm
issi
ons
Perm
issi
ons
Unix PermissionsUnix Permissions• The first character represents The first character represents
whether the listing is a directory. If whether the listing is a directory. If it is a directory, a “d” will appear it is a directory, a “d” will appear in the first character; otherwise, in the first character; otherwise, you should normally see a dash (-).you should normally see a dash (-).
dd rwx rwx r-xr-x r-xr-x
Unix PermissionsUnix Permissions• The remaining nine characters are The remaining nine characters are
divided into three triplets.divided into three triplets.• The first triplet represents the owner’s The first triplet represents the owner’s
permissions.permissions.• The second is the group’s permissions.The second is the group’s permissions.• The third triplet represents the The third triplet represents the
World’s permissions.World’s permissions.
Read PermissionRead Permission• 11stst position in a triplet: position in a triplet: r r stands stands
for for RRead; grants permission to ead; grants permission to view the contents of a file or view the contents of a file or directory (Value is ‘r’ or ‘-’).directory (Value is ‘r’ or ‘-’).
Write PermissionWrite Permission• 22ndnd position in a triplet: position in a triplet: w w stands stands
for for WWrite; grants permission to rite; grants permission to modify a file or the contents of a modify a file or the contents of a directory (Value is ‘w’ or ‘-’).directory (Value is ‘w’ or ‘-’).
Execute PermissionExecute Permission• 33rd rd position in a triplet: position in a triplet: xx stands stands
for efor eXXecute; grants permission to ecute; grants permission to run an application or open a run an application or open a directory (Value is ‘x’ or ‘-’).directory (Value is ‘x’ or ‘-’).
Unix PermissionsUnix Permissions• When changing permissions, we must When changing permissions, we must
first decide what number will represent first decide what number will represent the permissions for a triplet.the permissions for a triplet.
• We can do this by determining whether We can do this by determining whether or not a permission is turned on or off.or not a permission is turned on or off.
• If turned on, a permission gets a value If turned on, a permission gets a value of 1; if turned off, it gets a value of 0.of 1; if turned off, it gets a value of 0.
Unix PermissionsUnix Permissions• After deciding whether the three After deciding whether the three
permissions in a triplet are on or permissions in a triplet are on or off, we will have a binary numberoff, we will have a binary number
• We can convert the binary We can convert the binary number to its octal equivalentnumber to its octal equivalent
Unix PermissionsUnix Permissions
PermissionPermissionss BinaryBinary OctalOctal
- - -- - - 0 0 00 0 0 00- - x- - x 0 0 10 0 1 11- w -- w - 0 1 00 1 0 22- w x- w x 0 1 10 1 1 33
Unix PermissionsUnix Permissions
PermissionPermissionss BinaryBinary OctalOctal
r - -r - - 1 0 01 0 0 44r – xr – x 1 0 11 0 1 55r w -r w - 1 1 01 1 0 66r w xr w x 1 1 11 1 1 77
The chmod CommandThe chmod Command• Once you’ve established the octal Once you’ve established the octal
number representing the permission number representing the permission for each triplet, you can then use for each triplet, you can then use the change mode (the change mode (chmodchmod) command ) command to give a directory or file proper to give a directory or file proper permissionspermissions
chmod Syntax & Examplechmod Syntax & Example• Syntax:Syntax:chmod permissionMask file/dirchmod permissionMask file/dir
• Example:Example:chmod 755 public_htmlchmod 755 public_html
• Typically, directories and executable Typically, directories and executable files are given “755” permissions, files are given “755” permissions, while other files are given “644” while other files are given “644” permissionspermissions
Navigating UnixNavigating Unix• To move from directory to To move from directory to
directory, we use the directory, we use the cdcd commandcommand
• Syntax:Syntax:cd path/cd path/
Navigating UnixNavigating Unix•To move from a child to a To move from a child to a
parent directory:parent directory:cd ..cd ..
PARENT
CHILD
Navigating UnixNavigating Unix•To move from a grandchild to To move from a grandchild to
a parent directory:a parent directory:cd ../..cd ../..
PARENT
CHILD
GRANDCHILD
Navigating UnixNavigating Unix•To move from one child to a To move from one child to a
sibling directory:sibling directory:cd ../child2cd ../child2
PARENT
CHILD1 CHILD2
The List CommandThe List Command• The list command (The list command (lsls) shows the ) shows the
contents of a directorycontents of a directory• We can add switches to the list We can add switches to the list
command to modify what the command to modify what the command can docommand can do
• To use more than one switch, To use more than one switch, concatenate them:concatenate them:ls -ltls -lt
List Command SwitchesList Command Switches• ls –lls –l shows files in long format, shows files in long format,
including permissions including permissions • ls –als –a shows hidden files shows hidden files• ls –cls –c shows file listings in a shows file listings in a
column formatcolumn format• ls –tls –t sorts file listings by last sorts file listings by last
modified datemodified date
Using Wildcards with Using Wildcards with lsls• ls a*ls a* Wildcard, All files starting Wildcard, All files starting
with 'a' with 'a' • ls *a*ls *a* All filenames with 'a' in All filenames with 'a' in
them them • ls *a*htmlls *a*html All filenames with 'a' in All filenames with 'a' in
them and ending with htmlthem and ending with html• ls ?????ls ????? - All 5 character filenames - All 5 character filenames
Using Wildcards with Using Wildcards with lsls• ls [abc]*ls [abc]* - All filenames starting - All filenames starting
with a, b, or c with a, b, or c • ls [a-c]*ls [a-c]* - Same as above but - Same as above but
done as a range done as a range • ls [^a-c]*ls [^a-c]* - All filenames not - All filenames not
starting with a, b, or c starting with a, b, or c
The Unix Copy CommandThe Unix Copy Command• cp cp can be used to make a copy can be used to make a copy
of a file, leaving the original file of a file, leaving the original file untoucheduntouched
• Syntax:Syntax:cp oldfile [path/]newfilecp oldfile [path/]newfile
The Unix Copy CommandThe Unix Copy Command• To make a copy of a file while To make a copy of a file while
both the original and copy are in both the original and copy are in the the samesame directory: directory:
cp index.html home.htmlcp index.html home.html
The Unix Copy CommandThe Unix Copy Command• To make a copy of a file that To make a copy of a file that
results in the copy retaining the results in the copy retaining the original’s nameoriginal’s name, but is housed in , but is housed in a different directory:a different directory:
cp index.html ../academic/cp index.html ../academic/
The Unix Copy CommandThe Unix Copy Command• To make a copy of a file that To make a copy of a file that
results in the copy having a results in the copy having a new new namename and is housed in a different and is housed in a different directory:directory:
cp index.html cp index.html ../academic/home.html../academic/home.html
The Unix Move CommandThe Unix Move Command• The The mvmv command has two purposes: command has two purposes:
– To move files from one directory to To move files from one directory to anotheranother
– To rename filesTo rename files• Syntax:Syntax:mv oldfile mv oldfile newpath/[newfilename]newpath/[newfilename]
The Unix Move CommandThe Unix Move Command• To move a file from one directory To move a file from one directory
to another:to another:
mv index.html ../friends/mv index.html ../friends/
The Unix Move CommandThe Unix Move Command• To rename a file (stays in the To rename a file (stays in the
same directory):same directory):
mv index.html home.htmlmv index.html home.html
The Unix Move CommandThe Unix Move Command• To move a file To move a file andand rename it at rename it at
the same time:the same time:
mv index.html mv index.html ../friends/home.html../friends/home.html
Deleting FilesDeleting Files• Use Use rmrm to delete files to delete files• Syntax:Syntax:
rm filenamerm filename
Deleting FilesDeleting Files• To delete a single file:To delete a single file:rm index.htmlrm index.html(answer Y to confirm delete)(answer Y to confirm delete)
• To delete multiple files using a wildcard:To delete multiple files using a wildcard:rm *.htmlrm *.html(answer Y to confirm delete for each (answer Y to confirm delete for each file)file)
Deleting DirectoriesDeleting Directories• Use Use rmdirrmdir to delete directories to delete directories• DIRECTORY MUST BE EMPTYDIRECTORY MUST BE EMPTY!!!!!!!!• Syntax:Syntax:rmdir directorynamermdir directoryname
• To delete a directory:To delete a directory:rmdir images/rmdir images/(answer Y to confirm delete)(answer Y to confirm delete)
Other Useful CommandsOther Useful Commands• passwd passwd – Password utility that – Password utility that
allows users to update their allows users to update their passwordspasswords
• exit exit – End your Unix session – End your Unix session (you can also use (you can also use byebye))
Other Useful CommandsOther Useful Commands• clear clear – Gives you a blank – Gives you a blank
screen (you can also use screen (you can also use clscls))• who who – Lists users currently – Lists users currently
logged in to the serverlogged in to the server
Other Useful CommandsOther Useful Commands• finger username finger username – Retrieves – Retrieves
information about a userinformation about a user• cal cal – Displays a calendar of the – Displays a calendar of the
current monthcurrent month• date date – Displays the current – Displays the current
system datesystem date
Other Useful CommandsOther Useful Commands• !! !! – (pronounced “bang bang”) – (pronounced “bang bang”)
repeats the last commandrepeats the last command• ![a..z]![a..z] – Repeats the last – Repeats the last
command beginning with command beginning with selected letter (a-z)selected letter (a-z)
Other Useful CommandsOther Useful Commands• |more|more – Added to commands – Added to commands
which display lists to force page which display lists to force page stops (Ex: stops (Ex: ls –lt |morels –lt |more))
• C-z C-z – Temporarily stop a process– Temporarily stop a process
Other Useful CommandsOther Useful Commands• fg fg – Bring a process to the – Bring a process to the
foreground after it has been foreground after it has been stoppedstopped
• vacation vacation – Turn on the auto-reply – Turn on the auto-reply for e-mailfor e-mail
• pine pine – Launch the Pine E-mail – Launch the Pine E-mail clientclient
• emacs emacs – Start the Emacs editor– Start the Emacs editor
Online ManualOnline Manual• Eight SectionsEight Sections
– CommandsCommands– System callsSystem calls– Library functionsLibrary functions– Devices and device Devices and device
driversdrivers
– File formatsFile formats– GamesGames– MiscellaneousMiscellaneous– System System
maintenancemaintenance
Using Using manman• man commandman command• To lookup help on the To lookup help on the cpcp command: command:man cpman cp
• To lookup help on the To lookup help on the lsls command: command:man lsman ls
• C-cC-c exits the manual. exits the manual.
Questions?Questions?