Lecture 4 Shell environment III: - command alias & history; - job control; - editor (vim) CSE4251 The Unix Programming Environment 1.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
Advertisements

Introduction to the bash Shell (Bourne-Again SHell)
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Exam Revision. Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part?
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
CS 2061 Shells Also known as: Unix Command Interpreter.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface What is the directory tree Some UNIX commands.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Linux+ Guide to Linux Certification, Third Edition
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
Next Unix Topics Tuesday, 2/11 & 18/2014. Change Password (by 2/14/14) ssh to account on – faclinux.cse.ohio-state.edu – stdlinux.cse.ohio-state.edu passwd.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop III - Part A Shell Commands Professional Training.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
 Simple UNIX commands  I/O techniques in C++  Solutions to Lab#0 problems  Solutions to Lab#1 problems 1.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab,
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Linux Administration Working with the BASH Shell.
Introduction to the bash Shell (Bourne-Again SHell)
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
CS1010: Intro Workshop.
SUSE Linux Enterprise Desktop Administration
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
...looking a bit closer under the hood
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
CSE 303 Concepts and Tools for Software Development
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Unix Shell Environments
LPI Linux Certification
Presentation transcript:

Lecture 4 Shell environment III: - command alias & history; - job control; - editor (vim) CSE4251 The Unix Programming Environment 1

Recap Shell environment II – I/O redirection & pipe:, >>, 2>, 2>>, 2>&1, |, tee – building complex commands: &, ;, ?, &&, ||, – shell variables: e.g., export PATH in ~/.bashrc – Lab1: DUE 11:59pm, Tuesday, Feb 17,

alias shortcuts for long/complex commands – set alias: $ alias short_name=‘long_complex_command’ E.g., $ alias lm=‘ls –l | more’#ls page by page E.g., $ alias rm=‘rm –i’ #prompt before every removal E.g., simulate DOS commands cls and dir : $ alias cls=‘clear’#clear the screen $ alias dir=‘ls -l’

alias shortcuts for long/complex commands – show all aliases defined: $ alias $ alias... alias ls='ls --color=auto' alias ll='ls -l --color=auto‘ alias vi='vim‘ alias cdmy='cd /home/zhengm/0repos/emulator-iscsi/pfe_apps/MySQL‘...

alias shortcuts for long/complex commands – unset alias: unalias $ unalias lm $ unalias rm $ unalias cls $ unalias dir difference b/w alias and variable – aliases are used directly as “new” commands – variables are used as part of other commands (e.g., echo $SHELL)

command history shell saves recently used commands – list all saved commands: $ history or, use alias to save some typing in the future: $ alias h=‘history’ $ h – list N most recent commands: $ history N $ history 3 – size of history: $ echo $HISTSIZE $ echo $HISTSIZE 1000 $ history history 1004 vim ~/.bash_history 1005 history 3

command history invoke previously used commands – execute the last command again: $ !! – execute a command based on cmd#: $ !cmd_number E.g., $ !1005 #equal to $ man rm – execute a command based on (partial) name: $ !cmd_name E.g., $ !al#the last command begin w/ “al” #equal to $ alias where is history stored: ~/.bash_history $ history man rm 1006 alias 1007 man history 1008 history

Job control The shell allows you to run/manage multiple jobs in one terminal – place jobs in the background you can have multiple background jobs two background states: stopped and running – move a job to the foreground you can have only one foreground job (in one terminal) – suspend a job – kill a job – get information about a job

Background jobs If you follow a command with "&", the shell will run the job in the background – don't need to wait for the job to complete, you can type in a new command right away – can have a bunch of jobs running in the background $ tar -zvcf /tmp/etc.tar.gz /etc & [1] 7507 run in background job #PID (process# ) E.g., start a background job:

Background jobs If you follow a command with "&", the shell will run the job in the background – don't need to wait for the job to complete, you can type in a new command right away – can have a bunch of jobs running in the background [1]+ Done tar -zvcf /tmp/etc.tar.gz /etc the cmd for the job job # finished successfully E.g., when the background job completes:

Background jobs If you follow a command with "&", the shell will run the job in the background – don't need to wait for the job to complete, you can type in a new command right away – can have a bunch of jobs running in the background – still output to the screen by default (stdout & stderr); use I/O redirection to save stdout/stderr in log file and thus avoid interference $ tar -zvcf /tmp/etc.tar.gz /etc > /tmp/log.txt 2>&1 & [1] 7529

Background jobs Throw a job into background (suspend a job) – [ctrl]-z List current background jobs – $ jobs $ vi ~/.bashrc [1]+ Stopped vim ~/.bashrc $ $ jobs -l [1] Stopped vim ~/.bashrc

make a stopped background job run in background – $ bg %job_number bring a background job to foreground – $ fg %job_number E.g. $ fg %1 $ vi ~/.bashrc [1]+ Stopped vim ~/.bashrc $ fg %1 Background jobs

kill the foreground job – [ctrl]-c kill a background job – $ kill –signal %job_number E.g., $ kill -9 %1 Check signals – $ kill –l E.g., 9) SIGKILL 15) SIGTERM $ jobs [1]+ Stopped vim ~/.bashrc $ kill -9 %1; jobs [1]+ Stopped vim ~/.bashrc $ jobs [1]+ Killed vim ~/.bashrc $ jobs $ Kill jobs

jobs: list current jobs [ctrl]-z: suspends the foreground job [ctrl]-c: kill the foreground job bg: run the most recently suspended job in the background fg: move the most recently backgrounded job from the background into the foreground kill: terminate a job kill [-signal#] %job_number kill –l : list the kill signals summary of job control

editor recommended: either vi/vim or emacs

vi exists in every Unix-like OSes – default interface for important commands/tools, e.g.: visudo#edit superuser privileges crontab#schedule auto-run programs a “modal” editor: has two modes – edit mode: your keyboard is the one you’re familiar with (e.g., typing “i” means printing “i” on screen), just like typing in gedit or MS Word – command mode: letters have special meaning; do some special tasks (e.g., jump to line# 10,000 directly, replace all “cse4241” with “cse4251” in one go, delete 100 lines below, save and quit,...) vi/vim 101

vim is an improved version of vi – more functionalities, easier to use – similar to ~/.bashrc, vim has a configuration file called ~/.vimrc Example configurations: set nu " show line number set nonu " no line number set tabstop=4 " numbers of spaces of tab character syntax on " syntax highlight vi/vim 101

open an file: $ vim myscript.sh vi/vim 101 information about file and command; default in command mode cursor ~ means empty line line# (if enabled)

enter edit mode: type i vi/vim 101 typing “i” tells the editor you want to insert text

edit text: type “hello,” [Enter], “world!” vi/vim 101 keep showing your current mode type letters normally; [Enter] to start a newline

finish editing, exit edit mode and return to command mode: [Esc] vi/vim 101 after [Esc], you have returned to command mode

enter a command: type :wq, then [Enter] vi/vim 101

You have successfully created, edited, and saved a file using vim vi/vim 101 $ ls -l myscript.sh -rw-rw-r--. 1 zhengm zhengm 14 Sep 25 21:25 myscript.sh $ cat myscript.sh hello, world! $

More resources How to use vi/vim – – How to use Emacs –