Sie sind auf Seite 1von 36

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name : Gandi Govinda Naidu
Designation : Head of Computer Engg Section
Branch : Computer Engg
Institute : Govt. Polytechnic for women,
. Bheemunipatnam
Year/semester : III Semester
Subject : UNIX & C
Subject code : CM-304
Topic : Basics of UNIX
Duration : 50 Min
Sub topic : UNIX commands
Teaching Aids : PPT, Animations, Photographs
CM304.7 1
Recap

In previous period we learnt about UNIX


directory commands
- pwd
- cd
- mkdir
- rmdir

CM304.7 2
Objective

On completion of this period, you would be


able to know
 UNIX commands like find, wc, cmp, comm,
diff and banner

CM304.7 3
What is find?

 Recursively descends directory tree to find files.


 Syntax: find path… options
path – directory to begin searching
 Options:
-print prints filenames found.
-ls prints long listing of file names
found.

CM304.7 4
What is find?

Options:
-mtime n prints file names modified n
days ago
-mtime +n prints file names modified
>n days ago
-mtime –n prints file names modified
<n days ago

CM304.7 5
find

 Options (continued)
-name pattern prints file names matching pattern
-perm mode prints file names matching
permissions
-size +nc prints file names >n bytes

CM304.7 6
find

 Options (continued)
-size –nc prints file names <n bytes
-user username prints files owned by
username
-type c prints files of type c where c is:
“l” link
“f” text file
“d” directory

CM304.7 7
find Examples

 Show files greater than 2 GB


find /u02/oradata –size +200000000c –ls
 Show files less than 2 GB
find /u02/oradata –size -200000000c –ls

CM304.7 8
find Examples

• Find files modified in the last 24 hours


find /u01/app/oracle –type f –mtime –1 -ls
• Remove trace files older than 30 days
find /u01/app/oracle/admin –name “*.trc” –mtime
+30 \
–exec rm {} \;

CM304.7 9
find Examples

 find scripts where new users are created


find $ORACLE_HOME –type f –name “*.sql” \
–exec grep –il “identified by” {} \;
 find scripts that might have passwords
find $ORACLE_HOME –type f -exec grep –il “sqlplus” \
;

CM304.7 10
find Examples

 find files owned by oracle that are world


readable find / -user oracle –perm –o+r –ls
 find files owned by oracle that are world
writeable find / -user oracle –perm –o+w –ls

CM304.7 11
find Examples

 find linked files


find $ORACLE_HOME –type l -ls
 Compress export files that are larger than 1MB
and older than 30 days

find $ORACLE_HOME –name “*.dmp” –size


+1048576c \-mtime +30 –exec compress {} \;

CM304.7 12
The find Command
 find is one of the power tool of the system.
 It recursively examines a directory tree to look
for files either by
 Name or by matching one or more file
attributes.

CM304.7 13
The find Command
Examples:

$find /-name jani


This command displays all the
occurrences of the file named jani under /
directory.

$find –ctime 2 –name


This command displays names of those
files which are modified in the last two days
and are in the current Directory.

CM304.7 14
The wc Command

 It is named after its word counting function .


 It is used to count number of lines, words and
characters in the file named in the command
line.
 A word is assumed to be any character string
which terminates with a whitespace.

CM304.7 15
The wc Command Contd..

$wc jani
6 12 186 jani
 The first number represents the number of
lines in the file,
 the second represents number of words and
 the third is the number of characters which is

followed by the filename.

CM304.7 16
Contd..
The wc Command

This command has 3 options


 l option prints only the number of lines in

the file.
 w option prints the number of words in
the file.
 c option prints the number of characters
in the file.
$ wc –l jani $wc –w jani $wc –c jani
6 jani 12 jani 186 jani
CM304.7 17
The cmp command

This cmp command allows a user to compare


two files and displays the first line number and
character at which two files differ.
Consider the contents of the two files.

file1 file2
It’s fun playing It’s fun
Playing
Cricket Cricket.
CM304.7 18
The cmp command Contd..

$cmp file1 file2


file1 file2 differ: char 10 line1
The above output shows that the two files differ
at line1 at character 10( small p and capital P).

If two files are identical then cmp command


doesn’t give any output.

CM304.7 19
du – Disk Usage

Syntax: du [-sk] [file…]


Options:
-s sum of all files and subdirectories
-k results in K bytes rather than blocks
Example:
cd /u02/oradata
du –sk * | sort -nr

CM304.7 20
The comm Command

The comm Command compares two files that


are stored on the same field in the same order,
and lists out lines that are unique to each of the
files and lines that are common to both files.

CM304.7 21
Contd..
The comm Command

Consider two files


nagen.os jani.os
OS/2 WIN ROWS NT
WIN95 DOS
DOS MVS
MVS UNIX
UNIX

CM304.7 22
The comm Command
Contd..

 The output consists of three columns.


 The first columns shows lines only in the first
file.
 The second column shows lines only in the
second file.
 The third column shows lines common to both
files.

CM304.7 23
The diff Command

 The diff is a differential file comparator.


 The command specifies which lines must be
changed in the two files to bring them into
agreement.
 The text are compared on a line by line basis.
 If two lines differ by one character the enter line
is reported.

CM304.7 24
The diff Command
Contd..
Example:
$ diff file1 file2
192
>4c5
<z
 The word flagged by < belong to file1
 The word flagged by > belong to file2
 The lines 192 and 4c5 indicate how file can be
made to look like file1 file2

CM304.7 25
The diff Command
Contd..
 a - stands for append
 c - stands for change
 d - stands for delete
 Number before character refers to line number
in file.
 Number after character refers to line number in
file2.
 192 indicates that at the end of line number
one in file1,line no. 2 should be appended.
CM304.7 26
The banner command

 The banner command displays its argument in


large type on the screen .

 It displays one argument on one line unless


argument is enclosed in either single or double
codes.
 The command line format is $banner argument

CM304.7 27
The banner command
Contd..
Example;
$banner T T
####### #######
# #
# #
# #
# #
$banner “T T”
here output will be adjusted in to a single line

CM304.7 28
Summary
In this period you have learnt UNIX
commands like
find
wc
cmp
comm
diff
banner
CM304.7 29
Quiz

1.wc means……..
(a) list
(b) words
(c) word count
(d) none

CM304.7 30
Quiz

1.wc means……..
(a) list
(b) words
(c) word count
(d) none

CM304.7 31
Quiz

2.In UNIX banner is used for ___ letters.


(a) small
(b) medium
(c) capital
(d) large size

CM304.7 32
Quiz

2.In UNIX banner is used for ___ letters.


(a) small
(b) medium
(c) capital
(d) large size

CM304.7 33
Quiz

3.diff is a ___ of two files.


(a) common
(b) compare
(c) repeat
(d) differential comparator

CM304.7 34
Quiz

3.diff is a ___ of two files.


(a) common
(b) compare
(c) repeat
(d) differential comparator

CM304.7 35
Frequently asked questions

3. Explain find with examples.

2. Differentiate the various commands cmp,


comm and diff.

3. What is a wc?

CM304.7 36

Das könnte Ihnen auch gefallen