Unix/Linux - University of Tulsa

Download Report

Transcript Unix/Linux - University of Tulsa

Unix/Linux
cs3353
The Shell
• The shell is a program that acts as the
interface between the user and the kernel.
– The shell is fully programmable and will
interpret lists of commands entered by the
user, or read cmds from a file (known as a
script).
– A prompt is displayed by the shell program
indicating it is ready to accept input from the
user.
Shell Types
• Bourne Shell (ALGOL syntax)
– sh,
– bash
– ksh
– zsh
• C-shell (based on C language syntax)
– csh
– tcsh
Unix/Linux Commands
• commandName options files
• man commandName
– to read about the command
Example: man find
accounts
• Root
– Has absolute control over the OS
• Regular
– User login id number, string, and password.
Shell Startup
• The .bash_profile (in place of the .profile)
and .bashrc are used at TU.
• Ubuntu, .bashrc
Linux Files
• Everything in the OS is organized into
files.
• There is a i-node for every file on the file
system (i = information)
Files
• Regular files includes (aka ordinary)
– executable (*) and
– hidden files (.).
• Special files:
– Symbolic link (@)
– Directory (d)
– Others: block special, named pipe, character special
Use the cmd: file filename
Use the ls command.
The File System
• Navigate with cd, pwd, ls
• Organized by directories
– mkdir, rmdir
– cp, mv, rm
•
•
•
•
•
/ is known as root
/boot
/home
/var
/tmp
Directory Pathnames
• Absolute – always begins with root /.
• Relative – does not begin with root
./aFile
bFile
/home/user/cFile
../data/dFile
File names
• See pg 57
• 255 characters, no / allowed.
ls –l
•
•
•
•
•
•
•
Type-user-group-other
-rwxr-xr—
Token 1
Token 2-4
Token 5-7
Token 8-10
Access control is through the chmod cmd.
chmod
• Octal:
– chmod [ugo]+|-[rwx]
– Octal r=4, w=2, x=1, the complement of
umask
– X is required for a script to run (pg 29)
• Examples
The Shell Env
• Variables
– Local are only visible in the current process.
– Environment variables are inherited by subprocesses, Example: PATH
– PATH is used by the shell to find commands
entered by the user.
export PATH=$PATH:.:~/bin
echo $PATH
Input and Output
•
•
•
•
STDIN = 0
the standard input
STDOUT = 1
the standard output
STDERR = 2
the standard error
Most cmds are designed to display output
to the stdout
• Many cmds are designed to read input
from the stdin.
• Error messages go to stderr.
Input & Output
• The default location for output is the
terminal screen.
• It is possible to redirect the output of a
command to:
– Another command using a pipe |
– A file using the output redirect symbol >
Example: date > aFile
ps | wc –l
Input & Output
• It is possible to control the input to a command
• The read command is designed to capture input from the
standard input:
cat << stop > file
>Steve
>stop
greeting < file
echo “What is your name?”
read Name
echo “Greetings $Name”
Processes
• Init is process id # 1
• Dummy processes during system startup
do not have a process ID.
• All other processes have a process ID.
Example
• Use ps and sleep to introduce background
processes using the &
• ps will show processes running on a
system.
• A process can be stopped (killed) by using
the PID.
kill pid
Substitution (Meta Characters)
• *, ?, [range]
• !, ^, $