UNIX Utilities for Non-Programmers: A Guide for Users, Study notes of Computer Science

An excerpt from the book 'unix for programmers and users' by graham glass and king ables. It covers the basics of getting started with unix, popular shells, special characters, and common unix utilities. It also provides information on working with directories, removing files, file attributes, and process attributes.

Typology: Study notes

Pre 2010

Uploaded on 08/31/2009

koofers-user-8sk
koofers-user-8sk 🇺🇸

8 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
8/20/2008
1
Chapter 2
Unix Utilities for non-programmers
Graham Glass and King Ables,
UNIX for Programmers and Users
8/20/2008 cs3320 1
UNIX
for
Programmers
and
Users
,
Third Edition, Pearson Prentice Hall, 2003.
Original Notes by Raj Sunderraman
Converted to presentation and updated by
Michael Weeks
Getting Started
Obtain an account -OR- install Linux
Logging in
locally: enter username and password
remotel se the
ssh
/
telnet
tilit to sign on to
8/20/2008 cs3320 2
remotel
y: u
se
the
ssh
/
telnet
u
tilit
y
to
sign
on
to
Upon logging on you will see a prompt
(usually $ or %) which is displayed by a
special kind of program called a SHELL
program.
To set your password, use passwd
Shells
Popular shells:
Bourne Shell
Korn Shell
C Shell
8/20/2008 cs3320 3
C
Shell
Bash (Bourne Again SHell)
All have common core functionality; some
differences.
Each shell has its own programming
language. (Shell programming).
Running Utilities
To run a utility, simply type the name of the
utility after the prompt.
Some utilities: date, man, clear, stty,
8/20/2008 cs3320 4
Utility: date [yymmddhhmm[.ss]]
Utility: clear
Utility: man [-s section] word
man -k keyword
To logout, enter CTRL-D (or exit)
Special Characters
list meta characters with stty -a command
^ means control
^C means hold down control key (CTRL)
and press the C key
8/20/2008 cs3320 5
and
press
the
C
key
Special Characters
erase: CTRL-H erase character before
cursor
werase: CTRL-W erase word before cursor
kill: CTRL-U erase entire line
8/20/2008 cs3320 6
rprnt: CTRL-R reprint line
To test these:
type some input like “one two three four” at the
terminal prompt
move cursor around
try the above characters
pf3
pf4
pf5
pf8

Partial preview of the text

Download UNIX Utilities for Non-Programmers: A Guide for Users and more Study notes Computer Science in PDF only on Docsity!

Chapter 2

Unix Utilities for non-programmers

Graham Glass and King Ables,

UNIX for Programmers and Users

8/20/2008 cs3320 1

UNIX for Programmers and Users ,

Third Edition, Pearson Prentice Hall, 2003.

Original Notes by Raj Sunderraman

Converted to presentation and updated by

Michael Weeks

Getting Started

  • Obtain an account -OR- install Linux
  • Logging in
    • locally: enter username and password remotel se the ssh / telnet tilit to sign on to

8/20/2008 cs3320 2

  • remotely: use the ssh / telnet utility to sign on to
  • Upon logging on you will see a prompt

(usually $ or %) which is displayed by a

special kind of program called a SHELL

program.

  • To set your password, use passwd

Shells

  • Popular shells:
    • Bourne Shell
    • Korn Shell C Shell

8/20/2008 cs3320 3

  • C Shell
  • Bash (Bourne Again SHell)
  • All have common core functionality; some

differences.

  • Each shell has its own programming

language. (Shell programming).

Running Utilities

  • To run a utility, simply type the name of the

utility after the prompt.

  • Some utilities: date , man , clear , stty ,

passwd

8/20/2008 cs3320 4

passwd

  • Utility: date [yymmddhhmm[.ss]]
  • Utility: clear
  • Utility: man [-s section] word
  • man -k keyword
  • To logout, enter CTRL-D (or exit )

Special Characters

  • list meta characters with stty -a command
  • ^ means control
  • ^C means hold down control key (CTRL)

and press the C key

and press the C key

Special Characters

  • erase: CTRL-H erase character before cursor
  • werase: CTRL-W erase word before cursor
  • kill: CTRL-U erase entire line
  • rprnt: CTRL-R reprint line
  • To test these:
    • type some input like “one two three four” at the terminal prompt
    • move cursor around
    • try the above characters

Special Characters

  • intr: CTRL-C interrupt running program
  • susp: CTRL-Z suspend running program
  • stop: CTRL-S/CTRL-Q stop printing to screen

8/20/2008 cs3320 7

stop: CTRL S/CTRL Q stop printing to screen

  • eof: CTRL-D give program end of file
  • To test these:
    • Try a command like find *
    • For eof, try cat > testfile then CTRL-D on new line

Some common UNIX utilities

  • pwd
  • cat (like concatenate), more, page, head, tail
  • ls, cd
  • mv cp rm

8/20/2008 cs3320 8

  • mv, cp, rm
  • mkdir, rmdir
  • file (determine file type), wc (word count), lp
  • vi, pico, emacs
  • groups, chgrp, chmod

Pathnames

  • /home/mweeks/x.c
  • /export/home/mweeks
  • /Users/mweeks

8/20/2008 cs3320 9

/usr/oracle/m01/app/oracle/product/8.0.4/bin/sqlpl us

-. refers to current directory (example: ./a.out)

  • .. refers to parent directory (example: ../p2.cpp)

Example of cat

$ cat > letter Hi Mom,

Please send me money!

8/20/2008 cs3320 10

David ^D $ ls -l letter -rw-r--r-- 1 qcheng other 38 May 28 11: letter

List Files ( ls )

  • $ ls -algFsdR <file-spec>
  • options
    • a : hidden files
    • l : long listing g g
    • g : group
    • F : put character after file name indicating executable*, link@, directory/, socket=
    • s : num. disk blocks
    • d : dir details not contents
    • R : recursive listing

Show File Contents ( cat, more )

  • $ cat <file-spec-list>
    • list contents of file(s) on screen without pause
  • $ more <file-spec-list>
    • same as cat ; pauses after each screen -more- same as cat ; pauses after each screen more
    • space bar takes you to next screen;
    • q quit
    • enter shows next line
    • h help key for more commands

Word Count

  • word count
  • $ wc -clw <file-spec>
    • c counts the bytes

8/20/2008 cs3320 19

  • l counts the newline characters
  • w prints the word counts

File Attributes

  • -rwx------ 1 cscqxcx cscqxcx 3661 Jan 9 23: RingBufferActOutHandler.java - -rwx------ : file type (first char), permissions - file type (- regular, d dir, b buffered file disk drive, c unbuffered file terminal, l link, p pipe, s socket)

8/20/2008 cs3320 20

p p p )

  • 1 : hard link count
  • cscqxcx : file owner
  • cscqxcx : file's group
  • 3661 : file size in bytes
  • Jan 9 23:12 : file modification date
  • RingBufferActOutHandler.java : file name

File Type

  • $ file
  • ascertains the type of file (ascii/binary etc.)
  • example: [cscqxcx@techie BattleFieldOnFramework]$

8/20/2008 cs3320 21

  • [cscqxcx@techie BattleFieldOnFramework]$ file BFComputation.c
  • BFComputation.c: ASCII C program text, with CRLF line terminators

File Type

  • example:
    • [cscqxcx@techie testbed]$ file *
    • BattleFieldOnFramework: directory
    • BattleFieldOnFramework.09.24.tar: POSIX tar archive
    • RingBufferActOutHandler java: ASCII C program text

8/20/2008 cs3320 22

RingBufferActOutHandler.java: ASCII C program text

  • Samples: directory
  • try: ASCII text

Process Attributes

  • When a process executes, it has
    • a real user ID
    • an effective user ID a real group ID
    • a real group ID
    • an effective group ID

Process Attributes

  • When you log in, your login shell process

has its

  • real/effective user id set to your user id

real/effective group id set to your group id

  • real/effective group id set to your group id

Process' File Permissions

  • When a process runs, the file permissions

apply as follows:

  • If process' effective user id = owner of file; User Privilege applies

8/20/2008 cs3320 25

User Privilege applies

  • If process' effective user id is not owner of file, but its effective group id = file's group id; Group Privilege applies
  • Otherwise Other Privilege applies
  • Real user id is used for accounting purposes only

Process Access Rights

  • Process Access Rights
    • depends on who executes the process,
    • NOT who owns the executable
  • Sometimes undesirable

8/20/2008 cs3320 26

  • Sometimes undesirable
  • Example: game of rogue
    • file of best scores needs to be modified ONLY by rogue program process when player ends game; NOT by players' shells.

Process Access Rights

  • Special feature: 2 special file permissions
    • set user ID (s instead of x)
    • set group ID
  • When an executable with set user ID is executed

8/20/2008 cs3320 27

When an executable with set user ID is executed, the effective user ID of the process becomes that of the executable, NOT of the players shell

  • Allows process to modify best scores file

Groups

  • list the groups a particular user belongs to
    • $ groups
  • change the group a file belongs to

8/20/2008 cs3320 28

  • $ chgrp -R <group-name> <file-spec>
  • R stands for recursive
  • create subshell with effective group id =

group

  • $ newgrp <group-name>

Change File Permissions

  • change file mode; u,g,o,a r,w,x,s
    • user, group, other, all
    • read, write, execute, (set)
    • plus (+) adds permissions
    • minus (-) subtracts
  • Also allows octal numbers

Change File Permissions

  • Examples
    • $ chmod -R XXX <file-spec>
    • $ chmod -R g+w <file-spec>
  • $ chmod -R u-rw <file-spec>
  • $ chmod -R u+w,g-r <file-spec>

The vi Editor

  • CTRL-D (down half screen)
  • CTRL-U (up half screen)
  • CTRL-F (forward one screen)
  • CTRL-B (back one screen)

8/20/2008 cs3320 37

CTRL B (back one screen)

The vi Editor

  • Deleting Text:
    • delete character under cursor x
    • delete word dw
    • delete line dd

8/20/2008 cs3320 38

(also D)

  • delete many lines :d
  • Replacing text:
  • replace char under cursor r
  • replace word under cursor cw
  • replace entire line cc
  • substitute next 4 characters 4s

The vi Editor

  • Pasting text:
    • :y (yank lines)
    • 5yy (yank 5 lines) p

8/20/2008 cs3320 39

  • p
  • P
  • :nnp (after line nn )
  • pu

The vi Editor

  • Searching:
    • search forward /sss/
    • search backward ?sss?
  • Searching/Replacing:

8/20/2008 cs3320 40

  • Searching/Replacing:
    • :s/sss/ttt/
    • :s/sss/ttt/g

The vi Editor

  • Saving/Loading:
    • write to file :w
    • write again :w write :w
    • write :w
    • write and quit :wq
    • edit new file :e
    • read (insert) a file :r

The vi Editor

  • Misc
    • re-draw screen CTRL-L
    • execute a shell command :!comand
  • Quitting:
  • Quitting:
    • quit :q
    • write and quit :wq
    • quit without writing :q!
    • exit and write if changed :x

Review

  • Shells and Special Characters
  • Common Utilities
    • Working with Directories Remo ing Files

8/20/2008 cs3320 43

  • Removing Files
  • File Attributes/Types
  • Process Attributes
  • File permissions, groups, and owner
  • The vi editor