Download Unix Commands

Document related concepts

MTS system architecture wikipedia , lookup

Acorn MOS wikipedia , lookup

RSTS/E wikipedia , lookup

Berkeley Software Distribution wikipedia , lookup

Unix time wikipedia , lookup

Commodore DOS wikipedia , lookup

Burroughs MCP wikipedia , lookup

VS/9 wikipedia , lookup

Unix wikipedia , lookup

CP/M wikipedia , lookup

DNIX wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

Spring (operating system) wikipedia , lookup

Comparison of command shells wikipedia , lookup

Unix security wikipedia , lookup

Transcript
Using Unix
Goals
• Understand the roles of an operating
system.
• Understand the difference between
command-line and GUI.
• Understand some basic Unix
commands.
What is an Operating System?
• It is software.
• Controls the relationship between all
applications and hardware.
• Controls the relationship among
applications.
Command Line Operating Systems
• 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 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?
• Controls the INPUT, OUTPUT, and
PROCESSING activities for the computer
• High-quality O/S can make your computer
more effective and efficient
• A good OS makes the computer easier to
use.
The Roles of an OS
•A
•A
•A
•A
Traffic Cop
Communication System
Box of Tools
Self-Starter
A Traffic Cop
• Controls the resources of the
computer, including memory, file
storage, and CPU.
• Multitasking (the ability for more than
one application to “run” at once) is
possible on new computers.
A Communications System
• Helps all of the hardware components
communicate with each other.
• Helps applications communicate with
the hardware.
• Helps applications communicate with
one another.
A Toolbox
• Several utility programs are included
with an O/S including File
Management, Memory Management,
and Networking Tools.
A Self-Starter
• The OS takes over just after booting.
• Checks to see all hardware is present.
• “Hard Boot” – turning off the
computer and then back on
• “Soft Boot” – restarting the computer
without turning it off first.
Unix
• Developed by Bell Labs in 1969
• Command-Line OS
• Offered File Sharing
• Offered Process-Sharing
Introducing Unix Commands
• Issue commands from a command
prompt:
/:
• Unix is case sensitive!
• Commands are typed in lowercase:
cp (copy) is NOT the same as Cp or
CP
Unix Shells
• Unix has a number of shells which help
the user interact with the Operating
System Kernel (the main program that
stays resident in memory and executes OS
commands).
• Some shells include the Bourne shell,
Korn, Bash, TCSH and Csh.
Command Syntax
• Case sensitive! All commands are
lowercase
• General Format:
command [switches] arg1 arg2
Command
Switch
Arguments
Command Example
• Example:
ls –l *.html
Switch
Command
Argument
Correcting Typographical Errors
• DEL key removes the character to the
left (in some Telnet clients,
BACKSPACE will also do this)
• To erase:
– C-w – Erases previous word
– C-u – Erases an entire line
Directory Structures
• Unix paths begin with a forward slash
• The initial forward slash (/)
represents the root directory
• Typically, only the system administer
has full privileges to the root directory
Directory Paths
• An absolute path begins at the root:
/home/bhecker/public_html/
• A relative path indicates location
relative to your present working
directory:
../images/
More on Directories
• The command pwd will return the
directory name in which you are
currently working
• The directory that represents your
personal section of the server is
called your home directory
Directory Notation
• / - represents a directory
• /. – represents the current directory
• /.. – represents the parent directory
• /~ - represents a user’s home directory
Creating Directories
• Don’t use spaces in directory names.
• Use _ (underscore character) or
camelCasing to name directories.
• Directory names are case sensitive
(usually in lowercase, with camel
casing).
Creating a Directory
• Use the mkdir command:
mkdir campingImages
Name of the directory
Command
File & Directory Permissions
• ls –l command will show full
details, including file name, owner
name, modification date, size and
permission sequence.
Unix Permissions
• Permission sequence found at the
beginning of a directory listing (first
10 characters):
World’s
Permissions
Group’s
Permissions
Owner’s
Permissions
Directory
d rwx r-x r-x
Unix Permissions
• The first character represents
whether the listing is a directory. If it
is a directory, a “d” will appear in the
first character; otherwise, you should
normally see a dash (-).
d rwx
r-x r-x
Unix Permissions
• The remaining nine characters are divided
into three triplets.
• The first triplet represents the owner’s
permissions.
• The second is the group’s permissions.
• The third triplet represents the World’s
permissions.
Read Permission
• 1st position in a triplet: r stands for
Read; grants permission to view the
contents of a file or directory (Value
is ‘r’ or ‘-’).
Write Permission
• 2nd position in a triplet: w stands for
Write; grants permission to modify a
file or the contents of a directory
(Value is ‘w’ or ‘-’).
Execute Permission
• 3rd position in a triplet: x stands for
eXecute; grants permission to run an
application or open a directory (Value
is ‘x’ or ‘-’).
Unix Permissions
• When changing permissions, we must
first decide what number will represent
the permissions for a triplet.
• We can do this by determining whether
or not a permission is turned on or off.
• If turned on, a permission gets a value
of 1; if turned off, it gets a value of 0.
Unix Permissions
• After deciding whether the three
permissions in a triplet are on or off,
we will have a binary number
• We can convert the binary number to
its octal equivalent
Unix Permissions
Permissions
- - - - x
- w - w x
Binary
0 0 0
0 0 1
0 1 0
0 1 1
Octal
0
1
2
3
Unix Permissions
Permissions
r - r – x
r w r w x
Binary
1 0 0
1 0 1
1 1 0
1 1 1
Octal
4
5
6
7
The chmod Command
• Once you’ve established the octal
number representing the permission for
each triplet, you can then use the change
mode (chmod) command to give a
directory or file proper permissions
chmod Syntax & Example
• Syntax:
chmod permissionMask file/dir
• Example:
chmod 755 public_html
• Typically, directories and executable files
are given “755” permissions, while other
files are given “644” permissions
Navigating Unix
• To move from directory to directory,
we use the cd command
• Syntax:
cd path/
Navigating Unix
• To move from a child to a parent
directory:
cd ..
PARENT
CHILD
Navigating Unix
• To move from a grandchild to a
parent directory:
cd ../..
PARENT
CHILD
GRANDCHILD
Navigating Unix
• To move from one child to a
sibling directory:
cd ../child2
PARENT
CHILD1
CHILD2
The List Command
• The list command (ls) shows the
contents of a directory
• We can add switches to the list command
to modify what the command can do
• To use more than one switch, concatenate
them:
ls -lt
List Command Switches
• ls –l shows files in long format,
including permissions
• ls –a shows hidden files
• ls –c shows file listings in a column
format
• ls –t sorts file listings by last
modified date
Using Wildcards with ls
• ls a* Wildcard, All files starting with
'a'
• ls *a* All filenames with 'a' in them
• ls *a*html All filenames with 'a' in
them and ending with html
• ls ????? - All 5 character filenames
Using Wildcards with ls
• ls [abc]* - All filenames starting
with a, b, or c
• ls [a-c]* - Same as above but done
as a range
• ls [^a-c]* - All filenames not
starting with a, b, or c
The Unix Copy Command
• cp can be used to make a copy of a
file, leaving the original file
untouched
• Syntax:
cp oldfile [path/]newfile
The Unix Copy Command
• To make a copy of a file while both
the original and copy are in the same
directory:
cp index.html home.html
The Unix Copy Command
• To make a copy of a file that results
in the copy retaining the original’s
name, but is housed in a different
directory:
cp index.html ../academic/
The Unix Copy Command
• To make a copy of a file that results
in the copy having a new name and is
housed in a different directory:
cp index.html
../academic/home.html
The Unix Move Command
• The mv command has two purposes:
– To move files from one directory to
another
– To rename files
• Syntax:
mv oldfile
newpath/[newfilename]
The Unix Move Command
• To move a file from one directory to
another:
mv index.html ../friends/
The Unix Move Command
• To rename a file (stays in the same
directory):
mv index.html home.html
The Unix Move Command
• To move a file and rename it at the
same time:
mv index.html
../friends/home.html
Deleting Files
• Use rm to delete files
• Syntax:
rm filename
Deleting Files
• To delete a single file:
rm index.html
(answer Y to confirm delete)
• To delete multiple files using a wildcard:
rm *.html
(answer Y to confirm delete for each
file)
Deleting Directories
• Use rmdir to delete directories
• DIRECTORY MUST BE EMPTY!!!!
• Syntax:
rmdir directoryname
• To delete a directory:
rmdir images/
(answer Y to confirm delete)
Other Useful Commands
• passwd – Password utility that
allows users to update their
passwords
• exit – End your Unix session (you
can also use bye)
Other Useful Commands
• clear – Gives you a blank screen
(you can also use cls)
• who – Lists users currently logged in
to the server
Other Useful Commands
• finger username – Retrieves
information about a user
• cal – Displays a calendar of the
current month
• date – Displays the current system
date
Other Useful Commands
• !! – (pronounced “bang bang”)
repeats the last command
• ![a..z] – Repeats the last
command beginning with selected
letter (a-z)
Other Useful Commands
• |more – Added to commands which
display lists to force page stops (Ex:
ls –lt |more)
• C-z – Temporarily stop a process
Other Useful Commands
• fg – Bring a process to the
foreground after it has been stopped
• vacation – Turn on the auto-reply
for e-mail
• pine – Launch the Pine E-mail client
• emacs – Start the Emacs editor
Online Manual
• Eight Sections
– Commands
– System calls
– Library functions
– Devices and device
drivers
– File formats
– Games
– Miscellaneous
– System
maintenance
Using man
• man command
• To lookup help on the cp command:
man cp
• To lookup help on the ls command:
man ls
• C-c exits the manual.
Questions?