150 likes | 220 Views
Welcome to CSE459.11. Name: Di Cao Email: caod@cse.ohio-state.edu Classroom: DL357 Class Time: T 8:30am - 9:18am Office : DL680 Office Hours: 9:30am -10:30am(T). Lecture 1: Introduction to Unix Shell. Brief Unix History Running Model and System Calls Unix Shell & Flavor.
E N D
Welcome to CSE459.11 • Name: Di Cao • Email: caod@cse.ohio-state.edu • Classroom: DL357 • Class Time: T 8:30am - 9:18am • Office : DL680 • Office Hours: 9:30am -10:30am(T)
Lecture 1: Introduction to Unix Shell Brief Unix History Running Model and System Calls Unix Shell & Flavor
Unix History and Motivation • The first version of Unix came from AT&T in the early 1970s (Unix is old!). • Unix was developed by programmers and for programmers. • Unix is designed so that users can extend the functionality • To build new tools easily and efficiently • To customize the shell and user interface. • To string together a series of Unix commands to create new functionality. • To create custom commands that do exactly what we want.
What is Shell? • Shell is • Command Interpreter that turns text that you type (at the command line) in to actions: • Shell is a process; • User Interface: take the command from user
Flavors of Unix Shells • Two main flavors of Unix Shells • Bourne (or Standard Shell): sh, ksh, bash, zsh • AT&T shell • Fast • $ for command prompt • C shell : csh, tcsh • Berkley Shell • better for user customization and scripting • %, > for command prompt • To check shell: • % echo $SHELL (shell is a pre-defined variable) • To switch shell: • % exec shellname (e.g., % exec bash)
Popular Shells • sh Bourne Shell • ksh Korn Shell • csh,tcsh C Shell (for this course) • bash Bourne-Again Shell
Uses of Shell • Programming Shell can do • Interpret Commands: Parse, Evaluate • Customization of a Unix session • Scripting: Interpreted Programming Language
Customization of a Session • Each shell supports some customization. • User prompt • Where to find mail • Shortcuts (alias) • The customization takes place in startup files • Startup files are read by the shell when it starts up • The Startup files can differ for different shell
Startup files • sh,ksh: /etc/profile (system defaults) ~/.profile • bash: ~/.bash_profile ~/.bashrc ~/.bash_logout • csh: • ~/.login: executed when you logon • ~/.cshrc: executed when a new shell is spawned • ~/.logout: executed at logout
Running Model • User Mode • A process running in this mode can’t access kernel data structures and procedures • Kernel Mode • A process running in this mode can access kernel data structures and procedures • System call • Can be looked as the interface between user mode and kernel mode
Creating Processes • fork() • Create a duplicate of the calling process • exec() • Create a duplicate of the calling process • Load an executable program whose name is one of arguments of exec() into the address space of the new process • wait()- Cause a parent process to sleep until one of its child processes terminates • exit()
Your Best Friend • % man command (e.g., % man ls) • shows information about the command • usually space or ↓ for more information • q to quit • % man man
Some Common Commands • ls –l • mv src dst // rename a file • rm file // delete files or directories • cp src dst // copy files • mail • write sb // send an message to sb • lpr // print something • wc file // word counting for a file • tail –n file // print out the last n lines of file • tail +n file // print out file starting from nth line • mkdir dir_name // create a directory • rmdir dir_name // delete a directory
Recommended Reading • Chapter 1, sections 1.1 – 1.5