======cprog Journals====== ====Feb,3 2013==== Wrote some code today. It displayed the size of different integer data types( ie: int, long int and short int ). It went alright, made a few syntactical and logical errors, then I tried to push it and I think I might have deleted all that work trying to commit and push and rename and move directories but hey shit happens, I'll get it figured out soon enough. ====Feb,24 2013==== Worked with scanf and pointers in week 4, scanf made sense, pointers not so much. Scanf takes input and you can then point to a variable to store that data to. Pointers were a bit confusing, because some pointed to the address of data, others to the data in the address, and then some pointed to the data of the address inside of another address. Then in week 5 fgetc was used as another input function, but you could directly assign values to a variable unlike pointing to the variable with scanf. We ran into the problem of multiple scanf or fgetc statements where the enter key was taken as a value. To fix this we put in another input statement in front of the ones we originally had to "delete" the enter input. ====Mar, 1, 2013==== 3:30 - 4:40, 5:30 - 7:00 Was led closer to enlightenment by discovering the debugger, gdb, it blew my mind. It helped me see what my exponentiator was doing and i got slightly closer to completing it. Speaking of which i made a program that calculates 5^5 like a boss, anything else is suspect. All that is left is the algorithm. ====Mar, 6, 2013==== 3:30 - 6:00 Finally got the exponentiation function to work with the help of functions. I made separate scripts and combined them all together in lab and then i put them all in one script afterwards and pushed that one to bitbuket.org, just so i could convince myself it could be done both ways ====Mar, 22, 2013==== 3:00 - 4:40 Made shapes! Used the "gd" library which creates shapes such as rectangles, lines and polygons. The functions took many different parameters and could even be colored in. Made a circle of rectangles using a for loop. I messed with some of the features of the circle and ultimately created a super spiral ======unix Journals====== ====February, 3, 2013==== Got myself on the mailing list and started reading some of the text pages and working on the unix tasks. it is a bit strange but i was starting to pick it up ====February, 8, 2013==== Read through lab1 and got most of the answers I was expecting. Typing in the ls command gave me a list of the directories in my current directory. and the -l argument showed more information such as the size and date of creation. Copying the motd file into my directory, created a motd file in my current directory. I then checked the sizes of the motd file and the copy i made of that and they were the same size. When moving files, i realized moving was also a way of renaming, or moving it into a file of a different name. When you create a link and then add something to the directory corresponding to that link it creates a copy in the link as well. The man command was really helpful in describing the commands and their arguments. To get cp operations to be verbose you would type cp -v, and to back up files when moving you can type mv --backup. This lab was helpful in learning fundamental commands. ====February, 23, 2013==== Explored the cat fuction, which let's you jump right into text editing, but has very few functionality compared to text editors. Head and tail would let you read the first or last ten lines of a file. You can add options to the command that allow you to see more of the file. When editing the file i using tail on it with another login, the command let me see what was being put into the file. Then i got familiar with the vim text editor, it has some simple yet powerful functionality. The two different modes , insert and command, make it easy to edit the data you are working on. The editor is very adaptable to the type of machine you are using. ====March, 3, 2013==== 12:00PM - 1:30PM Did case study 1 extracted the archives then renamed abc.text to def.text. Re-compressed the file into arc.tar.gz and pushed to repository. Used the unzip command to unzip the file and the mv command to rename the text file. Then used the manual pages to find info that helped me with the tar and gzip, gunzip commands. ====March, 6, 2013==== 2:40PM - 3:30PM Started case study 0X2 and after extracting the file i noticed that commands were not working on the programs. The spaces in the names are greatly complicating things and it is understandable why you would want to avoid doing that. ==== March, 12, 2013==== 7:00PM - 7:30PM Had to read the manual page on the rm command and it explained how to remove the "- challenge round -" file, in order to remove a file starting with a - use the -- option then i used the wildcard symbol on the file name. Finished with case study 0X2 ==== March, 18, 2013==== 7:00PM - 8:15PM Worked through case study 0x3 using the file command. the first file "file.txt" was easy to view. The second file "abcd.text" had the wrong extension, and I had to use the file utility along with mv to change the file so i could unzip the file with the correct utility. It did eventually succumb to my power and i was successful in reading the file. Worked through lab 0x4 dealing with the shell. Adding the -a option to the ls command shows all of the files that start with a "." that are typically hidden. The .bash_history file appears to store the previously entered commands. Using the "printenv" command i saw that the shell i am in is /bin/bash, the mailfile is ~maildir, the terminal is xterm and the path is /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin. Then the alias' make using functions customize able by adding options automatically. Tab completions allow you to quickly complete command entries. ==== March, 26, 2013==== 6:45PM - 7:25PM Started case study 0x4 messaging. As if there weren't enough resources to communicate with other users, there are "write", "talk" and "ytalk" utilities that let you communicate with other users and even multiple users at once. did not get to use this functionality yet because i didn't have any partners. but i looked at the rest of the tools by logging in twice and messaging myself. Turning the "mesg" utility off does not notify you of incoming messages and tells you the other user has mesg turned off. ==== April, 1, 2013==== 12:45PM - 1:30PM Worked through lab 0x5and learned how to make the computer work for me. To create the files using touch enter the command: touch file1 file2 file3 file4 filea file1234 fileZZZ file41. Using ls on the directory with an argument of "file*" gives a list of all the files that start with the characters "file". an argument of "file?" gives you all the files with 5 character names. The argument file[23] give the files with the name file and the digits 2 and 3 and the argument "file[24a]*" gives the files with a 2, 4, or an a. using redirection operators we can affect where our input and output are going. You can direct the ouput of the "echo" command into a file using the ">" operator. to print out the file listing for the bin folder i used the command "ls -l | more". Using quotes you can change the command "echo $PATH" so that it displays $PATH by single quoting "echo '$PATH'". ==== April, 1, 2013==== 2:00PM - 3:30PM Using cat and wc you can read the line numbers of the /etc/motd file using the following command: cat etc/motd | wc -l giving you 26 lines I can specify to show only files starting with my first initial with the command: ls [z]* To show the files only four characters long use 4 wildcard operators such as: ls ???? To display all files starting with a, b, or c AND ending with r, s, or t. Those files are: bzcat, bzip2recover, bzless, cat and chvt ls [a-c]**[r-t] Finally to view the file “Long File $PATH for Shell Lab.text“ WITHOUT a backslash, tab completion or wildcard use the following command: cat 'Long File $PATH for Shell Lab.text ==== April, 13, 2013==== 5:30PM-6:30PM Worked through case study 0x5, web pages. Edited my cs.html file and it is view-able here: http://lab46.corning-cc.edu/~zdann/cs.html. Made an ordered list and listed 5 of the cars, dirtbikes, and a snowmobile that we own. you can see that here: http://lab46.corning-cc.edu/~zdann/ex0.html. Updated my homepage to include some info, the best list ever and some quotes from songs. Used instances of centered text, emphasized text, and bold text. You can see that here: http://lab46.corning-cc.edu/~zdann/. ==== April, 22, 2013==== 11:30PM - 1:45PM Worked through Lab 0x6 dealing with scripts. wrote the following two scripts: EXAPMLE1: #!/bin/bash n=1 for((i=1; i<=8; i++)); do touch file$n let n=$n+1 done x=1 for((j=1; j<=8; j++)); do echo "$x" >> ~/src/unix/file$x let x=$x+1 done echo "Enter a number between 1 and 8" read num touch newfile$num echo "$num" >> ~/src/unix/file$num EXAPMLE2: #!/bin/bash echo -n "Please enter a directory to process: " read directory cd "$directory" let filecount=$(ls -1 | wc -l) let a=$(ls [A-Ga-g]* -1 | wc -l) let b=$(ls [H-Mh-m]* -1 | wc -l) let c=$(ls [N-Sn-s]* -1 | wc -l) let d=$(ls [S-Zs-z]* -1 | wc -l) if [ "$a" -eq 60 ]; then let a=60 elif [ "$b" -eq 60 ]; then let b=60 elif [ "$c" -eq 60 ]; then let c=60 elif [ "$d" -eq 60 ]; then let d=60 fi echo "Total files: $filecount" echo "" echo -n "(a-g)" for((i=0;i<$a;i++)); do echo -n "*" done echo"" echo -n "(h-m)" for((j=0;j<$b;j++)); do echo -n "*" done echo"" echo -n "(n-s)" for((k=0;k<$a;k++)); do echo -n "*" done echo"" echo -n "(s-z)" for((l=0;l<$a;l++)); do echo -n "*" done echo"" ==== April, 22, 2013 ==== 2:30PM - 3:30PM Worked through case study 0x6. 3 examples of block device files are: XVDA1, XVDA2, XVDA3 and three character devices are: CONSOLE, FULL, and VCS. The df command lists filesystems currently in use by the system. Using it i saw that "/" is mounted on /dev/XVDA1, "/home" is mounted on nfs:/home, and "/temp" is mounted on /dev/XVDA2. Toggling my messaging on and off then viewing the permissions showed that when messaging was off my terminal did not have write access to others. Routing output of a command like cat /etc/motd to /dev/null sends the output to "oblivion" instead of to your terminal. ==== April, 22, 2013 ==== 3:30PM - 4:30PM dev/pts/38 5069 dev/pts/45 2738 Using the ps(1) command i can view my running processes ps will show multiple logins and the processes they are running. The command ps -u lists all processes in user oriented format. The PID for thr processes inetd is 839. Using top(1) the process that happen most frequently on the system appear to be implementations of irssi. The file counts.c is a c source code file. this can be determined with the file utility. to run the compiled executable you specify the directiry the executable is in then the name of the executable ie: ./counts. the command: time ./count > output puts 33554432.000000 is in the file called output. Adding & after the command line puts the process in the background through top i see that it is using roughly 100% CPU usage.the command line: sleep 8s; ls /var > ~/multitask.lab.txt &, will delay the start of the command to list the files in the /var directory to a file called multitask.lab.txt. You are unable to log out of your prompt if you have jobs currently running or stopped. After logging in twice my two terminal devices are dev/pts/38 with PID 5068 and dev/pts/45 with PID 2737. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND zdann 2737 0.0 0.1 89100 2524 ? SN 13:14 0:05 sshd: zdann@pts/45 zdann 2738 0.0 0.1 13640 2036 pts/45 SNs 13:14 0:02 -bash zdann 5068 0.0 0.1 89100 2532 ? SN 16:11 0:00 sshd: zdann@pts/38 zdann 5069 0.0 0.1 13636 2016 pts/38 SNs+ 16:11 0:00 -bash zdann 5558 0.0 0.0 8588 988 pts/45 RN+ 16:53 0:00 ps u -u zdann zdann 17872 0.0 0.0 62480 1308 ? SNs Jan25 0:33 SCREEN zdann 17873 0.0 0.0 13596 12 pts/67 SNs Jan25 0:00 /bin/bash zdann 17953 0.0 0.1 42480 2280 pts/67 SN+ Jan25 15:17 irssi The command: kill -s kill 5068 terminated my second login and displayed the message, the connection was terminated. Using ps -u statd i saw the process owned by statd: /sbin/rpc.statd. The PID of the init process is 1. ==== April, 22, 2013 ==== 5:00PM - 6:00PM Copied the source code files and compiled them: gcc -o helloC helloC.c, g++ -o helloCPP helloCPP.cc and as -o helloASM.o helloASM.S ld -o helloASM helloASM.o. HelloC.c is a c source code file according to file(1). gcc -S helloC.c creates the file helloC.s which is ascii assembler code acording to file(1). Using cat shows the contents of the file, which has been completed up to the assembly stage of compiling. The command as -o helloC.o helloC.s gives a helloC.o which is a 64 bit relocatable file according to file(1). After running the link script which linked the assembled code with the correct libraries the resulting hello file is a 64 bit executable which is the same as the helloC file. The command ./Hello gives the output: "Hello, World!" To compile the files in the multifile subdirectory use the following command: gcc -o main main.c display.c local.h process.c. The executable helloASM is 4 bytes, helloC is 8 bytes and helloCPP is 12 bytes. HelloCPP seemed to complete faster than the smaller files. ==== April, 28, 2013 ==== 6:00PM - 6:45PM Worked through Case Study 0x8: Used find(1) to find the header file "limits.h" Used the following command line. lab46:~ find /usr/ -name limits.h There are 8 bits in a char. It has two unique states, signed and unsigned. The range of a signed ahort int is -32768 - 32767. There are 16 bits in a short int. The range of unsigned integers is 0 - 4294967295. There are 32 bits in an unsigned int and there are 64 bits in a long long int. 64 bits in a long long int gcc -o dtypes dtypes.c unsigned int after: 4294967295 signed short int after -1 got this because it was unsigned so it can't have a negative or signed value. After the change the value goes from 32767 to -32768. this makes sense because a signed int cannot go higher than 32767 so it must roll over. #include int main() { unsigned int a, x; signed short int b, y; a = 0; b = 32767; x = a - 1; y = b + 1; fprintf(stdout, "signed short int before: %hd \t after: %hd\n", b, y); return(0); } #include int main() { signed long long int a, x; unsigned long long int b, y; x = 9223372036854775807 ; a = x++; y = 0; b = y--; fprintf(stdout, "Signed long long int before: %lld; after: %lld\n", x, $ fprintf(stdout, "Unsinged long long int before: %llu; after: %llu\n", y$ return(0); } ==== April, 28, 2013 ==== 6:45PM - 9:00PM Entered the following command to search for instances of 'System' in the passwd file of etc lab46:/etc$ grep System* passwd grep then returned gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh The command line lab46:/etc$ grep ^[b-d][aeiou] passwd returns any strings that start with b through d and contain any of the letters aeiou. The following command line searches for any strings starting with my initials Z or d and the output lab46:/etc$ grep ^[zd] passwd daemon:x:1:1:daemon:/usr/sbin:/bin/sh The following command line will find all the cases that star with r contain lower case vowels and end with h lab46:/etc$ grep ^r[aeiou]$h passwd root:x:0:0:root:/root:/bin/bash To edit all instances of centre to center in the regex.html file type the following in vi: :%s//
/g To change all of the instances to
enter :%s/<\/CENTRE>/<\/center>/g The "words" link points to the american-english file lab46:/usr/share/dict$ ls -l lrwxrwxrwx 1 root root 30 Jan 19 2011 words -> /etc/dictionaries-common/words cd /etc/dictionaries-common/ ls -l lrwxrwxrwx 1 root root 32 Jan 19 2011 words -> /usr/share/dict/american-english There are 98,586 words in the american-english file. lab46:/usr/share/dict$ wc -w american-english 98568 american-english There are 6,685 5 letter words lab46:/usr/share/dict$ grep ^.....$ american-english | wc -w There are 5,157 words that start with z or d. lab46:/usr/share/dict$ grep ^[zd] american-english | wc -w There are 764 three letter words that do not star with 'th' lab46:/usr/share/dict$ grep ^[^th]..$ american-english | wc -w There are 765 three letter words that do not end with 'e' lab46:/usr/share/dict$ grep ^..[^e]$ american-english | wc -w There are 12 words that start with z have an a afterwards and end with d lab46:/usr/share/dict$ grep ^z[a]$d american-english | wc -w There are 3 words that begin and end with aeiou lab46:/usr/share/dict$ grep ^[AEIOUaeiou][aeiou]$ american-english There are 7 words that start with my initials followed by a vowel ending with e s or t lab46:/usr/share/dict$ grep ^[zd][aeiou][est]$ american-english | wc -w There are 93411 words that do not start with my initials zd lab46:/usr/share/dict$ grep ^[^zd] american-english | wc -w There are 7295 that do not end with e lab46:/usr/share/dict$ grep [e]$ american-english | wc -w There are 4 words that contain the substring bob but do not end with b lab46:/usr/share/dict$ grep "bob"[^b]$ american-english | wc -w There are 37 words that start with the substring 'blue' lab46:/usr/share/dict$ grep ^"blue" american-english | wc -w There are 68 words that contain no vowels including y lab46:/usr/share/dict$ grep ^[^aeiouyAEIOUY][^aeiouyAEIOUY]$ american-english | wc -w There are 127 words that start with any character except a vowel followed by any character followed by 'a' 'b' 'c' or 'd' and end with a vowel lab46:/usr/share/dict$ grep ^[^AEIOUYaeiouy].[abcdABCD][aeiouy]$ american-english | wc -w And that is the end of a very long tedious lab! ==== April, 29, 2013 ==== 3:00PM - 4:00PM Started case study 0x9 using grep fgrep and egrep There are 17,862 occurrences of the substring 'coast' lab46:~$ grep [coast] pelopwar.txt | wc -w The word "coast" appears 9 times lab46:~$ grep -o "coast" pelopwar.txt | wc -w To find all the instances of "Dorian" as the last word on the line type: lab46:~$ grep "Dorian"$ pelopwar.txt | wc -l To find all the lines that start with lab46:~$ grep ^"Again" pelopwar.txt |wc -l 8 Instances of 'Athens' or 'Athenians' at the beginning of a line lab46:~$ egrep -o ^'(Athens|Athenians)' pelopwar.txt | wc -w 7 instances of 'Corinth' or 'Corinthians' at the end of a line lab46:~$ egrep -o '(Corinth|Corinthians)'$ pelopwar.txt | wc -w Using fgrep with the same arguments i sent egrep to find Athens and Athenians yielded no outcome because fgrep doesn't recognize the extra expressions that egrep does. The following will give the first 4 lines of output from last that begin with z or d lab46:~$ last >> grep1.text;grep -m4 ^[zd] grep1.text zdann pts/46 10.100.20.126 Mon Apr 29 15:30 still logged in zdann pts/76 10.100.20.126 Mon Apr 29 14:14 still logged in dparson3 pts/81 portal.corning.c Mon Apr 29 09:34 - 10:26 (00:51) dsherbur pts/81 cpe-74-67-84-112 Sun Apr 28 18:11 - 01:01 (06:50) This command line will display the first 4 sorted lines of lastlog's output that start with "e-g" lab46:~$ lastlog >> lastlog.text;sort lastlog.text >> sort.text;grep -m4 ^[e-g] sort.text eberdani pts/63 10.100.20.29 Tue Feb 22 10:12:22 -0500 2011 efarley **Never logged in** egarner **Never logged in** egleason pts/50 cpe-24-94-60-90. Thu Dec 20 17:28:38 -0500 2012 ==== April, 29, 2013 ==== :/<\/a><\/th>$ ==== April, 29, 2013 ==== 5:00PM - 6:00PM The file "/usr/bin/uptime" is executable and is ownd by "root". The file, "howlong" is read and write only and is owned by user. Both files are the same size and both are 64bit executable files. Running file on both files produces the same output because both are 64bit executable files. The file permissions must be changed for "Howlong" so that it can be executed. Both files give the same output when executed. The two files are binary files according to file(1) /usr/bin/uptime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped howlong: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped The two files "howlong" and "uptime" are the same because md5sum(1) gives the same exact output for both da2388cb2b29d954c22db441bb16188c */usr/bin/uptime da2388cb2b29d954c22db441bb16188c *howlong Proof from diff(1) that the files are the same is as follows lab46:~$ diff -s /usr/bin/uptime howlong Files /usr/bin/uptime and howlong are identical The Hash dump from md5sum for /usr/bin/uptime and bin/cp shows a difference between the two. Diff(1) has many options to help tell differences between many types of files such as binary, and texts. The following command will create an 8kB file called test.file and fill it with zeroes lab46:~$ dd if=/dev/zero of=test.file bs=1kB count=8 Using hexedit(1) to view the file will show the contents of the file to be all zeroes. Echoing "more information" to the file will append "more information" to the file. You can search for the string you just echoed in ASCII by pressing tab in hexedit to switch to ASCII then searching for the string. The file data.file is 8,186 bytes in size. The first 3kB appears to contain absolutely nothing, but according to joe nothing is something, so more specifically it contains zeroes. It does change throughout the file and