CS 497C - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

CS 497C

Description:

CS 497C Introduction to UNIX Lecture 7: General-Purpose Utilities Chin-Chih Chang chang_at_cs.twsu.edu script: Record Your Session If you want to keep track of all ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 21
Provided by: Kind158
Category:
Tags: 497c | clock | ticking

less

Transcript and Presenter's Notes

Title: CS 497C


1
CS 497C Introduction to UNIXLecture 7
General-Purpose Utilities
  • Chin-Chih Changchang_at_cs.twsu.edu

2
script Record Your Session
  • If you want to keep track of all your activities,
    you can invoke the script command after you log
    in
  • script
  • Script started, file is typescript
  • All your keystrokes that you enter get recorded
    in the file typescript.

3
script Record Your Session
  • You can view this file with the cat command.
  • Script overwrites any previous typescript file.
  • To append activities to existing file typescript,
    use
  • script -a
  • To log activities to a different log file, use
  • script logfile

4
clear and tput Clear Your Screen
  • There are two commands available in most UNIX
    systems to clear your screen clear and tput.
  • The clear command is used without arguments
  • clear
  • The tput command is used with the clear argument
  • tput clear

5
clear and tput Clear Your Screen
  • tput can als position the cursor at a specific
    location or be used to highlight text.
  • tput cup 10 20
  • You can boldface your text by using the smso and
    rmso arguments. smso starts highlighting the text
    and rmso ends highlighting.
  • tput smso
  • echo Come to the Web
  • tput rmso

6
uname Know Your Machines Name
  • If your machine is connected to the Internet,
    then your machine name forms part of your
    machines domain name (a series of words
    separated by dots).
  • Use n option to show the machine name in a
    network
  • uname n
  • sisko
  • Use r option to show the operating systems
    version.

7
date Display The System Date
  • The UNIX system maintains an internal clock meant
    to run perpetually. When the system is shut down,
    a battery backup keeps the clock ticking.
  • The clock actually stores the number of seconds
    elapsed since January 1, 1970.
  • You can display the current date with the date
    command.

8
date Display The System Date
  • The date command can display specific format by a
    symbol followed by the operator and a single
    character describing the format
  • d the day of the month (1 to 31)
  • m month in the number format (1 to 12)
  • h month name
  • y the last two digits of the year
  • H, M, and S the hour, minute and second,
    respectively.

9
date Display The System Date
  • You can combine them in the format where the
    symbol precedes a string which specifies the
    requested format within a pair of symbols.
  • To show the month name, date, and, you can use
    the following command
  • date h d y
  • Sep 3 01
  • To change the system date, you need the
    administrator permission.

10
cal The Calender
  • cal is a handy tool that you can invoke anytime
    to see the calendar of any specific month or a
    complete year.
  • To show December, use
  • cal dec
  • To show the year of 2002, use
  • cal 2002 more
  • The symbol connects two commands (in a
    pipeline) where more takes input from the cal
    command.

11
calendar A useful Reminder Mechanism
  • The calendar command provides a useful reminder
    mechanism for a user. The command searches a file
    named calendar in the current directory
  • cat calendar
  • Sep 3 Labor Day
  • Sep 5 Howework Due

12
calendar A useful Reminder Mechanism
  • You can use date and calendar in a sequence to
    show those lines containing todays and
    tomorrows dates.
  • date
  • Mon Sep 3 123014 CDT 2001
  • calendar
  • Sep 3 Labor Day

13
bc The Calculator
  • Two types of calculators are available in UNIX
    a graphical object (the xcalc command) and the
    character-based bc command.
  • bc belongs to a family of commands (called
    filters) that expect input from the keyboard when
    used without any argument.
  • Key in the following arithmetic expression
  • bc
  • 12 5
  • 17

14
bc The Calculator
  • bc added the two numbers and showed the output in
    the next time.
  • To quit bc, you have to use Ctrl-d that marks
    the end of input.
  • You can also ask bc to perform calculations
    together
  • 1212 232
  • 144
  • 4294967296

15
bc The Calculator
  • By default, bc performs truncated division, and
    you have to set scale to the number of digits of
    precision before you perform any division
  • 9/5
  • 1
  • scale 2
  • 17/7
  • 2.42

16
bc The Calculator
  • bc is quite useful in converting numbers from one
    base to another.
  • An example to convert a binary number to a
    decimal one is shown as follows
  • ibase2
  • 11001010
  • 202

17
bc The Calculator
  • The reverse is possible
  • obase 2
  • 14
  • 1110
  • You can convert from one base to the another
  • obase 16
  • 14
  • E

18
bc The Calculator
  • bc can be used with variables
  • x 3 y 4 z 5
  • p x y z
  • p
  • 12
  • bc is a pseudo-programming language featuring
    arrays, functions, conditionals (if) and loops
    (for and while). It also comes with a library for
    performing scientific calculations.

19
More General Purpose Commands
  • Copy, rename and delete files with cp, mv and rm.
  • View and print a file with cat, more, and lp.
  • Compress a file with compress and gzip.
  • Find out disk space utilization with df and du.

20
More General Purpose Commands
  • Extract the two ends of a file with head and
    tail.
  • Cut and past a file with cut and paste.
  • Find differences between two files with comm,
    cmp, and diff.
  • Sort a files contents with sort.
Write a Comment
User Comments (0)
About PowerShow.com