1a/b.
lab46:~$ ps USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND dblanch1 25797 2.3 0.1 13636 1976 pts/22 SNs 10:14 0:00 -bash dblanch1 25839 0.0 0.0 8588 980 pts/22 RN+ 10:15 0:00 ps u
1c. Use the t option to specify which tty to consider in it's output.
2a.
lab46:~$ ps axu USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 8356 796 ? Ss Apr29 0:10 init [2] root 2 0.0 0.0 0 0 ? S Apr29 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Apr29 1:55 [migration/0] root 4 0.0 0.0 0 0 ? S Apr29 0:02 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S Apr29 0:00 [watchdog/0] root 6 0.0 0.0 0 0 ? S Apr29 3:00 [migration/1] root 7 0.0 0.0 0 0 ? S Apr29 0:04 [ksoftirqd/1] root 8 0.0 0.0 0 0 ? S Apr29 0:00 [watchdog/1] root 9 0.0 0.0 0 0 ? S Apr29 3:31 [events/0] root 10 0.0 0.0 0 0 ? S Apr29 3:28 [events/1] root 11 0.0 0.0 0 0 ? S Apr29 0:00 [cpuset] root 12 0.0 0.0 0 0 ? S Apr29 0:00 [khelper] root 13 0.0 0.0 0 0 ? S Apr29 0:00 [netns] root 14 0.0 0.0 0 0 ? S Apr29 0:00 [async/mgr] root 15 0.0 0.0 0 0 ? S Apr29 0:00 [pm] root 16 0.0 0.0 0 0 ? S Apr29 0:00 [xenwatch] root 17 0.0 0.0 0 0 ? S Apr29 0:00 [xenbus] root 18 0.0 0.0 0 0 ? S Apr29 0:02 [sync_supers] root 19 0.0 0.0 0 0 ? S Apr29 0:01 [bdi-default] root 20 0.0 0.0 0 0 ? S Apr29 0:00 [kintegrityd/0] root 21 0.0 0.0 0 0 ? S Apr29 0:00 [kintegrityd/1] root 22 0.0 0.0 0 0 ? S Apr29 0:07 [kblockd/0] root 23 0.0 0.0 0 0 ? S Apr29 0:00 [kblockd/1] root 24 0.0 0.0 0 0 ? S Apr29 0:00 [kseriod] root 27 0.0 0.0 0 0 ? S Apr29 0:00 [kondemand/0] root 28 0.0 0.0 0 0 ? S Apr29 0:00 [kondemand/1] root 29 0.0 0.0 0 0 ? S Apr29 0:00 [khungtaskd] root 30 0.0 0.0 0 0 ? S Apr29 0:06 [kswapd0] root 31 0.0 0.0 0 0 ? SN Apr29 0:00 [ksmd] root 32 0.0 0.0 0 0 ? S Apr29 0:00 [aio/0] root 33 0.0 0.0 0 0 ? S Apr29 0:00 [aio/1] root 34 0.0 0.0 0 0 ? S Apr29 0:00 [crypto/0] root 35 0.0 0.0 0 0 ? S Apr29 0:00 [crypto/1] root 38 0.0 0.0 0 0 ? S Apr29 0:00 [khvcd] root 113 0.0 0.0 0 0 ? S Apr29 0:59 [kjournald] root 164 0.0 0.0 10416 696 ? S<s Apr29 0:00 udevd --daemon root 204 0.0 0.0 10412 596 ? S< Apr29 0:00 udevd --daemon root 205 0.0 0.0 10412 596 ? S< Apr29 0:00 udevd --daemon mwitter3 335 0.0 0.1 62208 1856 ? SNs May03 0:00 SCREEN mwitter3 336 0.0 0.1 13664 1972 pts/26 SNs May03 0:00 /bin/bash mwitter3 339 0.0 0.3 44304 5040 pts/26 SN+ May03 0:26 irssi root 345 0.0 0.0 0 0 ? S Apr29 5:16 [rpciod/0] root 346 0.0 0.0 0 0 ? S Apr29 1:21 [rpciod/1] root 351 0.0 0.0 0 0 ? S< Apr29 0:00 [kslowd000] root 352 0.0 0.0 0 0 ? S< Apr29 0:00 [kslowd001] root 371 0.0 0.0 0 0 ? S Apr29 6:58 [nfsiod] root 399 0.0 0.0 0 0 ? S Apr29 0:33 [kjournald] root 499 0.0 0.0 6756 1032 ? Ss Apr29 0:00 dhclient -v -pf daemon 554 0.0 0.0 8096 532 ? Ss Apr29 0:00 /sbin/portmap root 767 0.0 0.0 43232 752 ? S Apr29 0:00 supervising sys root 768 0.0 0.2 51344 4180 ? Ss Apr29 1:03 /usr/sbin/syslo daemon 836 0.0 0.0 12400 492 ? Ss Apr29 0:00 /usr/sbin/atd nobody 848 0.0 0.0 5988 612 ? Ss Apr29 0:01 /usr/bin/gdomap root 854 0.0 0.1 167388 2448 ? Ssl Apr29 6:54 /usr/sbin/nscd 106 884 0.0 0.0 15276 728 ? Ss Apr29 0:00 /usr/bin/dbus-d avahi 955 0.0 0.0 25904 1440 ? S Apr29 0:01 avahi-daemon: r avahi 956 0.0 0.0 25772 492 ? S Apr29 0:00 avahi-daemon: c mail 959 0.0 0.0 11736 628 ? S Apr29 0:00 /usr/sbin/nullm root 971 0.0 0.0 14676 776 ? Ss Apr29 0:06 /usr/sbin/cron nobody 979 0.0 0.3 49064 5280 ? Sl Apr29 0:59 python /usr/loc root 999 0.0 0.0 8328 524 ? Ss Apr29 0:00 /usr/sbin/inetd ntp 1006 0.0 0.1 32668 2120 ? Rs Apr29 0:25 /usr/sbin/ntpd root 1013 0.0 0.0 43116 1108 ? Ss Apr29 0:02 /usr/sbin/sshd statd 1046 0.0 0.0 14596 864 ? Ss Apr29 0:00 /sbin/rpc.statd root 1055 0.0 0.1 59288 2188 ? Ss Apr29 0:33 /usr/sbin/rpc.i root 1065 0.0 0.0 0 0 ? S Apr29 0:00 [nfsv4.0-svc] root 1088 0.0 0.0 5932 628 hvc0 Ss+ Apr29 0:00 /sbin/getty 384 tedmist1 1558 0.0 0.1 62600 2316 ? SNs Apr29 0:02 SCREEN tedmist1 1559 0.0 0.1 13668 1980 pts/5 SNs Apr29 0:00 /bin/bash tedmist1 1562 0.0 0.3 42768 5604 pts/5 SN+ Apr29 1:47 irssi bh011695 2033 0.0 0.1 62216 1916 ? SNs Apr29 0:02 SCREEN irssi bh011695 2034 0.0 0.3 42444 5280 pts/7 SNs+ Apr29 1:09 irssi smeas 2433 0.0 0.1 62632 2400 ? SNs Apr29 0:03 SCREEN smeas 2434 0.0 0.1 11572 1932 pts/6 SNs Apr29 0:00 /bin/bash smeas 2448 0.0 0.3 42504 5304 pts/6 RN+ Apr29 1:11 irssi jpettie 2590 0.0 0.1 13664 2008 pts/23 SNs May01 0:00 /bin/bash jpettie 2593 0.0 0.3 42468 5264 pts/23 SN+ May01 1:30 irssi jpettie 2603 0.0 0.1 13664 1984 pts/24 SNs May01 0:00 /bin/bash jpettie 2607 0.0 0.1 34696 2828 pts/24 SN+ May01 0:01 ssh positive@ir jpettie 2983 0.0 0.2 64108 3740 ? SNs Apr29 1:01 SCREEN -l jpettie 2984 0.0 0.1 13676 2048 pts/2 SNs+ Apr29 0:02 /bin/bash mgardne8 4858 0.0 0.1 62396 2096 ? SNs May02 0:01 SCREEN mgardne8 4859 0.0 0.1 13664 1976 pts/8 SNs May02 0:00 /bin/bash mgardne8 4863 0.0 0.3 42468 5224 pts/8 SN+ May02 0:50 irssi eolson1 9999 0.0 0.1 62216 1940 ? SNs May04 0:00 SCREEN eolson1 10000 0.0 0.1 13664 1972 pts/29 SNs May04 0:00 /bin/bash eolson1 10003 0.0 0.3 42432 5200 pts/29 SN+ May04 0:19 irssi mgough 10016 0.0 0.7 56048 12216 ? SN Apr30 1:36 ./eggdrop irc.c mgough 10019 0.0 0.7 55492 11548 ? SN Apr30 1:38 ./eggdrop webbo mgough 10022 0.0 0.1 62216 1796 ? SNs Apr30 0:02 SCREEN mgough 10023 0.0 0.1 13664 1976 pts/11 SNs Apr30 0:00 /bin/bash mgough 10027 0.0 0.3 42480 5324 pts/11 SN+ Apr30 1:03 irssi alius 13293 0.0 0.1 62348 1976 ? Ss Apr30 0:03 SCREEN alius 13294 0.0 0.1 13644 1948 pts/15 Ss Apr30 0:00 /bin/bash alius 13302 0.0 0.4 50204 7032 pts/15 S+ Apr30 1:01 irssi -c irc jserosky 13411 0.0 0.1 62380 2060 ? SNs Apr30 0:03 SCREEN jserosky 13412 0.0 0.1 13672 1984 pts/3 SNs Apr30 0:00 /bin/bash jserosky 13415 0.0 0.3 42456 5252 pts/3 SN+ Apr30 1:04 irssi jhammo13 13661 0.0 0.1 62348 1968 ? SNs May05 0:00 SCREEN jhammo13 13662 0.0 0.1 13664 1976 pts/30 SNs+ May05 0:00 /bin/bash jhammo13 13666 0.0 0.1 13664 1972 pts/31 SNs May05 0:00 /bin/bash jhammo13 13669 0.0 0.3 42340 5184 pts/31 SN+ May05 0:07 irssi jcavalu3 14468 0.0 0.1 62868 2560 ? SNs Apr30 0:02 SCREEN jcavalu3 14469 0.0 0.1 13664 1984 pts/10 SNs Apr30 0:00 /bin/bash jcavalu3 14472 0.0 0.3 42472 5244 pts/10 SN+ Apr30 1:01 irssi ddenunz2 14732 0.0 0.1 62348 2048 ? SNs May02 0:00 SCREEN ddenunz2 14733 0.0 0.1 13656 1968 pts/13 SNs+ May02 0:00 /bin/bash ddenunz2 14738 0.0 0.1 13656 1976 pts/16 SNs+ May02 0:00 /bin/bash jjohns43 15578 0.0 0.1 62216 1796 ? SNs May05 0:00 SCREEN jjohns43 15579 0.0 0.1 13668 1976 pts/25 SNs May05 0:00 /bin/bash jjohns43 15582 0.0 0.3 42344 5184 pts/25 SN+ May05 0:07 irssi root 16150 0.0 0.2 89100 3984 ? SNs May02 0:00 sshd: asowers [ asowers 16152 0.0 0.1 89248 2040 ? SN May02 0:03 sshd: asowers@p asowers 16153 0.0 0.1 13640 2000 pts/14 SNs+ May02 0:00 -bash thakes3 16852 0.0 0.1 62216 1920 ? SNs May05 0:00 SCREEN thakes3 16853 0.0 0.1 31528 2772 pts/27 SNs May05 0:00 /bin/zsh thakes3 16864 0.0 0.3 42444 5244 pts/27 SN+ May05 0:14 irssi root 18334 0.0 0.2 89100 3984 ? SNs May05 0:00 sshd: mhuff3 [p mhuff3 18336 0.0 0.1 89248 2160 ? SN May05 0:03 sshd: mhuff3@pt mhuff3 18337 0.0 0.1 13640 2000 pts/28 SNs May05 0:00 -bash mhuff3 18859 0.0 0.2 13056 3812 pts/28 SN+ May05 0:00 nano hexed.c root 21259 0.0 0.0 0 0 ? S 03:05 0:00 [flush-0:17] asowers 21734 0.0 0.1 62216 1792 ? SNs May03 0:01 SCREEN asowers 21735 0.0 0.1 13672 1980 pts/9 SNs May03 0:00 /bin/bash asowers 21738 0.0 0.3 42432 5208 pts/9 SN+ May03 0:37 irssi root 22920 0.0 0.0 0 0 ? S 06:08 0:00 [flush-202:1] mhuff3 25044 0.0 0.1 62348 2000 ? SNs May01 0:00 SCREEN mhuff3 25045 0.0 0.1 13676 2004 pts/17 SNs+ May01 0:00 /bin/bash mhuff3 25076 0.0 0.1 13668 1980 pts/18 SNs May01 0:00 /bin/bash mhuff3 25079 0.0 0.3 44304 5044 pts/18 SN+ May01 0:43 irssi mhuff3 25081 0.0 0.1 62216 1812 ? SNs May01 0:01 SCREEN irssi mhuff3 25082 0.0 0.3 42428 5284 pts/19 SNs+ May01 0:56 irssi root 25126 0.0 0.2 89100 3972 ? SNs 09:31 0:00 sshd: ahughe12 ahughe12 25129 0.0 0.1 89100 2024 ? SN 09:31 0:01 sshd: ahughe12@ ahughe12 25130 0.0 0.1 13644 2008 pts/21 SNs+ 09:31 0:00 -bash ahughe12 25193 0.0 0.0 96168 720 pts/21 TN 09:33 0:00 ./a.out root 25618 0.0 0.0 0 0 ? S 09:56 0:00 [flush-202:2] root 25624 0.0 0.2 89100 3988 ? SNs 10:00 0:00 sshd: jpettie [ jpettie 25645 0.1 0.1 89100 2028 ? SN 10:00 0:01 sshd: jpettie@p jpettie 25646 0.0 0.1 13624 1960 pts/1 SNs 10:00 0:00 -bash jpettie 25649 0.0 0.1 61848 2364 pts/1 SN+ 10:00 0:00 screen -x jpettie 25650 0.0 0.1 13668 2012 pts/4 SNs+ 10:00 0:00 /bin/bash root 25781 0.0 0.2 89100 3984 ? SNs 10:14 0:00 sshd: dblanch1 dblanch1 25796 0.0 0.1 89248 2044 ? RN 10:14 0:00 sshd: dblanch1@ dblanch1 25797 0.0 0.1 13644 2000 pts/22 SNs 10:14 0:00 -bash root 25857 0.0 0.2 89100 3988 ? SNs 10:15 0:00 sshd: dblanch1 dblanch1 25859 0.0 0.1 89100 2028 ? SN 10:15 0:00 sshd: dblanch1@ dblanch1 25860 0.0 0.1 13636 1972 pts/32 SNs 10:15 0:00 -bash dblanch1 25863 0.0 0.1 10916 1668 pts/32 SN+ 10:15 0:00 man ps dblanch1 25873 0.0 0.0 10360 1000 pts/32 SN+ 10:15 0:00 pager -s dblanch1 26024 0.0 0.0 8588 980 pts/22 RN+ 10:26 0:00 ps u axu cbenne17 26300 0.0 0.1 62216 1812 ? SNs May01 0:01 SCREEN cbenne17 26301 0.0 0.1 13680 1992 pts/20 SNs May01 0:00 /bin/bash cbenne17 26304 0.0 0.3 42344 5188 pts/20 SN+ May01 0:55 irssi root 31734 0.0 0.2 89100 3988 ? Ss May01 0:00 sshd: alius [pr alius 31736 0.0 0.1 89100 2032 ? S May01 0:17 sshd: alius@pts alius 31737 0.0 0.1 13636 1964 pts/0 Ss May01 0:00 -bash alius 31745 0.0 0.1 61848 2364 pts/0 S+ May01 0:01 screen -r
2b. inetd's PID is 999
lab46:~$ ps ax | grep inetd root 999 0.0 0.0 8328 524 ? Ss Apr29 0:00 /usr/sbin/inetd dblanch1 25950 0.0 0.0 10092 864 pts/22 RN+ 10:20 0:00 grep inetd
2c. The most active processes appear to me to be ones user's are currently running in the foreground.
3a.
file count.c count.c: ASCII C program text
3c. It works. run as:
lab46:~$ ./count
3d. I need to add the executable's directory (my home directory) to my shell's $PATH variable.
lab46:~$ PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin:/home/dblanch1
4a.
lab46:~$ time ./count > output real 0m33.896s user 0m33.582s sys 0m0.184s lab46:~$ cat output The number is: 33554432.000000
4b. The output is the same, however rather than waiting at the terminal for count to end, it went to the background. CPU utilisation is at 100%.
5a. lab46:~$ (sleep 8; ls /var > multitask.lab.txt)& We want the whole procedure to be in the background, so we group it in parantheses, lest we put just the ls process in the background.
6. The shell does not let you logout because there are stopped jobs and jobs in the background, and the shell preventing the user from logging out is to ensure the user did not accidentally press ctrl+d and abruptly end currently running processes.
7a. Job 2. 7b. This worked, and resuspended with ctrl+z. 7c. links is still in the jobs list. 7d. fg 1 7e. ctrl+d 7f. cat is no longer in the jobs list. 7g. pressed enter and then q to exit. 7h. jobs list is empty.
8a. 1 8b. 15 8c. 9 8d. 2
9a.
lab46:~$ who NAME LINE TIME IDLE PID COMMENT tedmist1 + pts/1 2013-05-06 13:05 00:12 29024 (143.66.50.10) smeas + pts/6 2013-04-29 20:05 00:28 2434 (li583-226:S.0) asowers + pts/12 2013-05-06 13:00 00:31 28983 (172.16.198.165) asowers + pts/14 2013-05-02 22:57 old 16150 (cpe-69-205-233-207.stny.res.rr.com) alius + pts/15 2013-04-30 15:57 02:26 13294 (cpe-74-65-109-183:S.0) ahughe12 + pts/21 2013-05-06 11:06 00:01 26550 (pod01.offbyone.lan) dblanch1 + pts/22 2013-05-06 13:39 00:01 29409 (cpe-67-252-70-71.stny.res.rr.com) mhuff3 + pts/28 2013-05-05 21:45 15:30 18334 (cpe-69-205-239-38.stny.res.rr.com) wedge - pts/32 2013-05-06 12:08 01:28 27853 (pod01.offbyone.lan) bkrishe3 + pts/33 2013-05-06 12:30 00:13 28322 (10.80.3.183) mwitter3 + pts/34 2013-05-06 13:25 00:12 29248 (cpe-69-205-163-56.stny.res.rr.com) dblanch1 + pts/35 2013-05-06 13:47 . 29472 (cpe-67-252-70-71.stny.res.rr.com) jserosky + pts/38 2013-05-06 13:29 . 29283 (pod00.offbyone.lan)
9b. 22 & 35 9c. 29412 & 29475, relatively
lab46:~$ ps xt ... dblanch1 29412 0.0 0.1 13644 2000 pts/22 SNs 13:39 0:00 -bash ... dblanch1 29475 0.1 0.1 13644 1976 pts/35 SNs 13:47 0:00 -bash ...
10a. Killing /dev/pts/22 10b.
lab46:~$ kill -9 29412
10c. “Connection to lab46.corning-cc.edu closed.” appeared on /dev/pts/22 10d. I am only logged in once now.
11a.
lab46:~$ ps -u statd USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND statd 1046 0.0 0.0 14596 840 ? Ss Apr29 0:00 /sbin/rpc.statd
11b. init's PID is 1, as it is the first process of executed by the system.
lab46:~$ ps ax | grep init root 1 0.0 0.0 8356 788 ? Ss Apr29 0:10 init [2] dblanch1 29888 0.0 0.0 10092 868 pts/35 RN+ 13:56 0:00 grep init
11c. cron's PID is 971 and is owned by root. cron is a task scheduler in the sense that you can schedule a command to be executed at a specific time, or have it reoccur every so often.
lab46:~$ ps ax | grep cron root 971 0.0 0.0 14676 776 ? Ss Apr29 0:06 /usr/sbin/cron dblanch1 29894 0.0 0.0 10092 868 pts/35 RN+ 13:57 0:00 grep cron
1a. grep “coast” -c < pelopwar.txt b. 9 c. grep '\<coast\>' -c < pelopwar.txt d. 8 e. grep '\<Dorian\>$' < pelopwar.txt f. grep '^\<Again\>' < pelopwar.txt
2a/b. egrep '^(\<Athens\>|\<Athenians\>)' < pelopwar.txt 2c/d. egrep '(\<Corinth\>|\<Corinthians\>)$' < pelopwar.txt
3. This produces no results as there is no line or string the file matching this.
Compiling Things:
as -o helloASM helloASM.s; ld -o helloASM helloASM.o gcc -o helloC helloC.c g++ -o helloCPP helloCPP.cc
All three compiling methods worked fine for me. The current directory is not in $PATH, so just typing the name of the binary in question is insufficient; it must be prefixed with a path.
file: helloC.c: ASCII C program text helloCPP.cc: ASCI C++ program text helloASM.S: ASCII assembler program text
gcc -s yields an assembler source file conversion of helloC.c
hello.o is a 64-bit relocatable ELF file, a UNIX executable format. It is an object file, so it is machine code nearly ready for execution, it just needs to be placed in another executable (which is why it is relocatable; either a finished form consisting of it's own code linked with necessary support libraries, or turned into a shared object and linked into another process; which is not the current case). The output matches as we just did what gcc would automatically do for us.
helloC could be compiled this way:
make helloC
Code Efficiency: helloC is 6546 bytes helloCPP is 8369 bytes helloASM is 935 bytes helloJAVA is 426 bytes
The resulting Java file is smaller than the other files because it does not link any support code into the bytecode file, instead linking it at run time.
dd: What is different? uptime is executable, and howlong is not. The permissions are different, because a regular user used dd to make the copy. howlong is not executable because UNIX does not by default create executable files. The differences exist because the actual file data is copied but not associated filesystem metadata, such as permissions, time and date, and the file name. file's output for both files is the same because it analyses the files' contents to determine it's type. In order to execute, howlong needs to be made executable. The only difference between the two programmes' output is the amount of time displayed as they were executed at separate times.
Comparisons: Using diff -s (which reports when both files are the same) causes it to report their file data is, in fact, the same. MD5 hashes are useful in data integrity because they provide an easy, compact way to check the contents of a file for any difference using an algorithm. diff can be used for checking changes between two different versions of a document (say you deleted a line from a document that you now decide that you needed, and you want to retrieve it).
The Exercises: 3a/b/c: To create the zero filled file:
dd bs=8kB count=1 if=/dev/zero of=test.file
I verified this with bvi. 3d. This would append the string to test.file 3e/f. The string start at byte 8001, so we can skip the first 8000 bytes:
dd bs=1 skip=8000 if=test.file of=string
4a. According to bvi, the file is 8186 bytes long. 4b. zeros. 4c. Not constant.
Byte Ranges (hexadecimal) - Size (decimal) 1000 -> 13A5 - (933 bytes) 19A7 -> 19BE - (23 bytes) 1BBF->1BF6 - (55 bytes)
4d/e: There are three such ranges. Segment 1: ELF 64-bit executable
dd bs=1 count=933 skip 4096 if=data.file of=segment1
Segment 2: ASCII text
dd bs=1 count=23 skip=6567 if=data.file of=segment2
Segment 4: gzip compressed data
dd bs=1 count=55 skip=7103 if=data.file of=segment3
In accordance with “The magic number is 42” [I hope the Earth doesn't get blown away soon for an interstellar highway], count is changed to 97 for segment3 such that the secret word can be extracted: “The secret word is: Monkeysnake.” Whatever that means.
1a/b.
lab46: ~$ grep 'System' gnats:x:41:41:Gnats Bug-Reporting System(admin):/var/lib/gnats:/bin/sh
2.
lab46: ~$ grep '^[b-d][aeiou]' /etc/passwd daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh
This search looks for lines starting b, c, or d and is immediately followed by a vowel. Pattern searching is more powerful than looking for just a string literal because you can search unknown strings so long as you have some idea of their structure.
3a.
lab46: ~$ grep '^[dwb]' /etc/passwd daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh www-data:x:33:33:www-data:/var/www:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh
3b.
lab46: ~$ grep '^[aeiou]h$' root:x:0:0:root:/root:/bin/bash
4a. %s/<centre>/<center>/g 4b. %s/<\/CENTRE>/<\/center>/g 4c. %s/<b>/<string>/g 4d. %s<\/b>/<\/strong>/g
5a. lab46: ~$ ls -l /usr/share/dict | grep words This points to /etc/dictionaries-common/words 5b. This file contains words the are on individual lines. 5c.
lab46: ~$ cat words | wc -l 98569 words in this file
For this next set of exercises, I copied the words file to my cwd, /home/dblacnh1 in this case.
6a. cat words | egrep '^.{5}$' | wc -l; 6685 matches 6b. cat words | grep '^[dwbDWB]' | wc -l; 14617 6c. cat words | egrep '^[dD].*[wW].*[bB]$' | wc -l; 1 match: dweeb 6d. cat words | egrep '&[aeiou].*[aeiou]$' | wc -l; 1731 matches 6e. cat words | grep '^[dD][aeiou][est]$' | wc -l; 10 matches 6f. cat words | grep '^[^dwbDWB]' | wc -l; 83951 matches 6g. cat words | egrep '^[^t][^h].+' | wc -l; 90669 matches 6h. cat words | grep '^..e$' | wc -l ; 72 matches 6i. cat words | grep '.*bob.*[^b]$' | wc -l ; 41 matches 6j. cat words | grep 'blue.*' | wc -l ; 37 matches 6k. cat words | grep '[^aeiouyAEIOUY]*' | wc -l ; 204 matches This should be 203 as 'Ångström' contains two vowels. 6l. cat words | grep '[^aeiou].[abcd][aeiou]$' | wc -l; 762 matches
*To make script1.sh run, we need to make it executable:
chmod +x script1.sh
Code for age.sh:
#!/bin/bash echo "In what year were you born? (YYYY) " read birth_year current_year=`/bin/date +%Y` let current_age=$current_year-$birth_year echo "Your current age is: "$current_age
Code for guess1.sh:
#!/bin/bash pick=$(($RANDOM % 20)) echo "Please pick a number [1,20]: " read guess if [ "$guess" -eq "$pick" ]; then echo "Congrats! You guessed correctly." else echo "You have three guesses left. Guess again: " read guess if [ "$guess" -eq "$pick" ]; then echo "Congrats! You guessed correctly." else echo "You have two guess left. Guess again: " read guess if [ "$guess" -eq "$pick" ]; then echo "Congrats! You guessed correctly." else echo "You have one guess left. Guess again: " read guess if [ "$guess" -eq "$pick" ]; then echo "It's about bloody time you guessed right..." else echo "You have failed. The correct answer is "$pick fi fi fi fi
4a. To make the loop put the count all on one line, each separated by a space, change:
echo "$i"
to
echo -n "$i"
4b. To change the stepping and direction, change:
for ((i=1;i<=10;i++)); do
to
for ((i=20;i>=2;i-=2)); do
Code for modified color.sh (now colour.sh):
#!/bin/bash echo -n "First colour is: " for colour in red orange yellow green blue indigo violet; do if [ "$colour" = "violet" ]; then echo -n "The final colour is: " echo $colour elif [ "$colour" != "violet" ]; then echo "$colour" if [ "$colour" != "indigo" ]; then echo -n "The next colour is: " fi fi done
Code for script6.sh:
#!/bin/bash for((i=1; i<=8; i++)); do echo "$i" >> "file"$i done echo "Pick a number [1,8]: " read number for ((i=8; i>0; i--)); do let j=$i+1 if [ "$i" -gt "$number" ]; then mv "file"$i "file"$j elif [ "$i" -eq "$number" ]; then mv "file"$i "file"$j echo "$number" >> "file"$number fi done echo "$number" >> "file"$number
Code for script7.sh:
#~/bin/bash ag=0 hm=0 ns=0 tz=0 q_files=0 echo -n "Directory to process: " read curr_dir cd $curr_dir echo "Processing: $curr_dir ..." a="`find ./ -name "a*" -maxdepth 1 | wc -l`" b="`find ./ -name "b*" -maxdepth 1 | wc -l`" c="`find ./ -name "c*" -maxdepth 1 | wc -l`" d="`find ./ -name "d*" -maxdepth 1 | wc -l`" e="`find ./ -name "e*" -maxdepth 1 | wc -l`" f="`find ./ -name "f*" -maxdepth 1 | wc -l`" g="`find ./ -name "g*" -maxdepth 1 | wc -l`" let ag=$a+$b+$c+$d+$e+$f+$g let q_files+=$ag if [ "$ag" -gt 60 ]; then let ag=60 fi h="`find ./ -name "h*" -maxdepth 1 | wc -l`" i="`find ./ -name "i*" -maxdepth 1 | wc -l`" j="`find ./ -name "j*" -maxdepth 1 | wc -l`" k="`find ./ -name "k*" -maxdepth 1 | wc -l`" l="`find ./ -name "l*" -maxdepth 1 | wc -l`" m="`find ./ -name "m*" -maxdepth 1 | wc -l`" let hm=$h+$i+$j+$k+$l+$m let q_files+=$hm if [ "$hm" -gt 60 ]; then let hm=60 fi n="`find ./ -name "n*" -maxdepth 1 | wc -l`" o="`find ./ -name "o*" -maxdepth 1 | wc -l`" p="`find ./ -name "p*" -maxdepth 1 | wc -l`" q="`find ./ -name "q*" -maxdepth 1 | wc -l`" r="`find ./ -name "r*" -maxdepth 1 | wc -l`" s="`find ./ -name "s*" -maxdepth 1 | wc -l`" let ns=$n+$o+$p+$q+$r+$s let q_files+=$ns if [ "$ns" -gt 60 ]; then let ns=60 fi t="`find ./ -name "t*" -maxdepth 1 | wc -l`" u="`find ./ -name "u*" -maxdepth 1 | wc -l`" v="`find ./ -name "v*" -maxdepth 1 | wc -l`" w="`find ./ -name "w*" -maxdepth 1 | wc -l`" x="`find ./ -name "x*" -maxdepth 1 | wc -l`" y="`find ./ -name "y*" -maxdepth 1 | wc -l`" z="`find ./ -name "z*" -maxdepth 1 | wc -l`" let tz=$t+$u+$v+$w+$x+$y+$z let q_files+=tz if [ "$tz" -gt 60 ]; then let tz=60 fi echo "Total files: $q_files" echo -n "(a->g): " for ((c=0;c<ag;c++)); do echo -n "*" done echo echo -n "(h->m): " for ((c=0;c<hm;c++)); do echo -n "*" done echo echo -n "(n->s): " for ((c=0;c<ns;c++)); do echo -n "*" done echo echo -n "(t->z): " for ((c=0;c<tz;c++)); do echo -n "*" done echo
1a. Permissions are 701.
lab46:~$ ls -l /home/ | grep dblanch1
1b & 1c. I used the id command. My UID is 5813, and I belong to a couple groups so I have two GIDs: 5000 (lab46), and 1730 (unix). 1d & 1e. root is the sysadmin, whose UID is 0 and GID is 0. I determined this by using:
lab46:~$ id root
2a. Using umask, my current umask is 0022. 2b. Current permissions correlate with the umask, as the permissions for the new file are -rw-r–r–. 2c. Permissions of this new file is 666. They correlate. 2d. To make new files' permission 640 by default, I used 027.
3a.
777 -> 111 111 111 077 -> 000 111 111 AND -> 000 111 111
3b.
Assuming a directory 777 -> 111 111 111 777 -> 111 111 111 AND -> 111 111 111
3c.
Assuming a directory 777
-226
551 Assuming a file 666
-226
441
3d.
777 074 703
4a & 4b. Using the id command, I belong to:
lab46 (GID 5000) unix (GID 1730) dblanch1 (5813)
5a & 5b. Directories
fall2010 permissions are 730 and unix is the group root permissions are 750 and the group is root unix permissions are 750 and the group is unix users permissions are 750 and the group is lab46.
5c. I cannot view unix/ME.TOO . unix/README: The mountain ate the dog. users/groups.cs: Up Up Down Down Left Right Left Right B A
5d. I cannot get into root because I am not a member of group root, and I cannot view the contents of fall2010 because I do not have read permissions to this file.
My inclination is to find files with whereis, but it's limited to searching along $PATH, so we'll go with find this time. Among the directories listed with find that a limits.h file is, I shall use /usr/include/limits.h. I called it:
lab46:~$ find / -name limits.h 2>/dev/null
On Lab46, the following is true: char is a four bit type. Has 2^4 (256) possible values. Signed Range: [-128,127] Unsigned Range: [0,255] short int is a sixteen bit type. Has 2^16 (65536) possible values. Signed Range: [-32768,32767] Unsigned Range: [0,65535]. int is a thirty-two bit type. Has 2^32 possible values. Signed Range: [ (-(2^32)/2), ((2^32)/2 - 1)] Unsigned Range: [0, ((2^32) - 1). long long int is a sixty-four bit type. Has 2^64 possible values. Signed Range: [ (-(2^64)/2), ((2^64)/2 -1)] Unsigned Range: [0, ((2^64) - 1).
“Testing the Limits” To compile:
lab46:~/devel$ gcc dtypes.c -o dtypes
Value of unsigned int, after: 429467295 This value is seen in limits.h, defined as the UINT_MAX macro. Value of signed int, after: -1 This is expected. The value is within signed int's range. The result of the modified code makes sense because the value will “roll over” (sort of like the digit wheel on old alarm clocks that had a wheel of digits for the tens of hours, ones of hours, tens of minutes, and ones of minutes). Modified code:
#include <stdio.h> #include <limits.h> int main() { unsigned int a, x; signed short int b, y; a = 0; // zero not letter "O" b = SHRT_MAX; x = a - 1; y = b + 1; printf("signed short int before: %hd \t after: %hd\n", b, y); return(0); }
“Playing with long long int” The minimum value of signed long long int: -9223372036854775808 One use of this data type could be to display the size of the American deficit to the dollar, truncated, of course. Code (C++):
#include <iostream> #include <limits.h> using namespace std; int main(){ cout << "***Playing with long long int***" << endl; cout << "Unsigned:" << endl; cout << "Min: " << 0 << " Max: " << ULLONG_MAX << endl; cout << "Signed: " << endl; cout << "Min: " << LLONG_MIN << " Max: " << LLONG_MAX << endl; return 0; }
Case Study 0x6 - Device Files Looking at /dev: Some files null (character) random (character) zero (character) loop0 (block) xvda1 (block) xvda2 (block)
Filesystems: /dev/xvda1 is mounted at / /dev/xvda2 is mounted at /tmp /dev/xvda3 is mounted as swap (determined by runnning the following:
cat /etc/fstab | grep swap
nfs:/home is mounted at /home nfs:/lib/mail is mounted at /var/mail udev is mounted at /dev There are two temporary file systems, one resides in memory (/dev/shm), and the other is mounted at /lib/init/rw
Software Devices: The two terminals I was using were /dev/pts/28 and /dev/pts/74. Permissions on for both terminals are crw–w—-. Write permissions for group are enabled for the UNIX messaging facilities to function (ie, mesg returns y).
Terminal Pointer: Both methods are the same because /dev/tty points to the current terminal.
Also: cat'ing to /dev/null dumps the output of cat. /dev/null is useful for ignoring command output and making technical jokes.
I did Case Study 5 - Web Pages today. My web page is all set up, including a quote from Camus and Hesse. It's just basic HTML, covering some primitive tags such as <br> to break off into a new line, <p> & </p> to demarcate paragraphs, and creating lists with <ol> & </ol> (ordered list) and <ul> & </ul> (unordered list) tags. The URL of my web page is http://lab46.corning-cc.edu/~dblanch1/index.html .
Case Study 4 - Messaging Utilities
I performed this on my local system using two accounts, user doug on tty2 and user root on tty3. I first ensured messaging was enabled on each account by calling:
doug@slackware: ~$ mesg y root@slackware: ~# mesg y
I then had doug write root “Hello”
doug@slackware: ~$ write root Hello // pressed CTRL+D here to exit.
Here is what root would see:
root@slackware: ~# Message from doug@slackware on tty2 at 20:42 ... Hello EOF // root pressed return here to get his shell back root@slackware: ~# write doug; mesg n I am busy. Do not interrupt. mesg is n now. doug@slackware: ~$ Message from root@slackware on tty3 at 20:43 I am busy. Do not interrupt. mesg is n now. EOF doug@slackware: ~$ write root write: root has messages disabled doug@slackware: ~$ mesg n root@slackware: ~# mesg y; write doug; mesg n I can still message you. I am the sysadmin. You cannot ignore me. // doug sees this, attempts to start a talk session, then realises his system has no talk daemon configured.
Some points about ytalk from the man pages, as I did not have time to actually configure a daemon and play with it: To bring up a shell while in a talk session, press ESC then S To invite another user to a session, press ESC then A To kick another user from a session, press ESC then D
Lab 4 - Basic Unix Shell Stuff Personalised my .signature file.
printenv brings this valuable information:
Shell: bash Term: xterm Path: /bin /usr/bin /usr/local/bin /usr/bin/X11 /usr/games /usr/local/java/bin
In order to display what is in the PATH shell variable:
doug@slackware: ~$ echo $PATH
Current alias for ls:
alias ls='ls --color-auto'
Which, according to the man page, this colourises the ouptput of ls (shocking, I know) based on the file type. Some examples of these colours: plain text is white, directories are blue, archives are red, symlinks are cyan, and executable files are green. Important to note is the colourisation of the file types can be customised with another shell variable, LS_COLORS
Removing the alias for ls removes colourised output for ls when ls is called with no parameters because the shell no long supplies the colour paramter.
Recreating and customising the ls alias
alias ls='ls --colour=auto -k -s --block-size=K'
Changes made here: Calling ls in the shell now displays the total file size of the directory now, and the size of each individual file in front of the filename now, in KiB, and the output is colourised again.
History:
doug@slackware: ~$ history -c //clears history doug@slackware: ~$ echo "###" ### dou@slackware: ~$ echo "You got it" You got it doug@slackware: ~$ echo "---" --- doug@slackware: ~$ history 31 echo "###" 32 echo "You got it" 33 echo "---" 34 history // 32 is the line number for "You got it" doug@slackware !32 echo "You got it" You got it
History cycling is useful if you mistype a command and need to correct (or at least this is my own personal, very common use for it).
Tab Completions: This is all fairly self explanatory. Skipping the first few parts of this to filling in vimtutor; to get a unique hit for tab completion to complete, at least vimt needs to be provided.
Not entirely sure when I originally posted this Lab 2 stuff, but I just noticed it was in the wrong section. So I am moving it.
Lab 2 Results:
10d. chmod 705 lab2
//Needs executable permission because it is a directory
11c.
/ | bin/ etc/ home/ lib/ sbin/ tmp/ usr/ var/ | dblanch1/ | making.waves unix.text some_assembly/ | a b c d e f g h u j k l m n o p q quest2 quest2.dblanch1.gz r s t u v w x y z
12. ls / | grep bin
// Of note, I guess, neither /bin or /sbin are revealed to be symlinked to anything ls /usr | grep bin // Again, neither /usr/bin or /usr/sbin are symlinked to anything ls /usr/local/ | grep bin // Again, neither bin nor sbin here are symlinked to anything. // /bin and /sbin store binaries for the local system necessary for startup and single user mode // /usr/bin and /usr/sbin store binaries that are not necessary for startup or single user mode, and as such, can be shared on a server amongst many clients // /usr/local/bin and /usr/local/sbin store binaries that are specific to the local system, but do not need to be on other computers in the network // Obviously, the difference between bin and sbin is that bin holds user binaries, while sbin holds binaries useful to system administration
Worksheet for Week 6
File Permissions
755 321 421 663
File Types
Normal Directory Special file, character. Used for raw input/output to devices Special file, block. Used for block input/output to devices. Often used with disk drives.
Modifying File Permissions Based on File Type
Do not modify. Normal file. chmod 725 chmod 625 chmod 627
Absolute vs Relative
Absolute. The root directory is explicitly mentioned. Relative. Up one directory level from the current working directory (.. is explicitly mentioned). Relative. No root directory is specified, so the current working directory's path is used. Absolute. Root directory is explicitly mentioned.
It might help if I posted how I overcame the challenge round…
rm ./?\ challenge\ round\ ? rm: remove regular file `./- challenge round -'? y
The results of the exercise for Case Study 2
1a. Choosing files:
“'ls' * HI! *”
“??? can you delete me ???.abc”
“compres “this” file.data”
1b. cat ?ls*
Will the weird filenames ever end? rm *can\ you* rm: remove regular file `??? can you delete me ???.abc'? y //verify ls | grep can //amazing... nothing appeared... gzip compress* //Compresses fine. ls | grep compress compress "this" file.data.gz
2a. Choosing files:
“* watch out! *”
“change my\ name.file”
“just a simple file.txt”
2b. cat \*\*\*\ watch\ out\!\ \*\*\*
Care must be taken when using the '!' symbol, as it deals with history.
mv change\ my\\\ name.file "change my name.file" && cat change* This file has spaces and a backslash in its name. cat just\ a\ simple\ file.txt Simple, but simpler without the spaces!
3a. Choosing files:
“#pico28903#”
“( paranthesis & other odd things)”
“one, 'two', three, “four””
3b. cat “#pico28903#”
laLAA... pretend this is a pico temp file.
cat "( paranthesis & other odd things)" Are we having fun yet? cat "one, 'two', three, "four"" cat: one, 'two', three, four: No such file or directory //This is because the double quotes around 'four' need to be escaped cat "one, 'two', three, \"four\"" spaces, commas, two types of quotes... oh my!
Completed the puzzle case study. Not really what I was expecting based on the name. Kind of disappointing, actually.
I have not had much time to work on my e-mail server project as of yet, so progress on that is where it was last week, unfortunately. This should change this week, though.
But anyway, I am starting to do the text processing lab. Here are my thoughts on it so far:
To get wc(1) to display just the line count of /etc/passwd, we would call:
lab46:~$ wc -l /etc/passwd
and this tells us there are twenty-seven lines in the file. Alternatively, we can use the long parameter format, according to its man page, and use –lines instead of -l
To display just the first sixteen lines of /etc/passwd, we would call:
lab46:~$ head -n 16 /etc/passwd
Alternatively, we can use the long parameter format and use –lines instead of -n.
To display just the last eight lines of /etc/passwd, we would call:
lab46:$ tail -n 8 /etc/passwd
Alternatively, we can use the long parameter format and use –lines instead of -n.
The -f (–follow) parameter is used to follow changes to a file. This would be especially useful for following changes to, say, a log file.
I started work on my first project yesterday, setting up an e-mail server. I ran into an issue yesterday that seems to be resolved now, however; my noip DUC was unable to associate itself with my noip account. To clarify, noip provides free dynamic DNS for users without a static IP address (most residential users, myself included). The Dynamic Update Client would not during configuration associate itself with the domain I chose in my noip account. More to come later.
Well, even though I've concluded I probably shouldn't be doing the problems that appear to be randomly placed in /var/public/unix , I'm still going ahead and doing them as I wait on confirmation for setting up an e-mail server (on my home computer) as a project for this class. “puzzle” is puzzling indeed… so far it appears to be just a collection of oddly named empty files. A few things that strike me about it at the moment is a file called “eieio.c”, and a few files seem to have the same group of letters in them, with one adding to the set… I also wonder if all the ??.c files are at all related…
Actually finished “Quest 2”. For some reason it didn't dawn on me that .gz without tar.gz needed to be extracted with gunzip… I suppose I'm a little too used to tar. I did notice that there is no submit directory under /var/public/unix though, so I could not submit my completed quest. That does have me thinking that perhaps I was not supposed to start doing the quests.
I was doing “Quest 2”, redirecting a programme's stdout (to produce file z) was fairly simple (admittedly after a search with Google), a la
sys:~$ FUNC 1>DEST
1 is stdout, 2 is stderr. It is important to note that this is a bash feature and will not work with zsh, csh, tcsh, et cetera.
I was perusing the public directory yesterday and found a directory called quests. I am not entirely certain what these are exactly, but I noticed the one entitled “some_assembly” seems to be a good exercise for using tar and basic file management (save for symlinking, ln -s src dest). I'll start doing these little “quests” though, particularly since they likely will go along well with the labs for this course. Oh, and when I was setting up screen, I used man screen to help me set it up. You tend to develop those habits when (basically) building your own Linux installation (I used Arch Linux before moving to Slackware; I switched away from it because it was too much work to maintain).
Morse code eh? C'est trés interessant… and I'll be perfectly honest, I did not know there was a reverse line command in UNIX.
I was just reading through the page for Lab 0. Nothing exciting going on there. Decided to leave some evidence that I did it by playing around with alpine a little bit, talking to myself mainly (or exclusively). I know root is watching.
I setup Mercurial, irssi, and screen as per the UNIX task page. Following the instructions it was pretty simple. Logging in via ssh was also a breeze (I've setup it up before to access my home computer remotely, and an FTP server (pure-ftp) to access the files easily and not pay money).