Table of Contents

Kellen's OPUS2012

*trademark*

Introduction

Kellen H, first member of my family to go to college. My goals are to get a CS degree and go into the military with it.

Part 1

Entries

Entry 1: 9/5/2012

I understand everything done by a computer is the result of a file regardless of what it is, this is important because it cleared up a lot of things done by computers that I couldn't comprehend prior to learning this.

Entry 2: 9/14/2012

Learned the basics of the ViM text editor, this will be extremely helpful to know in the future because as I understand more about Linux/Unix the more I suspect I will favor them in the not-too-distant future.

Entry 3: 9/28/2012

Today wildcars are introduced, they will be very helpful when searching long lists of entries or when I'd like to know how many entries there possibly are.

Entry 4: 9/28/2012

Today I learned about the use of scripts and their potential applications, this is exciting because the usefulness is only limited by how far you take it.

Keywords

Keyword

File modes (permissions)

Definition

Settings assigned to a file, influencing the access privileges of User(Host), Guest(not user, same terminal), and World(everyone else).

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

  • Matthew Haas, The Lair, in CSCS1730 class.
  • Dj Dates, C208 CCC, in CSCS1200 class.

unix Keyword 1 Phase 2

file copying/moving/renaming

Definition

File copying- When you of make a copy of a file or folder using the command cp. File moving- When you move a folder or file to a different location using the mv command. File renaming- When you rename a file or folder also uses the mv command.

References

Demonstration

Demonstration of the indicated keyword.

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ vim file1
lab46:~$ ls
Desktop    Music      Videos           closet   public_html
Documents  Pictures   archive1.tar.gz  file.c   src
Downloads  Public     archive2.zip     file.gz  the answer.txt
Maildir    Templates  archives         file1
lab46:~$ mv file1 file2
lab46:~$ ls
Desktop    Music      Videos           closet   public_html
Documents  Pictures   archive1.tar.gz  file.c   src
Downloads  Public     archive2.zip     file.gz  the answer.txt
Maildir    Templates  archives         file2
lab46:~$ mv file2 /home/khoose2/src/Unix/submit/Opus
lab46:~$ cd /home/khoose2/src/Unix/submit/Opus | ls
file2

Experiment 1

Question

How can you both rename and and move files using the same command?

Resources

Hypothesis

I hypothesize that the input 'mv file1 file2' will perform the action of changing the file name of 'file1' to 'file2'. I also hypothesize that the input 'mv file2 /home/khoose2/src/Unix/submit/Opus' will move the file 'file2' from the previous hypothesis test, to the final directory destination of Opus.

From what I have read it seems that the linux command 'mv' can be used to both rename and move files. The difference is the use of paths for moving files, and the use of file names when renaming.

Experiment

I will;

  1.) create a sample file named 'file1' by inputing the command 'vim file1'.
   A.) once in the vi text editor type ':wq', exiting the file and saving it.
   B.) enter the input command 'ls' to verify the creation of file 'file1'.
   B.) enter the input command 'mv file1 file2'.
   C.) enter 'ls' to verify the change of name to 'file2'.
  2.) enter the input command 'mv file2 /home/khoose2/src/Unix/submit/Opus'.
   A.) input the command 'cd /home/khoose2/src/Unix/submit/Opus | ls'; thus displaying the contents of the specified directory to verify the file 'file2' was successfully moved.
   

Data

lab46:~$ vim file1 lab46:~$ ls Desktop Music Videos closet public_html Documents Pictures archive1.tar.gz file.c src Downloads Public archive2.zip file.gz the answer.txt Maildir Templates archives file1 lab46:~$ mv file1 file2 lab46:~$ ls Desktop Music Videos closet public_html Documents Pictures archive1.tar.gz file.c src Downloads Public archive2.zip file.gz the answer.txt Maildir Templates archives file2 lab46:~$ mv file2 /home/khoose2/src/Unix/submit/Opus lab46:~$ cd /home/khoose2/src/Unix/submit/Opus | ls file2

Analysis

Based on the data collected:

  My hypothesis was correct, the actions I predicted were verified by my experiment and testing. There were no errors and the command were accepted without question.

Conclusions

Thanks to my experiment I illustrated the example of how the Linux command 'mv' can be used for both moving files and renaming files, depending on the use of paths or file names. This illustration proves my hypothesis correct.

Part 2

Entries

Entry 1: October 10th, 2012

Today we covered scripting and created a “self-aware” script. This script will store the name of the user and remember his name, without asking again, if the script is used again on the same terminal. The script is as follows:

#10-10script
#!/bin/bash
#
name="`cat ${0}.conf | grep '^name=' | cut -d'=' -f2 2>/dev/null`"
 if [ -z "${name}" ]; then
   echo -n "Who are you?"
   read name
   echo "Pleased to meet you, $name"
   echo "name=$name" > ${0}.conf
   elif [ ! -z "${1}" ]; then
   if [ ! "$name" = "$1" ];then
   echo "Intruder!"
   fi
   else
   echo "Welcome back, ${name}"
 fi

The use of 'f2' stands for the second field of an input, meaning it is the entry following the space after the originating command.

Lab46:~$ ./script5 bob abc

f1(field1)= './script5'

f2(field2)= 'bob'

f3(field3)= 'abc'

Entry 2: October 12th, 2012

In today's class we touched base on some C programming language and explored the four different Programming Paradigms;

1.) Structured/Imperative/Procedural

  1. C, Bash, C++, PHP, Python, Visual Basic

2.) Functional

  1. LISP

3.) Logical

  1. Prolog, Haskell

4.) Object Oriented

  1. C++, Java, Python, Eiffel, Smalltalk

Our first step into programming with the C language was the expected 'Hello World!' program which demonstrates output. The stated program is as follows;

#include <stdio.h>

int main()
{
  printf("Hello, World! \n");
  return (0)
} 

Entry 3: October 19, 2012

- Today we covered the use of grep, used to pull files matching the name, and sed, used to replace a pattern with something else. - This was extremely useful knowledge because it will help with data management later on in the course. - I wonder how exactly to set the parameters used with these operations in order for them to work efficiently.

lab46:~/src/class$ cat spring2013-20121026.html | grep '^<TH CLASS="ddtitle"'
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=90227">Orientation to Technology - 90227 - TECH 1050 - 001</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=90509">LabVIEW Programming - 90509 - TECH 1060 - 001</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=89682">Manufacturing Methods Lab - 89682 - TECH 1080 - 001</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=89648">Tech Word Process & Research - 89648 - TECH 1110 - 001</A></TH>

Entry 4: October 24, 2012

- Today we covered the use and application of Regular Expressions along with Extended Regular Expressions. - These will be vital in setting parameters for managing data.

Listed below are the expression and their use;

Regular Expressions:

$ -match end of line

\< -match beginning of word

\> -match end of word

. -match any single character

* -0 or more of previous

[] -character class: match any of enclosed

[^] -inverted “ ”: do not match any of enclosed

Extended Regular Expressions:

() - used for grouping

Keywords

unix Keyword 2

processes

Definition

Processes- programs or instances that operate concurrently with one another to produce a result.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

unix Keyword 2 Phase 2

dot files

Definition

A dot file is a file that is not normally visible using a basic ls command. These files tend to be configuration files for other programs, but not always.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

- http://www.cyberciti.biz/faq/bash-shell-display-only-hidden-dot-files/

Demonstration

Demonstration of the indicated keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ ls -a
.                .pinerc              Pictures
..               .profile             Public
.Xauthority      .recently-used.xbel  Templates
.addressbook     .ssh                 Videos
.bash_history    .swn                 abcdefghijklmnopqrstuvwxzy
.bash_logout     .swo                 archive1.tar.gz
.bashrc          .swp                 archive2.zip
.cache           .vim                 archives
.config          .viminfo             closet
.dbus            .vimrc               file.c
.fluxbox         .xinitrc             file.gz
.gstreamer-0.10  .xsession-errors     minecraft.jar
.gvfs            Desktop              public_html
.indent.pro      Documents            src
.irssi           Downloads            the answer.txt
.local           Maildir
.pine-passfile   Music

Experiment 2

Question

How can I sort a large list of files into a sorted list of legible text, using a single line of code?

Resources

Hypothesis

I know for a fact that it can be done, using the knowledge I already have along with things I will shortly learn. I predict the experiment will be a success.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment? I will use the course list of the 2012-2013 year as the victim of this experiment, I have copied it into my class directory prior to the beginning of this experiment.

1. Display the content of the html file

  a.) cat spring2013-20121026.html

2. Decide how to sort the files in question.

  a.) I will sort the according to class subject.
  b.) Using a combination of cat, grep, and sed, organize the data accordingly.

3. Document the input, and state success.

Data

Lab46:~$ cat spring2013-20121026.html | egrep '^<TH CLASS="ddtitle"'
    --- shows all classes, ussing the default layout pattern <TH CLASS="ddtitle" (SUCCESS)
    -Output example:
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=89752">Contemplative Meditation - 89752 - WELL 1505 - 002</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=89574">Introduction to Winemaking - 89574 - WINE 1010 - 001</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=89633">Tutor in Writing Center I - 89633 - WRIT 1701 - 001</A></TH>
<TH CLASS="ddtitle" scope="colgroup" ><A HREF="/PROD/bwckschd.p_disp_detail_sched?term_in=201330&amp;crn_in=90233">Tutor in Writing Center I - 90233 - WRIT 1701 - 002</A></TH>

Lab46:~$ cat spring2013-20121026.html | egrep '^<TH CLASS="ddtitle"'| sed 's/^<TH CLASS.*crn_in=.....">//g'
    --- shorten the output into a more manageable/legible format.
    -Output example:
Contemplative Meditation - 89752 - WELL 1505 - 002</A></TH>
Introduction to Winemaking - 89574 - WINE 1010 - 001</A></TH>
Tutor in Writing Center I - 89633 - WRIT 1701 - 001</A></TH>
Tutor in Writing Center I - 90233 - WRIT 1701 - 002</A></TH>

lab46:~/src/class$ cat spring2013-20121026.html |grep '^<TH CLASS="ddtitle"' | sed 's/^.*crn_in=.....">//g' |sed 's/<\/A><\/TH>$//g'| sed 's/^\(.*\) - \([0-9][0-9][0-9][0-9][0-9]\) - \(.*\) - \([0-9]*\)$/\3-\4:\2:\1/g'
    ---Rearrange data into an alphabetic format, with the subject first and the class name last on the line.
    -Output example:
WELL 1505-002:89752:Contemplative Meditation
WINE 1010-001:89574:Introduction to Winemaking
WRIT 1701-001:89633:Tutor in Writing Center I
WRIT 1701-002:90233:Tutor in Writing Center I

Analysis

Based on the data collected:

  • Was your hypothesis correct?

- Yes, I knew it was possible.

  • Was your hypothesis not applicable?

- I suppose so since my hypothesis was success, Matt is the teacher I cannot fail!

  • Is there more going on than you originally thought? (shortcomings in hypothesis)

- Yes, variables used exceeded my current knowledge, I had to seek out assistance from the teacher of the course.

  • What shortcomings might there be in your experiment?

- I needed to seek assistance in order to complete it, taking away from the feeling of self-accomplishment.

  • What shortcomings might there be in your data?

- I did not provide the full data output in the data section as it would not all fit.

Conclusions

I found out that any kind of sorting can be done using one line, as long as pipes, cat, sed, and grep, operations are all used correctly. Both Regular Expressions and Extended Regular Expressions are used to set the parameters used in sorting the data.

Part 3

Entries

Entry 1: October 17, 2012

Today we went over the creation of a C script capable of calculating the average of 4 numbers entered by the user;

 //10-17script
#include<stdio.h>
 
int main()
 {
    int a, b, c, d;
    float e;
 
    fprintf(stdout, "Please enter nubmer 1: ");
    fscanf(stdin, "%d", &a);
    fprintf(stdout, "Please enter number 2: ");
    fscanf(stdin, "%d", &b);
    fprintf(stdout, "Please enter number 3: ");
    fscanf(stdin, "%d", &c);
    fprintf(stdout, "Please enter number 4: ");
    fscanf(stdin, "%d", &d);
    e=(float)(a+b+c+d)/4;
    fprintf(stdout, "The average is %f/n", e);
    return(0);
}

Entry 2: October 19, 2012

Today was dedicated to the explanation and manipulation of processes, including the 64 kill options. The SIG commands, used to kill processes, that we covered in class include; -1-SIGHUP (1st kill option) -2-SIGINT -3-SIGQUIT (sent every time 'x' button is clicked) -4-SIGILL (kills illegal functions) -9-SIGTERM (default kill, terminate) -15-SIGKILL (unavoidable kill)

Entry 3: November 2, 2012

Today we covered the use of 'grrasp:~$', including the use of flakes to send files to other computers. examples.) echo $Display =output environment who =output all environments xeyes -display flake01:5 =send x program 'eyes' to flake01:5 pkill xeyes =kills all xeyes you initialize xwininfo -root -display =screen details xhost minus =blocks new things from screen

Entry 4: November 9, 2012

Today we covered the following commands and their uses in class; -last = logins from now till start of month. -head = read the first part of a file -tail = output the last part of a file -paste = merge lines of files -comm = compare two sorted files line by line (show similarities) -diff = compare files line by line (shows differences) -join =join lines of two files to a common field.

Keywords

unix Keyword 3

diff/diff3/patch

Definition

Operations used to compare files, outputting their differences, and is often used to tell the differences between versions of the same file.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

unix Keyword 3 Phase 2

sort/uniq

Definition

The sort commands sorts the the lines of text files in order. You can use different arguments like -r to sort them in reverse order. The uniq command is used with the sort command to remove duplicate lines in the file that you are sorting. There are also arguments for uniq like -d that only prints duplicated lines or -u that only prints unique lines.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

Demonstration

Demonstration of the indicated keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows: SORT:

lab46:~/src/class$ vim testdata
'testdata'  
  1 alpha
  2 beta
  3 zeta
  4 kapa
  5 kapa
  6 sigma
  7 sigma
  8 foxtrot
  9 foxtrot
  10 delta
  11 hotel
lab46:~/src/class$ sort -d testdata
alpha
beta
delta
foxtrot
foxtrot
hotel
kapa
kapa
sigma
sigma
zeta

UNIQ:

lab46:~/src/class$ vim testdata
'testdata'  
  1 alpha
  2 beta
  3 zeta
  4 kapa
  5 kapa
  6 sigma
  7 sigma
  8 foxtrot
  9 foxtrot
  10 delta
  11 hotel
lab46:~/src/class$ uniq -d testdata
kapa
sigma
foxtrot

Experiment 3

Question

What is the question you'd like to pose for experimentation? State it here.

Is there a way you can find out if a pattern occurs in something consecutively, and in reverse. It seems like a complex process so I'm curious.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

It turns out that after some research, the thing I was curious about is defined as a palindrome, it is a string of letters or numbers that reads one way the same as it does the other.

(http://en.wikipedia.org/wiki/Palindrome) (http://www.fun-with-words.com/palin_explain.html)

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Based off of what I have read, and learned from other people, I believe it is more than possible to make a script that does what I'd like, as it seems there are many that already exist that do such a thing.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

I will construct a script which i will then change into an executable file, I will then feed it strings of text to see if it can correctly distinguish between palindromes and non-palindromes.

Data

Perform your experiment, and collect/document the results here.

  1 #script: exp3
  2 #this is to test strings for palindrome characteristics
  3  echo "String please :"
  4      read str
  5      len=`expr $str | wc -c`
  6      len=`expr $len - 1`
  7      mid=`expr $len / 2`
  8      flag=1
  9      m=1
 10      while [ $m -le $mid ]
 11      do
 12              c=`echo $str | cut -c$len`
 13              p=`echo $str | cut -c$m`
 14              if [ $c != $p ]
 15              then
 16                 flag=0
 17                 break
 18              fi
 19              m=`expr $m + 1`
 20             len=`expr $len - 1`
 21      done
 22      if [ $flag -eq 1 ]
lab46:~/src/Unix/submit/Opus$ ./exp3
String please :
cat
The string is not palindrome
lab46:~/src/Unix/submit/Opus$ ./exp3
String please :
boob
The string is palindrome
lab46:~/src/Unix/submit/Opus$

Analysis

Based on the data collected:

  • Was your hypothesis correct?

-Yes

  • Was your hypothesis not applicable?

-No, it was.

  • Is there more going on than you originally thought? (shortcomings in hypothesis)

-Yes, the logic is much more involved and the script much more complex than I would have originally guessed.

  • What shortcomings might there be in your experiment?

-Lack of personal knowledge prior to the planning of the experiment.

  • What shortcomings might there be in your data?

-Only two words were tested so as not to present irrelevant data past testing the script's functionality.

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.