Unix - Hour 8 Filters and Piping
8.1.1) Created a file called testme. internet$ touch testme 8.1.2) Displayied permission information about the file just created. Redirected the result of command ls -l to this file and displayied permission information again. internet$ ls -l testme -rw-r--r-- 1 spantaro students 0 Jun 2 17:03 testme internet$ ls -l > testme internet$ ls -l testme -rw-r--r-- 1 spantaro students 1342 Jun 2 17:04 testme internet$ 8.1.3) Used redirecttion to display the content of the file. internet$ cat < testme total 28 -rwx------ 1 spantaro students 1373 May 22 23:42 README -rw-r--r-- 1 spantaro students 1373 May 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 May 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 May 30 10:53 my.new.cmd -rw-r--r-- 1 spantaro students 90 May 28 13:04 new.login -rw-r--r-- 1 spantaro students 0 May 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 May 30 18:35 say.hi -rw-r--r-- 1 spantaro students 7907 May 22 16:59 sort.manpage.Z d--x------ 3 spantaro students 512 May 28 13:58 testdir -rw-r--r-- 1 spantaro students 0 Jun 2 17:04 testme internet$ 8.1.4) appended the result of another command to the file testme and listed the content using redirection. internet$ ls -FC >> testme internet$ cat < testme total 28 -rwx------ 1 spantaro students 1373 May 22 23:42 README -rw-r--r-- 1 spantaro students 1373 May 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 May 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 May 30 10:53 my.new.cmd -rw-r--r-- 1 spantaro students 90 May 28 13:04 new.login -rw-r--r-- 1 spantaro students 0 May 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 May 30 18:35 say.hi -rw-r--r-- 1 spantaro students 7907 May 22 16:59 sort.manpage.Z d--x------ 3 spantaro students 512 May 28 13:58 testdir -rw-r--r-- 1 spantaro students 0 Jun 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$ 8.2.1) Showed in three diferrent ways how to list total of lines, words and characters of a file. internet% wc testme 27 212 1545 testme internet% wc < testme 27 212 1545 internet% cat testme | wc 27 212 1545 internet% 8.2.2) Displayied just total of words when flag -w was used , total of lines when -l flag was used, and showed the result for combination of these flags. The order is always fixed. First lines, then words, and the characters no mather how they are arranged. internet% wc -w testme 212 testme internet% wc -l testme 27 testme internet% wc -lw testme 27 212 testme internet% wc -wl testme 27 212 testme internet% wc testme 27 212 1545 testme internet% 8.2.3) Used pipe to redirect the first command to the second one. This showed how many files are in the current directory. The book says that ls lists each file in a new line, but this did not occurred. However the result obtained does show the total of files somehow. internet% ls | wc -l 22 internet% ls README cis328 my.new.cmd sort.manpage.Z READMES cis377 new.login testdir bugTrack cis396q newfile testme cis316 example prokids visible.ps_data cis325 m13com public-web cis327 m1feedback say.hi internet% 8.2.4) Showed the total of people currently connected once the result of the first command lists one person per line. internet% who | wc -l 5 internet% who root console May 24 13:01 (:0) clamm pts/4 Jun 2 16:22 (user-uini6p4.dsl.mindspring.com) spantaro pts/8 Jun 2 16:41 (dhcp26-223.ggu.edu) vochoa pts/14 May 22 16:28 (pool54-80.ggu.edu) root pts/7 May 24 13:02 (:0.0) internet% 8.2.5) This showed the total of lines of the file and not exactly the number of accounts are on the computeras suggested by the book. internet% cat /etc/passwd | wc -l 25 internet% cat /etc/passwd root:x:0:0:Super-User:/:/sbin/sh 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: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico 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:/: lanman:x:100:11:SunLink Server account:/opt/lanman:/bin/false lmxadmin:x:10869:11:SunLink Server Administrator:/var/opt/lanman/lmxadmin:/bin/sh lmxguest:x:10870:11:SunLink Server GUEST Login:/home/lmxguest:/bin/false lmworld:x:10871:11:SunLink Server World Login:/home/lmworld:/bin/false www:x:97:23:WWW Server:/web/iplanet:/usr/bin/rksh melvin:x:10872:10::/export/melvin:/usr/local/bin/bash iac:x:99:10:Infotrac Client Software:/usr/local/iac:/usr/bin/ksh infotrac:x:95:10:Infotrac Login:/usr/local/infotrac:/usr/bin/ksh keith:x:11840:1::/home/keith:/bin/sh mysql:x:12021:602::/home/mysql:/bin/sh templaw:x:12194:1::/home/templaw:/bin/sh usrqt2:x:12197:1::/home/usrqt2:/bin/sh usrqt3:x:12198:1::/home/usrqt3:/bin/sh internet% 8.4.1) Lists files in a case-sensitive manner internet% ls -1F README* READMES TEST bugTrack/ cis316/ cis325/ cis327/ cis328/ cis377/ cis396q/ example* m13com/ m1feedback/ my.new.cmd* new.login newfile prokids/ public-web/ say.hi* sort.manpage.Z test testdir/ testme visible.ps_data internet% internet% ls -1 | sort -f bugTrack cis316 cis325 cis327 cis328 cis377 cis396q example m13com m1feedback my.new.cmd new.login newfile prokids public-web README READMES say.hi sort.manpage.Z TEST test testdir testme visible.ps_data internet% 8.4.2) The file testme was displayied sorted in the screen. internet% sort testme -rw-r--r-- 1 spantaro students 0 Jun 2 17:04 testme -rw-r--r-- 1 spantaro students 0 May 22 23:44 newfile -rw-r--r-- 1 spantaro students 90 May 28 13:04 new.login -rw-r--r-- 1 spantaro students 1373 May 30 17:08 READMES -rw-r--r-- 1 spantaro students 7907 May 22 16:59 sort.manpage.Z -rwx------ 1 spantaro students 1373 May 22 23:42 README -rwxr-xr-x 1 spantaro students 0 May 30 10:53 my.new.cmd -rwxr-xr-x 1 spantaro students 0 May 30 13:08 example -rwxr-xr-x 1 spantaro students 62 May 30 18:35 say.hi 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/ d--x------ 3 spantaro students 512 May 28 13:58 testdir drwx------ 2 spantaro students 512 Mar 30 13:06 public-web drwx------ 2 spantaro students 512 May 16 17:20 cis396q drwx------ 2 spantaro students 512 Oct 4 2000 cis327 drwx------ 2 spantaro students 512 Sep 19 2000 cis377 drwx------ 2 spantaro students 512 Sep 19 2000 m13com drwx------ 2 spantaro students 512 Sep 19 2000 m1feedback drwx------ 2 spantaro students 1024 Apr 13 11:18 cis316 drwx------ 2 spantaro students 1024 Apr 16 23:10 cis328 drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack drwx------ 2 spantaro students 1536 Apr 28 2000 prokids drwx------ 3 spantaro students 2048 Sep 19 2000 cis325 total 28 internet% 8.4.3) internet% ls -s |sort -n 0 TEST 0 example 0 my.new.cmd 0 newfile 0 test total 40 1 bugTrack 1 cis316 1 cis327 1 cis328 1 cis377 1 cis396q 1 m13com 1 m1feedback 1 new.login 1 public-web 1 say.hi 1 testdir 2 README 2 READMES 2 cis325 2 prokids 2 testme 8 sort.manpage.Z 10 visible.ps_data internet% |