unix/linux cs3353. the shell the shell is a program that acts as the interface between the user and...

20
Unix/Linux cs3353

Upload: virgil-jackson

Post on 04-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 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

Unix/Linux

cs3353

Page 2: 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

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.

Page 3: 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

Shell Types

• Bourne Shell (ALGOL syntax)– sh,– bash– ksh– zsh

• C-shell (based on C language syntax)– csh– tcsh

Page 4: 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

Unix/Linux Commands

• commandName options files

• man commandName – to read about the command

Example: man find

Page 5: 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

accounts

• Root– Has absolute control over the OS

• Regular– User login id number, string, and password.

Page 6: 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

Shell Startup

• The .bash_profile (in place of the .profile) and .bashrc are used at TU.

• Ubuntu, .bashrc

Page 7: 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

Linux Files

• Everything in the OS is organized into files.

• There is a i-node for every file on the file system (i = information)

Page 8: 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

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.

Page 9: 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

The File System

• Navigate with cd, pwd, ls• Organized by directories

– mkdir, rmdir– cp, mv, rm

• / is known as root• /boot• /home• /var• /tmp

Page 10: 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

Directory Pathnames

• Absolute – always begins with root /.

• Relative – does not begin with root

./aFile

bFile

/home/user/cFile

../data/dFile

Page 11: 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

File names

• See pg 57

• 255 characters, no / allowed.

Page 12: 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

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.

Page 13: 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

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

Page 14: 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

The Shell Env

• Variables– Local are only visible in the current process.– Environment variables are inherited by sub-

processes, Example: PATH– PATH is used by the shell to find commands

entered by the user.

export PATH=$PATH:.:~/bin

echo $PATH

Page 15: 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

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.

Page 16: 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

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

Page 17: 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

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>stopgreeting < file

echo “What is your name?”read Nameecho “Greetings $Name”

Page 18: 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

Processes

• Init is process id # 1

• Dummy processes during system startup do not have a process ID.

• All other processes have a process ID.

Page 19: 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

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

Page 20: 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

Substitution (Meta Characters)

• *, ?, [range]

• !, ^, $