CSC 140: Introduction to IT - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CSC 140: Introduction to IT

Description:

Names of people in a telephone directory. Numbers. CIT 140: Introduction to IT. Slide #3 ... r Reverse order of sort -u Do not list duplicate lines in output. ... – PowerPoint PPT presentation

Number of Views:98
Avg rating:3.0/5.0
Slides: 15
Provided by: NKU
Category:

less

Transcript and Presenter's Notes

Title: CSC 140: Introduction to IT


1
CSC 140 Introduction to IT
  • Advanced File Processing

2
Sorting
  • Ordering set of items by some criteria.
  • Systems in which sorting is used include
  • Words in a dictionary.
  • Names of people in a telephone directory.
  • Numbers.

3
Sorting sort
  • sort -f -i -d -l -v file1 file2,
  • -d Sort in dictionary order (default.)
  • -f Ignore case of letters.
  • -i Ignore non-printable characters.
  • -n Sort in numerical order.
  • -r Reverse order of sort
  • -u Do not list duplicate lines in output.

4
sort Example
  • cat days.txt
  • Sunday
  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • sort days.txt
  • Friday
  • Monday
  • Saturday
  • Sunday
  • Thursday
  • Tuesday
  • Wednesday

5
sort Example
  • cat days.txt
  • Sunday
  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • sort -r days.txt
  • Wednesday
  • Tuesday
  • Thursday
  • Sunday
  • Saturday
  • Monday
  • Friday

6
sort Example
  • cat numbers.txt
  • 101
  • 5571
  • 58
  • 2001
  • 9
  • sort numbers.txt
  • 101
  • 2001
  • 5571
  • 58
  • 9
  • sort -n numbers.txt
  • 9
  • 58
  • 101
  • 2001
  • 5571

7
Searching for Files find
  • find path expression
  • Search for files that match expression under
    path.
  • Example expressions
  • -atime x Was file accessed x days ago?
  • -atime x Was file accessed
  • -mtime /- x Was file modified /
  • -name x Does filename match x?
  • -perm x Does file match permissions x?
  • -size /-x Is file larger/smaller than x
    blocks?
  • -type c Is file a regular file link
    directory?
  • -user n Does file belong to user n?

8
Basic Find Options
  • find /usr/include -name stdio.h
  • /usr/include/stdio.h
  • find /usr/include -name stdio.h -ls
  • 12 -rw-r--r-- 1 root bin 11461 Apr
    6 2002 /usr/include/stdio.h
  • find /usr/include -type l
  • /usr/include/iso/assert_iso.h
  • /usr/include/iso/errno_iso.h
  • ...
  • /usr/include/uil
  • /usr/include/xil
  • find /usr/include -type d
  • /usr/include
  • /usr/include/xfn
  • ...

9
More Find Options
  • find /usr/include -mtime -7
  • find /usr/include -mtime 7
  • /usr/include
  • ...
  • /usr/include/xfn/FN_bindingset.h
  • find /usr/include -perm urw,grw,or
  • find /usr/include -perm urw,gr,or
  • /usr/include/zconf.h
  • /usr/include/zlib.h
  • ...
  • find /usr -name '.h'
  • find cannot read dir /usr/lostfound Permission
    denied
  • /usr/openwin/share/include/X11/DPS/ColorSB.h
  • /usr/openwin/share/include/X11/DPS/ColorSBP.h
  • ...

10
Combining find Expressions
  • find /usr/include -perm urw,gr,or -user
    waldenj
  • find /usr/include -perm urw,gr,or -user root
  • /usr/include/zconf.h
  • ...
  • /usr/include/xfn/FN_compound_name.h
  • find /kernel -type f -user root -size 1000 -ls
  • 303 696 -rwxr-xr-x 2 root sys
    701748 May 13 2003 /kernel/drv/ip
  • 801 888 -rwxr-xr-x 2 root sys
    899456 May 13 2003 /kernel/drv/sparcv9/ip
  • 303 696 -rwxr-xr-x 2 root sys
    701748 May 13 2003 /kernel/strmod/ip
  • 801 888 -rwxr-xr-x 2 root sys
    899456 May 13 2003 /kernel/strmod/sparcv9/ip
  • 384 1768 -rwxr-xr-x 1 root sys
    1794232 May 27 2003 /kernel/genunix

11
Combining find Expressions with -o
  • find /usr \( -name gnome -o -name dict \) -ls
  • 68869 1 drwxr-xr-x 3 root other
    512 Dec 29 2003 /usr/demo/gnome
  • 3862 1 drwxr-xr-x 2 root bin
    512 Dec 29 2003 /usr/share/lib/dict
  • 20512 1 drwxr-xr-x 33 root other
    1024 Dec 29 2003 /usr/share/gnome
  • 71884 2 drwxr-xr-x 4 root other
    1536 Dec 29 2003 /usr/share/gnome/pixmaps/nautilu
    s/gnome
  • 3844 1 lrwxrwxrwx 1 root root
    16 Dec 29 2003 /usr/dict - ./share/lib/dict
  • 26756 1 drwxr-xr-x 3 root other
    512 Dec 29 2003 /usr/gnome
  • 90435 2 -rw-r--r-- 1 bin bin
    1480 May 2 2003 /usr/local/share/terminfo/g/gnom
    e

12
Cutting Text cut
  • cut -d char -f -s file1 file2, ...
  • Print specified fields of files.
  • -c1-2 Print characters 1 through 2 of each
    line.
  • -d char Use specified character as field
    separator.
  • (Tab is default separator.)
  • -f Print field
  • -f 1,2 Print field 1 and field 2
  • -f 1-2 Print all fields 1 through 2
  • -s Dont print lines that dont contain
    field separator.

13
Cutting with space-separated fields
who longa pts/13 Oct 3 1111
(10.20.12.102) waldenj pts/16 Oct 8
1623 (10.20.10.77) trutat1 pts/14
Oct 8 1651 (10.20.11.151) who cut
-c1-8 longa waldenj trutat1 who cut
-c1-14 longa pts waldenj pts trutat1
pts who cut -d " " -f1 longa waldenj trutat1
14
Cutting -separated fields
tail /etc/passwd cut -d -f1,6 cribbett/expor
t/home7/cribbett matracia/export/home7/matracia m
uellerm/export/home7/muellerm nadaudm/export/hom
e7/nadaudm kohuss/export/home7/kohuss cit1403/ex
port/home7/cit1403 stevenso/export/home7/stevenso
mousem/export/home7/mousem krugd/export/home1/k
rugd frankc/export/home7/frankc
Write a Comment
User Comments (0)
About PowerShow.com