Unix - Hour 9 Wildcards and Regular Expressions 9.1.1) Lists the content of mu home directory showing the type of files by column. internet% ls -CF README* cis327/ m1feedback/ say.hi* READMES cis328/ my.new.cmd* sort.manpage.Z TEST cis377/ new.login test bugTrack/ cis396q/ newfile testdir/ cis316/ example* prokids/ testme cis325/ m13com/ public-web/ visible.ps_data internet% 9.1.2) Listed the names of all files and directories in my home directory. internet% echo * OWL README README.2 READMES TEST bugTrack cis316 cis325 cis327 cis328 cis377 cis 396q example file1 m13com m1feedback my.new.cmd new.login newfile prokids public -web say.hi say.hitoo sort.manpage.Z test teestdir testme visible.ps_data internet% 9.1.3) Listed the names of all files and directories in my home directory that starts with letter 't' (lower case). internet% echo t* test testdir testme internet% 9.1.4) Listed all files and directories that ends with letter s. internet% echo *s prokids internet% With ls instead of echo the result showed not only the name but the content of the directory that ended with letter's'. internet% ls -CF *s prokids: pk_create_customers.lst pk_funcdate.lst pk_create_customers.sql pk_funcdate.sql pk_create_customertype.lst pk_funcstring.lst pk_create_customertype.sql pk_funcstring.sql pk_create_orderitems.lst pk_function1.sql pk_create_orderitems.sql pk_function2.sql pk_create_orderitems.sql.save pk_insertupdatedelete.lst pk_create_orders.lst pk_insertupdatedelete.sql pk_create_orders.sql pk_pack1.sql pk_create_product.lst pk_pack2.sql pk_create_product.sql pk_procedure1.sql pk_create_subject.lst pk_procedure2.sql pk_create_subject.sql pk_report1.lst pk_create_subjectmirror.lst pk_report1.sql pk_create_subjectmirror.sql pk_report2.lst pk_createview_institution.lst pk_report2.sql pk_createview_institution.sql pk_sqlloader.bad pk_createview_school.lst pk_sqlloader.ctl pk_createview_school.sql pk_sqlloader.log pk_describeprint.lst pk_testfunctions.sql pk_describeprint.sql pk_testfunctions.sql.save pk_funccomputation.lst pk_testpack1.sql pk_funccomputation.sql pk_trigger1.sql 9.1.5) It displayed all the files that had the pattern function somewhere in their name. The wild card in this case was embbeded in a file in a path. internet% echo prokids/*function* prokids/pk_function1.sql prokids/pk_function2.sql prokids/pk_testfunctions.sql p rokids/pk_testfunctions.sql.save internet% 9.1.6) Changed to OWL directory. , then . internet% cd OWL Listed the content of this directory by column showing the type of file. internet% ls -CF file1.a file3.a owl.b owl_subdir/ file2.a owl.a owl.c displayed only the files that starts with 'owl' internet% echo owl* owl.a owl.b owl.c owl_subdir displayed only the files that starts with 'owl' and had only one letter after the dot. internet% echo owl.? owl.a owl.b owl.c displayed only the files that starts with 'owl' and had only one letter after the pattern 'owl'. In this case there was no match. internet% echo owl? echo: No match The shell did not repeated because it understood the ? as a wild card internet% echo are you listening? echo: No match The shell repeated the sentence because it was between quotes. internet% echo 'are you listening?' are you listening? internet% 9.2.1) Listed the content of home directory. internet% ls OWL cis325 m13com say.hi README cis327 m1feedback say.hitoo README.2 cis328 my.new.cmd sort.manpage.Z READMES cis377 new.login test TEST cis396q newfile testdir bugTrack example prokids testme cis316 file1 public-web visible.ps_data Listed long list but only with directories that starts with 'b'. internet% ls -ld b* drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack Listed long list of file that starts with the letter specified. -d lists directories names rather than their contents. internet% ls -ld a* b* k* o* s* t* drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack -rwxr-xr-x 1 spantaro students 62 Maay 30 18:35 say.hi -rwxr-xr-x 1 spantaro students 110 Juun 6 17:23 say.hitoo -rw-r--r-- 1 spantaro students 7907 Maay 22 16:59 sort.manpage.Z -rw-r--r-- 1 spantaro students 0 Juun 2 18:32 test drwxr-xr-x 3 spantaro students 512 Jun 3 16:09 testdir -rw-r--r-- 1 spantaro students 1545 Juun 2 17:16 testme Another way to do the same as above. internet% ls -ld [abkost]* drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack -rwxr-xr-x 1 spantaro students 62 Maay 30 18:35 say.hi -rwxr-xr-x 1 spantaro students 110 Juun 6 17:23 say.hitoo -rw-r--r-- 1 spantaro students 7907 Maay 22 16:59 sort.manpage.Z -rw-r--r-- 1 spantaro students 0 Juun 2 18:32 test drwxr-xr-x 3 spantaro students 512 Jun 3 16:09 testdir -rw-r--r-- 1 spantaro students 1545 Juun 2 17:16 testme internet% 9.2.2) Displays the name of files that are in the specified range. From a to h. internet% ls -ld [a-h]* drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack drwx------ 2 spantaro students 1024 Apr 13 11:18 cis316 drwx------ 3 spantaro students 2048 Sep 19 2000 cis325 drwx------ 2 spantaro students 512 Oct 4 2000 cis327 drwx------ 2 spantaro students 1024 Apr 16 23:10 cis328 drwx------ 2 spantaro students 512 Sep 19 2000 cis377 drwx------ 2 spantaro students 512 May 16 17:20 cis396q -rwxr-xr-x 1 spantaro students 0 Maay 30 13:08 example -rw-r--r-- 1 spantaro students 0 Juun 6 16:23 file1 internet% 9.2.3) The space typed by mistake produced a wrong result and all the files and directories were listed. internet% ls -CFd [a-h] * OWL/ cis325/ m13com/ say.hi* README* cis327/ m1feedback/ say.hitoo* README.2* cis328/ my.new.cmd* sort.manpage.Z READMES cis377/ new.login test TEST cis396q/ newfile testdir/ bugTrack/ example* prokids/ testme cis316/ file1 public-web/ visible.ps_data internet% 9.2.4) Listed all files that had one of the characters in the specified range. The -d flag forces to display only the name of directories instead of their contents. internet% ls -d *[0-9._]* README.2 cis328 m13com say.hi cis316 cis377 m1feedback say.hitoo cis325 cis396q my.new.cmd sort.manpage.Z cis327 file1 new.login visible.ps_data internet% ls OWL cis325 m13com say.hi README cis327 m1feedback say.hitoo README.2 cis328 my.new.cmd sort.manpage.Z READMES cis377 new.login test TEST cis396q newfile testdir bugTrack example prokids testme cis316 file1 public-web visible.ps_data internet% Searching files using 'grep'
9.3.1) It displayed all lines that have the 'Admin' pattern. internet% grep Admin /etc/passwd adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: lmxadmin:x:10869:11:SunLink Server Administrator:/var/opt/lanman/lmxadmin:/bin/s h internet% 9.3.2) It displayed all lines that have the 'usr' pattern in the beginning of the line. internet% grep '^usr' /etc/passwd usrqt2:x:12197:1::/home/usrqt2:/bin/sh usrqt3:x:12198:1::/home/usrqt3:/bin/sh internet% 9.3.3) This showed all lines that start with pattern 'usrqt' and excluded the ones that have the digits 0,1 or 2 right after. internet% grep '^usrqt[^0-2]' /etc/passwd usrqt3:x:12198:1::/home/usrqt3:/bin/sh internet% 9.3.4) Removing the ^ from the command it showed the lines that were excluded in the previous exercise. internet% grep 'usrqt[0-2]' /etc/passwd usrqt2:x:12197:1::/home/usrqt2:/bin/sh internet% 9.3.6) It displayed all lines that end with ':'. This shows lines for accounts that did not specify a login shell. internet% grep ':$' /etc/passwd daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: internet% 9.3.7) It showed all files in the cis316 directory that have the word 'create'. The first * expands the search beyond files in the current directory, and */* expands your search to all files contained one directory below the current point. internet% grep 'create*' * */* ctCustomer.sql:create table Customer ( ctOrderLines.sql:create table OrderLines ( ctOrders.sql:create table Orders ( ctProduct.sql:create table Product ( ctSequences.sql:create sequence ProductIDSeq increment by 1 start with 1; ctSequences.sql:create sequence ShippingMethodIDSeq increment by 1 start with 1; ctSequences.sql:create sequence ShippingAddressIDSeq increment by 1 start with 1 ; ctSequences.sql:create sequence CustomerIDSeq increment by 1 start with 1; ctSequences.sql:create sequence OrdersIDSeq increment by 1 start with 1; ctShippingAddress.sql:create table ShippingAddress ( ctShippingMethod.sql:create table ShippingMethod ( makeDB.sql:@createAll internet% 9.3.8) It showed all lines that have a dot followed by two spaces. internet% grep '\. ' README account expires SIX (6) months from creation. Extensions are available. You currently have a POP3 account. This enables you to run programs such as Eudora, Outlook or Netscape to check your email. The settings you will as a default index page. I recommend you create your own index.html page No "hacking" or "cracking" is allowed. If you abuse email, IRC, other internet% 9.4.1) Displays the content of file testme. internet% cat testme total 28 -rwx------ 1 spantaro students 1373 Maay 22 23:42 README -rw-r--r-- 1 spantaro students 1373 Maay 30 17:08 READMES drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack drwx------ 2 spantaro students 1024 Apr 13 11:18 cis316 drwx------ 3 spantaro students 2048 Sep 19 2000 cis325 drwx------ 2 spantaro students 512 Oct 4 2000 cis327 drwx------ 2 spantaro students 1024 Apr 16 23:10 cis328 drwx------ 2 spantaro students 512 Sep 19 2000 cis377 drwx------ 2 spantaro students 512 May 16 17:20 cis396q -rwxr-xr-x 1 spantaro students 0 Maay 30 13:08 example drwx------ 2 spantaro students 512 Sep 19 2000 m13com drwx------ 2 spantaro students 512 Sep 19 2000 m1feedback -rwxr-xr-x 1 spantaro students 0 Maay 30 10:53 my.new.cmd -rw-r--r-- 1 spantaro students 90 Maay 28 13:04 new.login -rw-r--r-- 1 spantaro students 0 Maay 22 23:44 newfile drwx------ 2 spantaro students 1536 Apr 28 2000 prokids drwx------ 2 spantaro students 512 Mar 30 13:06 public-web -rwxr-xr-x 1 spantaro students 62 Maay 30 18:35 say.hi -rw-r--r-- 1 spantaro students 7907 Maay 22 16:59 sort.manpage.Z d--x------ 3 spantaro students 512 May 28 13:58 testdir -rw-r--r-- 1 spantaro students 0 Juun 2 17:04 testme README* cis327/ m13com/ prokids/ testme READMES cis328/ m1feedback/ public-web/ bugTrack/ cis377/ my.new.cmd* say.hi* cis316/ cis396q/ new.login sort.manpage.Z cis325/ example* newfile testdir/ internet% 9.4.2) Displays the lines of file 'testme' that have 'READMES' pattern. internet% grep READMES testme -rw-r--r-- 1 spantaro students 1373 Maay 30 17:08 READMES READMES cis328/ m1feedback/ public-web/ internet% 9.4.3) Displays the lines of file 'testme' that have 'owl' pattern. In this case none. internet% grep owl testme internet% 9.4.4) Changed to etc directory. Listed how many lines the file 'passwd' has, and then listed how many lines match the 'usr' pattern. internet% cd /etc internet% wc -l /etc/passwd 25 /etc/passwd internet% grep -c usr /etc/passwd 11 internet% |