History Command - PowerPoint PPT Presentation

About This Presentation
Title:

History Command

Description:

Successive up arrows step through the previous commands ... Save and exit: ZZ. Change the tab stops: set tabstop=4. Entering unix commands: sh ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 18
Provided by: set134
Learn more at: http://cs.sou.edu
Category:
Tags: class | command | history

less

Transcript and Presenter's Notes

Title: History Command


1
History Command
  • UNIX records all of the commands executed
  • Up arrow displays the previous command
  • Successive up arrows step through the previous
    commands
  • The variable HISTFILE contains a record of all
    commands
  • gthistory gt commands creates a file with a record
    of past executed commands

2
The script command
  • The script command is handy
  • gtscript OR gtscript scriptFile
  • It logs all your input and system output to a
    file
  • If you do not specify a file, the log goes to a
    file called typescript
  • Type gtexit to terminate the logging

3
Escaping special characters
  • Problem we might want to override special
    characters and have UNIX interpret them
    literally
  • Example
  • gtecho HOST echoes the host computer plus the
    home directory name
  • gtecho \HOST \ echoes the literal string
  • gtecho 'HOST ' echoes everything in quotes
    literally
  • gtecho "HOST " echoes everything except for \
    and

4
The tar command
  • Problem want to copy a bunch of files at once
  • Solution tar glues a series of files together
  • Note this is not compression
  • tar commands
  • Glue files together gttar cf tarfile fileList
  • Verbose output tar -cvf tarFile fileList
  • List files in a tarFile tar -tf tarFile
  • Extract files from tarFile gttar -xvf tarFile
  • Note The dash is not needed in the above commands

5
The compress utilities
  • Compression greatly reduces the size of the files
    being transferred
  • Compress a file and create a .gz extensiongtgzip
    fileName
  • Uncompress a file to its original namegtgunzip
    fileName.gz or gtgzip d fileNameOr gt tar zxovf
    fileName.tar.gz
  • Full procedure
  • First tar, then gzip
  • First, extract, then untar

6
Communicating with users
  • gttalk username starts a chat program
  • gtmail initiates a basic mail program
  • gtfinger username displays the content of a file
    called /.plan
  • Procedure
  • Suppose we are user harley
  • echo whatever gt /.plan
  • Other users can type gtfinger harley
  • whatever will display on their terminal

7
UNIX Toolbox Philosophy
  • Create powerful command line tools
  • Each does one thing
  • Each does it very well
  • Design these tools to work well together
  • The tools handle streams
  • Filters are commands whose inputs and outputs are
    stream
  • Job is to transform the input
  • input is either from stdin or a file
  • The tools are normally C programs

8
Streams and Redirection
  • Stream a flow of data from source to sink
  • C programs have default stream sources or sinks
  • stdin standard input (keyboard)
  • stdout standard output (monitor)
  • stderr error output (often same as stdout)
  • Redirection alter the default source or sink
  • Examples
  • redirect stdout to a file gtls gt fileName
  • redirect a file list and append to a filegtls
    gtgt filename
  • redirect input from a file instead of stdinmail
    username ltmessage
  • redirect error messages grep harley 2gt file
  • redirect both stdout and stderr grep harley gt
  • redirect, append both stdout and stderr grep
    harley gtgt

9
Concatenating files
  • Method one (cp command)
  • gtcp file1 file2 file3 destination
  • Method two (cat command with redirection)
  • cat jnk.txt grades gtboth.txt
  • Note cat is the command to type the contents of
    a file
  • Method three (concatenation redirection)
  • cat jnk.txt gtboth.txt
  • cat grades gtgtboth.txt

10
Pipes
  • Send the output of one command to the input of
    the next (cmd1 cmd2)
  • The pipe character
  • Example ls grep a sort u
  • Example ls al more

11
Editors History
  • ed a line editor (Ken Thompson)
  • ex An improved version of ed (Bill Joy)
  • sed stream editor, can apply editing commands
    from the command line using streams
  • vi Screen oriented text editor (We will use this
    one)
  • Standard UNIX editor
  • available on all UNIX systems
  • smaller and faster than emacs
  • minimal keystrokes to do tasks, hard to learn
  • emacs (Richard Stallman)
  • powerful, cumbersome, part of the GNU IDE
  • Others these work more like those on windows,
    but they are not guaranteed to be on every UNIX
    system

12
vi editor
  • Enter and exit the program
  • To enter gtvi fileName
  • To exit colon and then wq (write and quit) or q!
    (quit without write)
  • Modes
  • insert mode input text into a file
  • command mode keyboard command key
  • last line mode longer commands

input
command key
esc
command
or /
esc
last-line
13
File Pointer
  • All commands are relative to a single file
    pointer
  • Central to using vi is navigating around the file
  • Navigation commands
  • arrows work as you would expect on most vi
  • Go to line 1 1G
  • Go to line 50 50G
  • Go forward one word w
  • Go to the end of the line
  • Go to the beginning of the line

14
Delete, Cut, Copy, Paste
  • delete one word dw
  • delete 4 words 4dw or d4w
  • delete (cut) 50 lines 50dd
  • yank (copy the current line y
  • yank (copy) 50 lines 50y
  • yank (copy) into one of 26 buffers buffer c "cy
  • paste cut/copied text after the current line P
  • paste cut/copied text before the current line p
  • paste from buffer c "cp
  • delete one character x
  • delete 50 characters 50x

15
More vi Commands
  • Undo command after a mistake u
  • Undo all recent commands U
  • join this line and the next j
  • joint four lines 4j
  • replace a single character r
  • Save and exit ZZ
  • Change the tab stops set tabstop4
  • Entering unix commands sh

16
vi Insert Mode Examples
  • change rest of a line until ltescgt c
  • Change a word until ltescgt cw
  • Change line until ltescgt cc
  • Insert before file pointer until you ltescgt i
  • Append after file pointer until ltescgt a
  • Insert below until ltescgt o
  • Insert above until ltescgt O
  • Replace until ltescgt R

17
VI Last-Line examples
  • Search for the word cat /cat
  • Search backwords for cat ?cat
  • Replace all this line cat by dog s/cat/dog/g
  • Replace once cat by dog s/cat/dog/
  • Replace once on every line s/cat/dog/
  • Replace all every line s/cat/dog/g
  • Save the file w
  • Save the file as w fileName
  • Save and quit wq
  • Merge a file into the current place r fileName
  • Display line numbers set number
  • Don't display line numbers set nonumber
Write a Comment
User Comments (0)
About PowerShow.com