Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Advanced File Processing Part 2.

Similar presentations


Presentation on theme: "CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Advanced File Processing Part 2."— Presentation transcript:

1 CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Advanced File Processing Part 2

2 CIT 140: Introduction to ITSlide #2 Topics 1.Searching for files: find 2.Searching files: grep and egrep 3.Cutting and pasting: cut and paste 4.Encryption and decryption: tr and crypt

3 CIT 140: Introduction to ITSlide #3 Searching for Files: find find path expression Search for files that match expression under path. Example expressions: -atime +xWas file accessed > x days ago? -atime –xWas file accessed < x days ago? -mtime +/- xWas file modified >/< x days ago? -name xDoes filename match x? -perm xDoes file match permissions x? -size +/-xIs file larger/smaller than x blocks? -type cIs file a regular file | link | directory? -user nDoes file belong to user n?

4 CIT 140: Introduction to ITSlide #4 Basic Find Options > find /usr/include -name stdio.h /usr/include/stdio.h > find /usr/include -name stdio.h -ls 1839412 -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...

5 CIT 140: Introduction to ITSlide #5 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 u=rw,g=rw,o=r > find /usr/include -perm u=rw,g=r,o=r /usr/include/zconf.h /usr/include/zlib.h... > find /usr -name '*.h' find: cannot read dir /usr/lost+found: Permission denied /usr/openwin/share/include/X11/DPS/ColorSB.h /usr/openwin/share/include/X11/DPS/ColorSBP.h...

6 CIT 140: Introduction to ITSlide #6 Combining find Expressions > find /usr/include -perm u=rw,g=r,o=r -user waldenj > find /usr/include -perm u=rw,g=r,o=r -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

7 CIT 140: Introduction to ITSlide #7 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/nautilus/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/gnome

8 CIT 140: Introduction to ITSlide #8 Searching Files: grep grep [-i] [-l] [-n] [-v] pattern file1 [file2,...] Search for pattern in the file arguments. -iIgnore case of letters in files. -lPrint only the names of files that contain matches. -nPrint line numbers along with matching lines. -vPrint only nonmatching lines.

9 CIT 140: Introduction to ITSlide #9 Simple Searches > grep catt /usr/dict/words backscatter... wildcatter > grep -c catt /usr/dict/words 8 > grep -c -v catt /usr/dict/words 25135 > wc -l /usr/dict/words 25143 /usr/dict/words > grep -n catt /usr/dict/words 1814:backscatter... 24675:wildcatter > grep -l catt /usr/include/*.h /usr/include/exec_attr.h /usr/include/xti.h

10 CIT 140: Introduction to ITSlide #10 Regular Expressions ^Beginning of line $End of line [a-z]Character range (all lower case) [0-9]Character range (digits) [aeiou]Character range (vowels).Any character *Zero or more of previous pattern a|bMatch a or b

11 CIT 140: Introduction to ITSlide #11 Regular Expression Searches > egrep '^dogg' /usr/dict/words dogging doggone > egrep 'dogg$' /usr/dict/words > egrep 'mann$' /usr/dict/words Boltzmann Hermann Neumann Riemann Schumann > egrep '^mann' /usr/dict/words manna mannequin mannerism

12 CIT 140: Introduction to ITSlide #12 Regular Expression Searches > egrep 'catt|dogg' /usr/dict/words backscatter cattail... dogging doggone... wildcatter > egrep '^(catt|dogg)‘ /usr/dict/words cattail cattle cattleman cattlemen dogging doggone

13 CIT 140: Introduction to ITSlide #13 Character classes > grep '[0-9]' /usr/dict/words 10th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th > grep -c '^[xz]' /usr/dict/words 49 > grep -c '[xz]$' /usr/dict/words 196

14 CIT 140: Introduction to ITSlide #14 How many words words have 4 sequential vowels? > grep '[aeiou][aeiou][aeiou][aeiou]' /usr/dict/words aqueous Hawaiian obsequious onomatopoeia pharmacopoeia prosopopoeia queue Sequoia

15 CIT 140: Introduction to ITSlide #15 Cutting Text: cut cut [-d char] [-f #] [-s] file1 [file2,...] Print specified fields of files. -c#1-#2Print characters #1 through #2 of each line. -d charUse specified character as field separator. (Tab is default separator.) -f #Print field # -f #1,#2Print field #1 and field #2 -f #1-#2Print all fields #1 through #2 -sDon’t print lines that don’t contain field separator.

16 CIT 140: Introduction to ITSlide #16 Cutting with space-separated fields > who longa pts/13 Oct 3 11:11 (10.20.12.102) waldenj pts/16 Oct 8 16:23 (10.20.10.77) trutat1 pts/14 Oct 8 16:51 (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

17 CIT 140: Introduction to ITSlide #17 Cutting :-separated fields > tail /etc/passwd | cut -d: -f1,6 cribbett:/export/home7/cribbett matracia:/export/home7/matracia muellerm:/export/home7/muellerm nadaudm:/export/home7/nadaudm kohuss:/export/home7/kohuss cit1403:/export/home7/cit1403 stevenso:/export/home7/stevenso mousem:/export/home7/mousem krugd:/export/home1/krugd frankc:/export/home7/frankc

18 CIT 140: Introduction to ITSlide #18 Pasting Text: paste paste [-d char] [-f #] [-s] file1 [file2,...] Horizontally concatenate files. -d charUse specified character as field separator. (Tab is default separator.) -f #Print field # -f #1,#2Print field #1 and field #2 -f #1-#2Print all fields #1 through #2 -sDon’t print lines that don’t contain field separator.

19 CIT 140: Introduction to ITSlide #19 Cutting and Pasting > who >who.txt > cut -d " " -f1 who.txt >users.txt > cat users.txt longa waldenj trutat1 > cut -c25-31 who.txt >cut.txt > cat cut.txt Oct 3 Oct 8 > paste users.txt cut.txt longa Oct 3 waldenj Oct 8 trutat1 Oct 8

20 CIT 140: Introduction to ITSlide #20 Encryption Encryption is the process of encoding a message so that its meaning is not obvious. Decryption is the reverse process, transforming an encrypted message back into its original form.

21 CIT 140: Introduction to ITSlide #21 ROT13 ROT13 (“ROTate by 13 places”) is a simple Caesar cipher used for obscuring text by replacing each letter with the letter thirteen places down the alphabet. Not secure, but used to obscure quiz or puzzle answers so you don’t accidentally read them.

22 CIT 140: Introduction to ITSlide #22 ROT13 in UNIX > tr A-Za-z N-ZA-Mn-za-m rot13.txt > cat rot13.txt Fhaqnl Zbaqnl Ghrfqnl Jrqarfqnl Guhefqnl Sevqnl Fngheqnl > tr A-Za-z N-ZA-Mn-za-m <rot13.txt Sunday Monday Tuesday Wednesday Thursday Friday Saturday

23 CIT 140: Introduction to ITSlide #23 Encrypting Files: crypt crypt key ciphertext.txt Encrypt the file plaintext.txt using the specified key and store the result in ciphertext.txt. crypt key <ciphertext.txt Decrypt the file ciphertext.txt using the specified key, which must be identical to the key used to originally encrypt the file.

24 CIT 140: Introduction to ITSlide #24 Example of crypt > crypt hsk45$ crypt.txt > cat crypt.txt ~¿RNiÊV·wVæT®Ýz}ðqpà¾r´6 àÐÚ©ÖÓ'ÔÙóéö`­'îõkóòÇ > crypt hsk45$ <crypt.txt Sunday Monday Tuesday Wednesday Thursday Friday Saturday > crypt foobar <crypt.txt º´­Z Æ'98Åéïkai£7`Íôãâ^w²ª®9Z*A53=QeúSU9Ð _¾ø6`!>ü


Download ppt "CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Advanced File Processing Part 2."

Similar presentations


Ads by Google