1 / 17

History Command

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 >history > commands creates a file with a record of past executed commands.

wren
Télécharger la présentation

History Command

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • >history > commands creates a file with a record of past executed commands

  2. The script command • The script command is handy >script OR >script 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 >exit to terminate the logging

  3. Escaping special characters • Problem: we might want to override special characters and have UNIX interpret them literally • Example >echo $HOST ~ echoes the host computer plus the home directory name >echo \$HOST \~ echoes the literal string >echo '$HOST ~' echoes everything in quotes literally >echo "$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: >tar –cf tarfile fileList • Verbose output: tar -cvf tarFile fileList • List files in a tarFile: tar -tf tarFile • Extract files from tarFile: >tar -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 extension>gzip fileName • Uncompress a file to its original name>gunzip fileName.gz or >gzip –d fileNameOr > tar zxovf fileName.tar.gz • Full procedure • First tar, then gzip • First, extract, then untar

  6. Communicating with users >talk [username] starts a chat program >mail initiates a basic mail program >finger username displays the content of a file called ~/.plan Procedure • Suppose we are user harley • echo whatever > ~/.plan • Other users can type: >finger 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 >ls ~ > fileName • redirect a file list and append to a file>ls ~ >> filename • redirect input from a file instead of stdinmail username <message • redirect error messages: grep harley ~ 2> file • redirect both stdout and stderr grep harley ~ >& • redirect, append both stdout and stderr: grep harley ~>>&

  9. Concatenating files • Method one (cp command) >cp file1 file2 file3 destination • Method two (cat command with redirection) cat jnk.txt grades >both.txt Note: cat is the command to type the contents of a file • Method three (concatenation redirection) • cat jnk.txt >both.txt • cat grades >>both.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. Enter and exit the program To enter: >vi 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 vi editor 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 tabstop=4 • Entering unix commands: sh

  16. vi Insert Mode Examples • change rest of a line until <esc>: c$ • Change a word until <esc>: cw • Change line until <esc>: cc • Insert before file pointer until you <esc>: i • Append after file pointer until <esc>: a • Insert below until <esc>: o • Insert above until <esc>: O • Replace until <esc>: 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

More Related