Lee Gottshall's Fall 2011 Opus
I'm Lee.This is my first year at college and i'm majoring in Computer sciences. I work in a hospital kitchen part time and that's incidentally one of the reasons i'm going to college.I'm into a little bit of everything, I write, i game, i read a lot and i watch a ton of movies. Oh. I'm also a horrible procrastinator <_<
Today we learned some basic commands in Unix and were given some time to “play” by using the commands to explore the system.
Today we learned about extended command mode for VI and the control key combinations that allow you to do shortcuts for things like cut and paste.These should be useful tools in speeding up things like Shell Scripting assuming i can remember them.
Today we wrote a shell script that converts numbers from base 10 (normal numbers) to base 2 (binary). This was useful because it helped understand the thinking process to develop the psuedocode for an assignment in another class where we were to make psuedocode for a binary converter. This was also useful in understand relations between commands for other Shell Scripts.
Today we learned how to write the shell script for a basic bot using II or IRC Improved. This was a useful demonstration of how multiple commands work together to form a script and how to look at coding and break it down in a manner that allows you to see what part of the script does what.
Listing used by typing the command ls. Listing does a variety of things. ls lists current files and directories in whatever directory you may be in while ls -l lists files running on the system, who ran them and the permissions for the files. ls -a is used to find hidden files or directories that are excluded from the standard ls command through use of a . before the name.
lab46:~$ ls Downloads Maildir bin closet in irc link longcat motd public_html src tmp
lab46:~$ ls -a . .config .irssi .ssh closet src .. .dbus .local .viminfo in tmp .117.swp .fluxbox .mozilla .xinitrc irc .Xauthority .gconf .openoffice.org .xsession-errors link .bash_history .gconfd .pine-passfile Downloads longcat .bash_logout .gvfs .pinerc Maildir motd .bashrc .indent.pro .profile bin public_html
lab46:~$ ls -l total 16 drwxr-xr-x 2 lgottsha lab46 6 Sep 20 15:14 Downloads lrwxrwxrwx 1 lgottsha lab46 18 Aug 28 10:37 Maildir -> /var/mail/lgottsha drwxr-xr-x 2 lgottsha lab46 4096 Sep 29 16:46 bin drwxr-xr-x 2 lgottsha lab46 32 Sep 15 16:17 closet -rw-r--r-- 1 lgottsha lab46 15 Sep 29 14:59 in drwx------ 4 lgottsha lab46 39 Sep 29 14:55 irc lrwxrwxrwx 1 lgottsha lab46 4 Sep 1 14:45 link -> file -rw-r--r-- 1 lgottsha lab46 58 Sep 13 15:57 longcat -rw-r--r-- 1 lgottsha lab46 1310 Sep 15 15:15 motd drwx-----x 2 lgottsha lab46 6 Aug 26 2009 public_html drwx------ 3 lgottsha lab46 34 Jan 20 2011 src drwxr-xr-x 2 lgottsha lab46 84 Sep 22 16:46 tmp
Ownership is the display of the user who owns a file, owndership can be seen with the ls -l command which displays it in the third column of the results
lab46:~$ ls -l total 16 drwxr-xr-x 2 //**lgottsha*//* lab46 6 Sep 20 15:14 Downloads lrwxrwxrwx 1 lgottsha lab46 18 Aug 28 10:37 Maildir -> /var/mail/lgottsha drwxr-xr-x 2 lgottsha lab46 4096 Sep 29 16:46 bin
Permissions are a users consent to access a file, Viewed with the ls -l command there are permissions for editing, opening/ viewing and executable and are displayed as a W, R or X under the ls -l command. Where these are located determines who has which permissions be it the owner, another group or something else.
lrwxrwxrwx* 1 lgottsha lab46 18 Aug 28 10:37 Maildir -> /var/mail/lgottsha drwxr-xr-x*2 lgottsha lab46 4096 Sep 29 16:46 bin drwxr-xr-x* 2 lgottsha lab46 32 Sep 15 16:17 closet -rw-r--r--* 1 lgottsha lab46 15 Sep 29 14:59 in
* indicates the permissions line
VI text editors insert mode. The mode that allows VI to actually edit text with in a file. Initially entered through the use of lower case “i” after initializing VI there are multiple other commands to enter insert mode.
#!/bin/bash a=0 echo -n "Please enter a Number: " read number until [ $number -eq 0 ]; do n=0 until [ `echo "$number-2^$n"|bc` -lt 0 ];do let n=$n+1 done let n=$n-1 let number=$number-`echo "2^$n"|bc` places="" for((i=0;i<$n;i++)); do places="${places}0" done places="1${places}" let a=$a+$places done echo "the binary value is $a" exit 0 ~ ~ ~ -- INSERT -- 1,1 All
A file in VI's insert mode.
VI's command mode is the environment you are in when initially opening VI. In command mode you cannot edit text by typing but can use a variety of commands to perform different functions on the file instead. The simplest commands are :q to quit :w to save your file :wq to save then quit and :q! to quit without saving
#!/bin/bash a=0 echo -n "Please enter a Number: " read number until [ $number -eq 0 ]; do n=0 until [ `echo "$number-2^$n"|bc` -lt 0 ];do let n=$n+1 done let n=$n-1 let number=$number-`echo "2^$n"|bc` places="" for((i=0;i<$n;i++)); do places="${places}0" done places="1${places}" let a=$a+$places done echo "the binary value is $a" exit 0 ~ ~ ~ :q
A file in VI's Command Mode being given the command to quit.
regular files are files that are not links or directories most regular files appears gray in color and can be read via the cat command.
lab46:~$ ls Downloads Maildir bin closet in* irc link longcat* motd* public_html src tmp
*indicates the regular files in my directory
Directories are places where files are stored. Much like folders for GUI users of operating systems like Windows. when shown via the ls command directories are blue and if you have permissions you may enter them via the cd command. The command for a knew directory is mkdir “Directory name”
lab46:~$ ls Downloads* Maildir bin* closet* in irc* link longcat motd public_html* src* tmp*
* Indicates the directories within my home directory
Files that are neither directories nor regular files. special files are yellow by default and usually device files thatrepresent the hardware components of the machin
lab46:/dev/input$ ls by-path event0 event1 mice* mouse0*
*special files representing the Mouse
killing a process sends a signal to it telling it to terminate. While there are a variety of kill commands for various situations Kill -9 will kill any process that you can kill. to kil something find the process you want via the ps command and type the kill command followed by the processes PID number.
lab46:~$ ps USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND lgottsha 2449 0.0 0.0 8580 896 pts/38 RN+ 12:07 0:00 ps u lgottsha 7752 0.0 0.1 13640 2008 pts/38 SNs 09:42 0:00 -bash lgottsha 23924 0.0 0.1 13660 2004 pts/29 SNs Sep20 0:00 /bin/bash lgottsha 31149 0.0 0.6 157312 7272 pts/29 SNl+ Sep29 0:00 vi
The kill command for vi in this situation would be kill -9 31146
Shell scripting is where a script is written for the shell or command line that causes something to happen. Shell scripts for unix start with the #!/bin/bash line,the initial characters known as sh and bang and the rest of the line specifying that the script is intended to run on the bash shell. Scripts can be used for a variety of things and are considered one of the most basic programming languages.
#!/bin/bash #B35T 5R1PT 3V4R echo -n "please enter your name: " read name #put user input into name echo "Hi, $name, We've had a slight weapons malfunction here,but we're fine here now, everything fine. How're you?" exit 0 ~
The code of a simple script
Viewing files is done via the cat command. When viewed the files text will be displayed on screen, however not all files are viewable. When nonviewable files are ran through car they will cause random code to appear on the screen and the user will need to crtl C to unlock their terminal. Only regular files will always be viewable.
lab46:/usr/games$ cat monop ELF>@@@h@@@@@@À@@@@dqdq hqhq`hq`p qq`q` @@DDPåtdgg@g@Qåt/lib64/ld-linux-x86-64.so.2GNUGNU¬Pßù*Uê6Å u½«[%+#"$&%' !)*( 3ªÏ ]-bÊ@÷qFjÃî}±2¿V É(!:ÕvérO; __gmon_start__libc.so.6fflushstrcpygetwexitsprintfsrandfopensetregidperrorsignalputsputchargetpidsbrkcallocstrlengetcharfseekctimestdoutstrcasecmpgetgid__ctype_b_locerrcreatfreadclose__ctype_tolower_locerrx_IO_getc__libc_start_mainwrit%uiee__x/0s`*Ps`Xs``s`hs`ps`xs`ss`_2.2.5s` s`
The result of using car on a nonviewable file
lab46:~/bin$ cat Password Ah-ah-ah. You didn't say the magic word.
The result of using cat on the file Password.
The windows equivalent of deletion. to remove a file you'd use the rm command followed by the name of the file you want to remove and responding yes to the prompt “remove regular file 'filename'?” with yes. You can only remove files that you have permissions to.
lab46:~$ ls Downloads bin in link motd src trashfile Maildir closet irc longcat public_html tmp lab46:~$ rm trashfile rm: remove regular empty file `trashfile'? yes lab46:~$ ls Downloads Maildir bin closet in irc link longcat motd public_html src tmp
State the course objective; define what that objective entails.
State the method you will use for measuring successful academic/intellectual achievement of this objective.
Follow your method and obtain a measurement. Document the results here.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
is it possible to create a “menu” to the games directory using shell scripts?
www.unix.com google
That it will be possible to make a link to the games directory and show games available using the cd,echo and ls commands using the echo and cd commands will put the user in the directory and ls will display the avalible games while echo will ask the user to pick a game.
With shell script
#!/usr/games echo -n "would you like to play a game?:" read word if [ "$word" = "yes" ] then echo "`cd /usr/games`" echo "`ls`" echo "Pick a game, any game..." else echo"THEN, YOU SHALL NOT PASS" exit 1 fi exit 0
Was unable to get directory to change to the games directory. The rest of the script worked well but was useless without the cd.
Based on the data collected:
My hypothesis was incorrect, the script failed to execute as expected. Some variable must not be being taken into account.
Concept may be doable but needs something additional to support the CD command. CD will not execute because the script is taking place in a subshell.
What is the question you'd like to pose for experimentation? State it here.
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.
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.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
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.
What is the question you'd like to pose for experimentation? State it here.
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.
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.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
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.
Today we played with regular expressions in class and used them to sort through the dictionary. We learned regular expressions are helpful in finding things when you don't know exactly what you're looking for or don't know all of what your looking for.
Today we learned more regular expressions and were given time to play. Haas helped me figure out how to do the basics of my Spambot idea so he can now scream at anyone who talks to him ^.^
Today we played a bit with C programming after a conversation about the death of bills gates vs. the death of the producer of C. We wrote a script in C and then made the same script in Bash.
Today we had playtime to protest the cursed snow that has arrived early. I spent some time working on my bot.
Text Processing is the simple act of typing in a text editor. Unix has two main text editors. Nano, and VI. It's a lot like wordpad versus microsoft word. Nano is about as basic as you can get with nothing aside from the ability to enter text and save text files. VI, the “greatest text editor” ever however comes with a whole bunch of useful commands that allow you to edit your text in it's command mode, as well as an insert mode that allows you to simply edit text.
Compressing a file reduces it's size but makes it completely unacessable until it's Decompressed. The compression command for a file is gzip while the command to Decompress it gunzip. An example is shown below.
lab46:~$ ls Datatypes.c Hello.s bin data dl irc motd tmp Downloads Maildir closet datatyes hello link scripts uhoh Hello.c bashex cscript2.c datatypes in longcat src lab46:~$ gziplongcat -bash: gziplongcat: command not found lab46:~$ gzip longcat lab46:~$ ls Datatypes.c Hello.s bin data dl irc motd tmp Downloads Maildir closet datatyes hello link scripts uhoh Hello.c bashex cscript2.c datatypes in longcat.gz src lab46:~$ gunzip longcat.gz lab46:~$ ls Datatypes.c Hello.s bin data dl irc motd tmp Downloads Maildir closet datatyes hello link scripts uhoh Hello.c bashex cscript2.c datatypes in longcat src
Moving and renaming files are done with the move command mv. To rename a file you simply type mv followed by the filename and new desired name. To move them you type the name of the file followed by the directory you wish to put them in. Examples provided below.
lab46:~$ lab46:~$ ls Datatypes.c Hello.s bin data dl irc motd tmp Downloads Maildir closet datatyes hello link scripts uhoh Hello.c bashex cscript2.c datatypes in longcat src lab46:~$ mv longcat Catgnol lab46:~$ ls Catgnol Hello.c bashex cscript2.c datatypes in motd tmp Datatypes.c Hello.s bin data dl irc scripts uhoh Downloads Maildir closet datatyes hello link src lab46:~$ mv Catgnol /closet mv: cannot create regular file `/closet': Permission denied lab46:~$ mv Catgnol bin lab46:~$ ls Datatypes.c Hello.s bin data dl irc scripts uhoh Downloads Maildir closet datatyes hello link src Hello.c bashex cscript2.c datatypes in motd tmp lab46:~$
There are multiple ways to make files in Unix. You can create it with the Touch command by type “Touch” followed by the filename. You can also create a file using text editors Nano and VI by saving a blank document as the filename. An Example of the Touch Command is shown below.
lab46:~$ ls Datatypes.c Hello.s bin data dl irc scripts uhoh Downloads Maildir closet datatyes hello link src Hello.c bashex cscript2.c datatypes in motd tmp lab46:~$ touch AllHallowed lab46:~$ ls AllHallowed Hello.c bashex cscript2.c datatypes in motd tmp Datatypes.c Hello.s bin data dl irc scripts uhoh Downloads Maildir closet datatyes hello link src lab46:~$
Linking files is done with the ln command. Using ln -s and the filename followed by the linkname to create a link. An example is show below.
lab46:~$ ls AllHallowed Hello.c bashex cscript2.c datatypes in motd tmp Datatypes.c Hello.s bin data dl irc scripts uhoh Downloads Maildir closet datatyes hello link src lab46:~$ ln -s AllHallowed click lab46:~$ ls AllHallowed Hello.c bashex closet datatyes hello link src Datatypes.c Hello.s bin cscript2.c datatypes in motd tmp Downloads Maildir click data dl irc scripts uhoh lab46:~$ click -bash: click: command not found lab46:~$ cat click Happy Halloween lab46:~$
Copying a file just like on a GUI system like windows creates an exact duplicate of the file. Copying is done with the CP command followed by the file you wish to copy and the name of the new file. An example is shown below.
lab46:~/bin$ ls Binary Doomsday Password Script1.sh Script3.sh Script5.sh Spambot2.0 opusresults Catgnol IIRC Project Script2.sh Script4.sh Spambot hallow lab46:~/bin$ cp Password JPRef lab46:~/bin$ ls Binary Doomsday JPRef Project Script2.sh Script4.sh Spambot hallow Catgnol IIRC Password Script1.sh Script3.sh Script5.sh Spambot2.0 opusresults lab46:~/bin$ cat Password JPRef Ah-ah-ah. You didn't say the magic word. Ah-ah-ah. You didn't say the magic word.
C is a programming language that can be found on most computers today. Considered a 'lower' language, C can assume certain things such as using the word add instead of the addition symbol. Below is an example of C code.
#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
When typing on Unix, on the command line and then pressing tab after typing a partial command or filename will complete the file name. However if multiple files have the same beginning then you must put enough of the file name to differentiate them or tab complete wont' work.
A wild card is used to find part of a file name or find part of a term within a file and can be used to find files when you only have a part of their name or data. An example is shown below.
lab46:/usr$ lab46:/usr$ ls bin games include lib lib32 lib64 local man sbin share src lab46:/usr$ ls *[aeiouy]|wc -l 375 lab46:/usr$
375 files end in a vowel within the usr directory
Can be used to find information within files an examples is below
lab46:~$ ls AllHallowed Downloads Hello.s bashex closet data datatypes hello irc motd src uhoh Datatypes.c Hello.c Maildir bin cscript2.c datatyes dl in link scripts tmp lab46:~$ cat Datatypes.c |grep '^[one]*$'|less|wc -l 1 lab46:~$
The Datatypes.c files has exactly one “one” in it.
The local host is the host upon which your directly accessing from your location. in the case of our Unix class the local hos would be the Lab46 server.
A remote host differs from a local host in that it isn't part of the sever or system that you are on but you can access it. An examples of this would be running a program off of cloud storage.
Understand the workings of Shell scriptings
Pick apart one of the scripts we do in class and see if i can understand how things work.
I was able to understand the basics of how our Binary Number Converter worked.
#!/bin/bash a=0 echo -n "Please enter a Number: " read number until [ $number -eq 0 ]; do n=0 until [ `echo "$number-2^$n"|bc` -lt 0 ];do let n=$n+1 done let n=$n-1 let number=$number-`echo "2^$n"|bc` places="" for((i=0;i<$n;i++)); do places="${places}0" done places="1${places}" let a=$a+$places done echo "the binary value is $a" exit 0 lab46:~/bin$
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
A.I think i did acceptably at it. B.There's always room for improvement. C. Not really. Measuring your understanding can't really be given an exact definition D. Yes because it makes it a bit easier when writing code for scripting E. Not really. Most of it's just experience.
What is the question you'd like to pose for experimentation? State it here.
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.
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.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
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.
What is the question you'd like to pose for experimentation? State it here.
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.
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.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
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.
If you're doing an experiment instead of a retest, delete this section.
If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:
Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.
Evaluate their resources and commentary. Answer the following questions:
State their experiment's hypothesis. Answer the following questions:
Follow the steps given to recreate the original experiment. Answer the following questions:
Publish the data you have gained from your performing of the experiment here.
Answer the following:
Answer the following:
Today we learned how to use xcommands which cause images to appear on other peoples screens by connecting to the server their virtual machine was hosted on. This lead to much trolling and spamming of random anims and images. In addition we were given time to play with these commands and work on other projects.
Today we worked on taking the raw HTML for the CCC course listings and used regular expressions to pick out the bits of HTML coding that we didn't want to make it easier to read as well as to clean up the format a bit.The end form of the command we used to do this was around two and a half lines on the whiteboard
Today was a play and work on stuff day so we could get stuff done on our OPUS due to the upcoming break
Today we learned about EoCE, or the end of class experience, which is not a final exam, but a final experience of the class which is a totally and completely different thing than a final exam. Haas answered any questions we had about the EoCE before taking questions on everything else and giving us more play time while putting out small fires and burning children and such while discovering the interesting universe of Ryan VS. Dorkman.
Foregrounding a process brings it back from being backgrounded and allows you to resume using it. To Foreground a process you type the file name followed by fg.
Backgrounding a process frees up the terminal and allows you to do other things. To background a process simply type the filename followed by the ampersand (&). In order to bring the process back you will need to use the foreground command
Identification and definition of the chosen keyword. Substitute “keyword” with the actual 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:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual 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:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual 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:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual 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:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual 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:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
State the course objective; define what that objective entails.
State the method you will use for measuring successful academic/intellectual achievement of this objective.
Follow your method and obtain a measurement. Document the results here.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
can i write a script that allows me to compress files simply by typing their names?
Class, Opii
I think it will succeed.
gzip, the command use to compress files should be able to work in conjunction with the Echo command to allow me to make a title entry bar for the files i want to compress.
I'm going to write the script.
the script was successful in compressing the files run through it.
!/bin/bash echo "enter filename: " read word word=$word gzip $word exit
My Hypothesis was correct and is possibly applicable. The only real shortcoming is how limited the script is.
if something as like zipping a file can be made put into a script to simplify it then it's possible to do so with more advanced commands.
can i have a regular expression search through an entire directory?
Class, Opii
I think it will succeed.
Using the cat and ls commands with grep and there's no reason you shouldn't be able to add
I'm going to write the script.
could not get the command to work “ls usr |cat|grep '^[1]*$'|less|wc -l” only shows “0” regardless of the directory
Something must be wrong with the command.
Data suggests that the command i'm using is incorrectly structured. While my commands is faulty i think the objective is plausible.