0% found this document useful (0 votes)
8 views

COMP 201 OpenSource L3 UnixFilesys

Uploaded by

michellesparks
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

COMP 201 OpenSource L3 UnixFilesys

Uploaded by

michellesparks
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 74

COMP 201 OPEN SOURCE &

SYSTEM ADMINISTRATION
DANIEL OBUOBI
BASIC OF UNIX & FILE SYSTEM
Basics of UNIX
Getting Started With UNIX
Section A: Objectives
After studying this lesson, you should be able to:
– Define operating systems in general
– Describe what a UNIX shell is
– Describe the options for connecting to a
UNIX system
– Log on to and log out of UNIX
Getting Started With UNIX
Section A: Objectives (Contd)
After studying this lesson, you should be able to:
– Use the date, cal, who, finger, clear, man,
whatis, whereis, whoami, and passwd
commands
– Recall a command from the command
history
– Use Pine to check email on CSE
What is an Operating System?

• An operating system (OS) is the most


important program that runs on a computer.
• Primary purpose is to facilitate:
– Easy, efficient, fair, orderly and secure use of hardware and
software resources.
• Allows users to employ application software,
language libraries, system calls and program
generation tools.
Layered View of a Computer System
Types of Operating Systems

• Single-user, single-process system


– Historic, but rare (only a few PDAs use this)
• Single-user, multiprocess system
– Some PCs and workstations may be configured like this.
e.g., Windows 95, OS/2
• Multiuser, multiprocess system
– Commonly used on computers that support multiple users
in organizations such as universities and large businesses .
e.g. UNIX, Linux, WindowsNT Server
Introducing the UNIX Operating System

• UNIX is a multi-user, multiprocess operating


system.
• A multi-user system lets many people
simultaneously access and share the resources
of a server computer.
• A multiprocess system lets one user run more
than one process at a time.
• UNIX is also a portable operating system.
Introducing the UNIX Operating System (Contd)

• Its portability means it can be used in a variety of


computing environments.
– Traditionally, most operating systems were written in Assembler, for a
specific architecture.
– VERY painful - if at all possible - to ‘port' the operating system to other
architectures.
• UNIX is mostly written in the C language. This alone
allows UNIX to be portable to many architectures.
• UNIX/LINUX runs on a wider variety of computers
than any other operating system.
A Brief History of UNIX

• A group of programmers at Bell Labs originally


developed UNIX in the early 1970s.
• Bell Labs distributed UNIX in its source code form,
so anyone who used UNIX could customize it as
needed.
• Eventually, two standard version of UNIX evolved:
– AT&T produced System V (1983)
– University of California at Berkeley developed BSD
(Berkeley System Distribution, 2BSD, 1978)
Layers of a UNIX System

Hardware

Kernel
System Calls

Shells, ls, cp, etc.

Netscape, vi, pine, etc.


UNIX Software Architecture
(Contd)
Introducing UNIX Shells

• The UNIX shell is a program that starts running when


you log on and interprets the commands that you
enter from the keyboard.
Introducing UNIX Shells (Contd)

• UNIX provides several shells, including the


Bourne shell (sh), the Korn shell (ksh), and the
C shell (csh).
• The Bourne Again shell (bash), TC shell (tcsh)
and Z shell (zsh) are relatively new and are
more popular with LINUX systems.
Various UNIX Shells
Logging On to UNIX

• After you connect to a UNIX system, you must


log on by entering your user name and
password.

• For security reasons, the password does not


appear on the screen as you type it.
Connecting to UNIX using PuTTY or Telnet

• PuTTY is a free implementation of Telnet and SSH for Win32 and Unix
platforms.
– Much better than using Telnet, more secure and easier to use
• Telnet is a terminal emulation program for the Internet.
• SSH (Secure Shell) is for UNIX/LINUX systems to provide
authentication security for TCP/IP applications, such as FTP and
Telnet. It can encrypt communications as they go across a network or
the Internet.

• Each computer on the Internet has an Internet Protocol (IP) address.


• An IP address is a set of four numbers separated by periods, such as
129.93.165.2
• Most systems on the Internet also have a domain name such as
cse.unl.edu.
Connecting to UNIX via PuTTY
Connecting to UNIX via PuTTY (Contd)
Connecting to UNIX via Telnet
Connecting to UNIX via Telnet (Contd)
Entering Commands

• UNIX philosophy: it assumes users know what they


are doing.
• UNIX is command-line based system. It is important
to remember commands and their usage.
• Commands in UNIX are programs.
• UNIX is case-sensitive, that is, it distinguishes
between uppercase and lowercase letters, so that
date differs from Date
• You type most UNIX commands in lowercase.
Structure of a UNIX command

$ command [ - option (s) ] [ option argument (s) ] [ command argument (s) ]

where:
$ is system prompt ($ for Bourne Shell, % for C shell)
command is the name of the valid UNIX command for that shell in lowercase
letters
[-option(s)] is one or more modifiers that change the behavior of command
[option argument(s)] is one or more modifiers that change the behavior of [-
option(s)]
[command argument(s)] is one or more objects that are affected by command,
generally, files or pathnames

A space seperates command, options, option arguments and command arguments, but no
space is necessary between multiple options or multiple option arguments. And a
space is optional between the option and option argument.
Structure of a UNIX command (Contd)

$ command [ -option (s) ] [ option argument (s) ] [ command argument (s) ]

Examples:
• $ ls
– Contains only the command ls
• $ ls -la
– Contains the command ls and two options, l and a
• $ ls -la m*
– Contains the command ls; two options, l and a;
and a command argument, m*
• $ lpr -Pspr -n 3 proposal.ps
– Contains the command lpr; two options, P and n;
two option arguments, spr and 3; and a command
argument, proposal.ps
The date Command

• Use the UNIX date command to display


the system date, which the system
administrator maintains
date
The cal Command

• Display the calendar of current month


cal
• Display the calendar of 2004
cal 2004
• Display the calendar of July 1775
cal 7 1775
The who and finger Commands

• In a multi-user system, knowing who is logged on


to the system may be helpful

• Use the who command to see who is using the


system and their current location
who

• User finger command to know the detailed


information for a specific user
finger username
The clear Command

• You can use the clear command to


clear your screen; it has no options or
arguments.
clear
Command-line History

The Command-line History


– Access the command history with the up and
down arrow keys
– Pressing the up arrow key once recalls the most
recently used command
– Each time you press the up arrow key, you recall
an older command
– Each time you press the down arrow key, you
scroll forward in the command history
The man Program

• For reference, UNIX includes an online manual that contains


all commands, including their options and arguments
• The man program in UNIX displays this online manual, called
the man pages, for command-line assistance
man who

– Press the <Space> key on the keyboard shows you more manual
pages, one screen at a time
– Press Ctrl+B to go back to previous screen
– Press <q> to quit man pages and return to the command line prompt
The whatis Command

• Sometimes you find that the man pages contain


more information than you want to see
• To display a brief summary of a command, use the
whatis command
• The whatis command shows only the name and
brief description that appears near the top of a
command’s man page
whatis who
The whereis Command

• Locate the binary, source, and man page


files for a command
whereis who
The whoami Command

• Display the effective current username


whoami
Changing Passwords

• A user name is unique, but not confidential,


and may be provided to other users. The
password, on the other hand, is confidential
and secures your work on the system
• Using the passwd command to change
password
Logging Out of UNIX

• Logging out ends your current process and


indicates to UNIX that you are finished.
• How you log out depends on the shell you are
using.
• For the Bourne, Korn, or Bash shells, type exit
on the command line or press Ctrl+D.
• In the C shell, type logout on the command
line.
Pine: Checking Emails on CSE

• You can use pine program to check your email.


– Pine is probably the most extensive and friendly e-mail
program available for UNIX.
• To start Pine
Type pine and then press <Enter>, the following pine Main Menu screen
appears.
• To quit Pine
1. At almost any place in Pine, press q (Quit). You are asked: Really quit
pine?
2. Press y (yes) or press <Enter> to quit.
• You can also use the up and down arrow key to move
the cursor to each field.
Writing a Message in Pine

• To write a message, press C (Compose).

• The ^ character indicates the Control key. You must hold


down the Control key while you press the letter for each
command.
Writing and Sending a Test Message to Yourself

1. Press C (Compose). You see the Compose Message screen.


2. In the To field, type your email address and press <Enter>.
3. In the Cc field, press <Enter>.
4. In the Attachment field, press <Enter>.
5. In the Subject field, type Test and press <Enter>.
6. Below the Message Text line, type This is a test.
7. To send your message, type <Control>X.
You are asked:
Send message?
8. Press y (yes) or press <Enter>.
Sending/Replying/Forwarding a Message

• Sending a Message
– After your message is composed, type <Control>X, and then press y or
press <Enter>. Your message is sent and a copy is saved to the sent-
mail folder

• Replying a Message
– To reply to a message that you have selected at the Message Index
screen or that you are viewing: Press R
– You are asked whether you want to include the original message in
your reply. Also, if the original message was sent to more than one
person, you are asked if you want to reply to all recipients.

• Forward a Message
– Press F
– Enter the address of your recipient and send the message as usual.
File and File Systems
Understanding Files and Directories:
Objectives
• After studying this lesson, you should be
able to:
– File system structure
– Navigating, creating and deleting…
– Unix permissions
Understanding the UNIX File System

• In UNIX, a file is the basic component for data


storage.
• UNIX considers everything it interacts with as a
file, even attached devices such as monitors.
• A file system is the UNIX system’s way of
organizing files on mass storage devices such
as hard and floppy disks.
Unix File System Structure

• The file system is a hierarchical structure


resembling a rooted tree, anchored at
the root (“/”).
• A typical UNIX system contains
hundreds of files and directories.
Unix File System Structure (Contd)

• Every item in the file system is a file (or a


link).
• A directory is a special kind of file can
contain other files and directories (called
subdirectories).
• The subdirectory is considered as the
child of the parent directory.
• Each directory may have only one
parent.
Some Standard Directories

• Root directory (/)


– at the top of the file system hierarchy. Contains some standard files
and directories.
• /bin
– binaries, or executables, which are the programs needed to start the
system and perform other essential system tasks.
• /dev
– Files in /dev references system devices. They access system
devices and resources such as hard disks, printers, …
• /etc
– configuration files that the system uses when the computer starts,
such as passwd (user info file), rc (scripts or directories of scripts)
Some Standard Directories (Contd)

• /lib a collection of related files for a given language


in a single file called an archive. Some libraries are also stored in
the /usr/lib directory, but /lib contains all essential libraries.
• /users normally used to hold the home directories of all the
users of the system. On CSE a similar directory is /home.
• /usr contains subdirectories that hold the UNIX
utilities, tools, language libraries, and manual pages.
• /tmp many programs need a temporary place to store data
during processing cycle. /tmp is the traditional location for these
files.
Home and Current Working Directories

• When you log in, the UNIX system puts you in


a specific directory, called your home
directory.
– The tilda (~) represents the home directory

• Whatever directory you are presently in is


known as the current working directory.
– A single dot (.) denotes the current working
directory
– Two consecutive dots (..) denotes the parent of the
current working directory
Absolute & Relative Paths
• To describe an object in the file system you
specify a path.
• Paths are either absolute, starting with the root
level:
/users/faculty/sarwar/courses/ee446
• Or they are relative, staring with the current
working directory or a user’s home directory
~/courses/ee446
./courses/ee446
Navigating the File System
pwd print working directory name
cd <dir> change to <dir>
cd .. change to parent dir
ls list directory contents
ls -l long listing
ls -a list all files
ls -al long listing all files
ls –F mark directories with /, executable files with *
ls –R Recursively lists subdirectories encountered
The pwd Command

• You can use the UNIX pwd command to


display your current path (pwd stands for
print working directory)
pwd
The cd Command

• cd [dir] Change the current working directory


to ‘dir’

cd Return to your home directory


cd .. Move back to the parent directory
cd . Keep you in the current directory
cd ~ Enter your home directory
cd ~jgao Enter the home directory of jgao
The ls Command

• Use the ls command to list a directory’s


contents, including files and directories.
• If the ls command is used without any
argument, it displays the names of files
and directories in the current working
directory.
The ls Command (Contd)

ls -l long listing
ls -a list all files
ls -al long listing all files
ls –F mark directories with /,
executable files with *
ls –R Recursively lists subdirectories
encountered
e.g.
ls –l /etc long list the /etc directory
Creating & Deleting Files

cp copy files or directories


mv move files or directories
mkdir create directories
rmdir delete empty directories
rm delete a file
rm –r delete recursively
rm -rf force recursive delete
Copying Files

• cp [options] source target

• cp [-i] source_file target_file


– copy the contents of source_file to the destination
path named by target_file
• cp [-i] source_file… target
– copy one or more source_files to the directory
specified by target
• cp –r [-i] source_dir… target
– copy one or more directories specified by
source_dir to the directory specified by target
Copying Files (Contd)

• Common options:
-i : interactive; prompts before overwriting an existing
file
-r : recursive; cp will copy the directory and all its files,
including any subdirectories and their files to target
Example 1: Copying a file
cp goodies goodies.old
Example 2: Copying a list of files to a destination directory
cp result1, result2, result3 /tmp
Example 3: Copying a directory to a destination directory
cp -r /etc/xml .
Move or Rename Files

• mv [-fi] source target_file


– moves the file named by source to the destination
specified by target_file.
• mv [-fi] source... target_dir
– moves each file named by source to a destination
file in the existing directory named by target_dir.

-f move the file(s) without prompting even if it is


writing over an existing target.
-i prompt for confirmation whenever the move would
overwrite an existing target.
Move or Rename Files (Contd)

Examples:
• mv file1 file2
– Rename the file named file1 in the current
working directory to file2

• mv file2 ..
– Push or move the file named file2 up to the
parent of the current working director
Create and Remove Directories

• mkdir dirnames
– Create directories specified in ‘dirnames’

• rmdir dirnames
– Remove the empty directories specified in
‘dirnames’
Remove Files

rm remove file or directory


• This is destructive!
• They are gone!
• They cannot be retrieved!!!
Syntax: rm [options] file…
Note: the above does not generally work
with directories.
rm –r dirname
Unix File Permissions

• Because UNIX is a multi-user system, users can


set permissions for files they own so that others
can read, write, or execute their files.
• A file’s owner is the person who created it.
• The permissions the owner sets are listed as
part of the file description.
• The first section of file permission specifiers
indicates the owner’s permissions.
Unix File Permissions (Contd)

• Each file and directory has permissions that support


access control.
• Types of users
– User (owner), group, others
• Types of Access Permissions
– Read, write, and execute

R W X
User (u)
Group (g)
Others (o)
Unix File Permissions (Contd)

• read (‘r’)
– For file: can view file contents
– For directory: can read directory contents (‘ls’)
• write (‘w’)
– For file: can write to or remove the file
– For directory: can create a new directory or file in
it or remove an existing entry from it
• execute (‘x’)
– For file: can execute (run) file
– For directory: can search, ‘cd’ into the directory
Unix File Permissions (Contd)

• Permissions are defined in three sets, for the user


(owner), group, and others.
• 1st character: file type, ‘-’ for file, ‘d’ directory, ‘s’
special, ‘l’ link
• Character means permission granted, ‘-’ means denied.
View Permissions
File Permissions: Examples

-rw-------
Only owner can read and write
-rwxrwxrwx
Everyone can read, write and execute (not very
common!)
-rw-r--r--
Everyone can read, but only owner can write
Directory Permissions: Examples

drwx------
Only owner can view, delete/create files, and cd
into that directory
drwxrwx---
Owner and group can view, create/delete files, cd,
etc.
drwxr-xr-x
Everyone can view and cd into, but only owner can
modify
Changing Permissions

$ chmod [ugoa(+/-/=)rwx] <dir>

Where
• u user, g group, o others, a all (user,
group, and others);
• + add permission, - take away permission,
= assign permission
Changing Permissions: Examples

• Denying execute permission to everyone


chmod a-x file

• Making a file readable and writable by the


group and other
chmod go+rw file
Changing Permissions (Numeric
Approach)

• Each access given an octal value


r = read = 4;
w = write = 2;
x = execute = 1
• Sum the access for each permission domain
• Example:
– Approach 1 -rwxr-x---
chmod a+rxw myfile.txt
chmod o-rxw myfile.txt
chmod g-w myfile.txt 4+2+1 4+1 0
– Approach 2
chmod 750 myfile.txt
7 5 0
More Examples

• To give yourself read & write permission and no


permission to anyone else:
chmod 600 foobar.txt
• To give yourself read & write permission and
everyone else read permission only:
chmod 644 index.html
• To give yourself full access to a directory, and
everyone else read & execute permission only:
chmod 755 homeDirectory

You might also like