User Tools

Site Tools


opus:spring2013:mgardne8:start

Matthew Gardner's spring2013 Opus

Test Chrome Edit</WRAP?>

Introduction

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

unix Journals

Week 1

This Week we used Screen to keep Irssi open for class chat.

Screen

To start a new screen use

Screen

To detach from a screen:

Ctrl-A And D

To list all screens use:

Screen -list

or

Screen -ls

To reatach to the most recent screen:

Screen -rd

To reatach to any screen session:

Screen -r <ID of screen>

To kill a screen session:

Screen -X -S <ID of screen> kill

IRSSI

To start IRSSI:

IRSSI

To connect to the Lab46 Chat server:

/server IRC

To list all channels:

/list

To join a channel:

/jon #<channel>

To switch between channels

Ctrl + LEFTARROW or RIGHTARROW

Misc Commands

List - List files in the current directory:

ls

Make Directory

mkdir <Directory name>

Alpine - Mail Client

Alpine

Nano - Text Editing

Nano [-C]

Week 2

This week covered some basic Utilities and some information on Archive handling

Archives

To untar a GZip'd tar (.tar.gz) use:

Tar -zxvf <Archive Name>

Quick reference at: http://www.computerhope.com/unix/utar.htm

To Unzip a regluar zip file (.zip) use:

unzip <Archive Name>

Quick reference at: http://linux.about.com/od/commands/a/blcmdl1_unzipx.htm

To create a GZip'd tar (.tar.gz) use:

tar -cvzf <Name.tar.gz> <directory/>

For example:

tar -cvzf Home.tar.gz home/
Misc Utilities and commands

Copy

cp <location/file> <new location/file>

Move/Rename - can be used to both move file to differnt locations and rename files

mv <orig> <new>

Remove/Deleate

rm <file>

Symbolic link - “A shortcut” if you will

ln -s <location/file> <2nd location/file>

Manual Pages:

man <command>

An example use would be:

man ls | more
Pipeline

Not covered but I feel it's imporant to add this week: http://en.wikipedia.org/wiki/Pipeline_(Unix)

Week 3

This week covered Naming Conventions and File/Directories

Naming Conventions

Always Remember: KISSBNOLTDEW

Keep It Simple Stupid Because No One Likes to Do Extra Work
Permissions

How to check:

ls -l
lab46:~$ ls -l
total 4
lrwxrwxrwx  1 mgardne8 lab46   18 Jan 20 13:54 Maildir -> /var/mail/mgardne8
-rw-r--r--  1 mgardne8 lab46    0 May  1 23:47 Tree.Txt
drwxr-xr-x  4 mgardne8 lab46   46 Jan 22 17:53 mgardne8
drwx-----x  2 mgardne8 lab46   53 May  2 00:01 public_html
drwx------ 12 mgardne8 lab46 4096 Apr 17 12:29 src
drwxr-xr-x  6 mgardne8 lab46   52 Jan 22 18:04 znc

How to edit:

chmod <0000> <file>

Where <0000> are your numeric representation of your permissions and <file> is the file you want to set permissions on

lab46:~$ chmod 644 Example.Txt
lab46:~$ ls -l
<snip>
-rw-r--r--  1 mgardne8 lab46   15 May  2 00:24 Example.Txt
<snip>
lab46:~$ chmod 600 Example.Txt
lab46:~$ ls -l
<snip>
-rw-------  1 mgardne8 lab46   15 May  2 00:24 Example.Txt
<snip>

Quick Reference

400     r——–             files (won’t let you accidentally erase)
444     r–r–r–           files (lets everyone read)
600     rw——-            files (no one else can read or see files)
644     rw-r–r–          files (owner can read/write, group read, public read)
664     rw-rw-r–         files (owner can read/write, group read/write, public read)
666     rw-rw-rw-        files (owner can read/write, group read/write, public read/write)
700     rwx——            programs and directories (Owner r/w/execute)
750     rwxr-x—          programs and directories etc
755     rwxr-xr-x        programs and directories etc
777     rwxrwxrwx        programs and directories etc
*Nix "Shortcuts"

Home Directory

Lab46:anyLocation$ cd ~

Or

lab46:~$ cd /
lab46:/$ cd home/
lab46:/home$ cd mgardne8/
lab46:~$

Relative Current directory

.

Parent directory

..
DIRECTORY TREES!!!!11!!111ONEONE11!!!!

Created using:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/' > ~/public_html/tree.txt

Command (Minus saving into a file) Stolen from: http://stackoverflow.com/questions/1581559/ascii-library-for-creating-pretty-directory-trees

My home dir:

 .
 |-mgardne8
 |---znc
 |-public_html
 |-src
 |---lab_1
 |-----Test_Compiles
 |---lab_2
 |---lab_3
 |---lab_4
 |---lab_6
 |---lab_7
 |---lab_phone
 |---scrap
 |---submit
 |-znc
 |---bin
 |---include
 |-----znc
 |---lib
 |-----pkgconfig
 |-----znc
 |---share
 |-----man
 |-------man1
 |-----znc
 |-------modules
 |---------blockuser
 |-----------tmpl
 |---------cert
 |-----------tmpl
 |---------certauth
 |-----------tmpl
 |---------lastseen
 |-----------tmpl
 |---------listsockets
 |-----------tmpl
 |---------notes
 |-----------files
 |-----------tmpl
 |---------perform
 |-----------tmpl
 |---------send_raw
 |-----------files
 |-----------tmpl
 |---------stickychan
 |-----------tmpl
 |---------webadmin
 |-----------files
 |-----------tmpl
 |-------webskins
 |---------_default_
 |-----------pub
 |-----------tmpl
 |---------dark-clouds
 |-----------pub
 |-----------tmpl
 |---------forest
 |-----------pub
 |-----------tmpl
 |---------ice
 |-----------pub
 |-----------tmpl
 

/var/public/unix

.
 |-archives
 |-cluster
 |-conf
 |-courselist
 |-cs6
 |-data
 |-devel
 |---archive
 |---multifile
 |-eoce
 |-ex3
 |-file
 |-filters
 |-final
 |-grep
 |-groups
 |---unix
 |---users
 |-lab12
 |-lab2
 |-list-archives
 |---spring2002
 |-misc
 |-multitask
 |-naming
 |---badname
 |-----challenge
 |-----example
 |-----exercise
 |-narrative
 |---a
 |-patterns
 |-puzzle
 |---script
 |-puzzlebox
 |-quests
 |-regex
 |-scripting
 |---project
 |-----output
 |-shell
 |-stuff
 |---examples
 |-web
 

/var/public/cpp

 .
 |-cli
 |-cs1
 |-cs3
 |-cs5
 |-cs99
 |-data
 |---spring2012
 |-----project4
 |-eoce
 |---spring2012
 |-----bn
 |---spring2013
 |-----game
 |-------images
 |-exam1
 |-examples
 |---overloaded_shapes
 |---spring2012
 |-----project1
 |-files
 |-final
 |-incomplete
 |-inheritance
 |-input
 |-interfaces
 |-lab0
 |-lab1
 |-lab3
 |-lab5
 |-lab6
 |-lab7
 |-lab8
 |-multifile
 |---exponentiator
 |---scores
 |-overloading
 |-pointers
 |---debug
 |-polymorphism
 |-recursion
 |-scope
 |-shapes
 |-templates

Week 4

TEXT TEXT AND MORE TEXT, WHOOO, OH, AND FILE TYPES, DON'T FORGET THOSE

MISC COMMANDS

VI - VIM - ANOTHER TEXT EDITOR THAT IS NOT NANO

vim [File]

MORE INFORMAN ON VIM CAN BE FOUND http://lab46.corning-cc.edu/haas/spring2013/unix/labs/lab3#the_vi_editor AND http://tnerual.eriogerg.free.fr/vimqrc.pdf

CAT - DISPLAY FILES ON SCREEN

cat <FILE>
lab46:~$ cat Example.Txt
BLAH BLAH BLAH

HEAD - DISPLAYS X LINES FROM THE TOP OF THE FILE

head -N <LINES> <FILE>
lab46:~$ head -N 1 Example.Txt
BLAH BLAH BLAH

TAIL - DISPLAYS X LINES FROM THE BOTTOM OF THE FILE

tail -N <LINES> <FILE>
lab46:~$ Tail -N 1 Example.Txt
BLAH BLAH BLAH

FILE - GIVES INFORMATION ON A FILE, SUCH AS WHEN IT WAS CREATED, AND WHAT TYPE OF FILE IT IS (NOT BASED ON THE EXTENSION)

file <FILE>
lab46:~$ file Example.Txt
Example.Txt: ASCII text
lab46:~$ file abcd.tar
abcd.tar: gzip compressed data, was "abcd.tar", from Unix, last modified: Wed Sep 22 16:02:40 2010, max compression
MISC FILES

.signature - THIS FILE IS USED TO ADD A SIGNATURE TO ALL MAIL SENT USING ALPINE

.plan - THIS FILE IS USED TO RESPOND TO ALL FINGERS

Week 5

“Break Week”

Week 6

Lets chat this week! Also learn about those less fun imporant control codes and Dot-Files that are not important at all, you'll never even notice a dot file, it's not like they are used for anything, with their special dot and all that jazz.

Imporant Control Codes

Interrupt

CTRL-C

End Of File

CTRL-D

Suspend

CTRL-Z

Escape Character

CTRL-[

Make It Ding CTRL-G

Imporant Files
.bash_Profile

Personal Settings for Bash

.bashrc

Called by .bash_profile

.exrc

Vi/ex Settings

.forward

Used for email forwarding

.pinerc

Pine settings

.vimrc

Vim settings

Imporant Environment Variables

Places system searches for executables

$Path
lab46:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin

The systems hostname

$HOSTNAME
lab46:~$ echo $HOSTNAME
lab46

The user running the command

$USER
lab46:~$ echo $USER
mgardne8

A variable you never ever mess with, unless you like to break stuff.

$TERM
lab46:~$ echo $TERM
xterm

The path to the default shell. (Shouldn't mess with this)

$SHELL
lab46:~$ echo $SHELL
/bin/bash
Misc Programs

Not going to go into detail in these programs/utilities

write
ytalk

Week 7

Wildcards, Input/Output Redirection and Web Pages. Oh my!

Wild Cards
*

Used to match 0 or more characters

?

Used to match exactly one character

[ ]

Used to match ANY of the contained characters

[^ ]

Uased to NOT match ANY of the contained characters

For example, in the following set of files:

file1 filea
file2 file1234
file3 fileZZZ
file4 file41

To search for list all files that contain only one character after the word “file” you would:

lab46:~/shell$ ls file?
file1  file2  file3  file4  filea

To list all files that end in a number between (inclusive) 1 and 3 you would:

lab46:~/shell$ ls *?[1-3]
file1  file2  file3  file41

Finally: To list all files that end in .Txt in your home Directory (And all sub-directories) you would do the following:

lab46:~/shell$ ls -R ~ | grep '.Txt'
Example.Txt
Tree.Txt
sometextfile.Txt

This method is CaSe SeNsAtIvE and will not pick up

.tXt
.TXT
.TXt
.txT

or any modification of capitalization.

Input/Output Redirection

The following chart was stolen from: http://lab46.corning-cc.edu/haas/spring2013/unix/labs/lab5

Symbol Description
> STDOUT redirection operator
>> STDOUT append redirection operator
< STDIN redirection operator
2> STDERR redirection operator
2>> STDERR append redirection operator
| pipe

Some example uses of these are:

To save the manual page of 'grep' as 'grep_manual.Txt'

lab46:~/shell$ man grep > grep_manual.Txt

To append some text to your Note.Txt file

lab46:~/shell$ cat Note.Txt
Note number 1
lab46:~/shell$ echo "Note number 2" >> Note.Txt
lab46:~/shell$ echo "Note number 3" >> Note.Txt
lab46:~/shell$ cat Note.Txt
Note number 1
Note number 2
Note number 3
lab46:~/shell$ cat Args.Txt
-a1 // does something something
-a4 // does something else
-b4 // something something blah blah
-c5 // more blahs
-abc1337 // the most imporant argument of them all!
-43x0R // Enables expert mode

To feed “Args.Txt” to the 'grep' command and search for all instances of the number '1' you would do the following:

lab46:~/shell$ grep '1' < Args.Txt
-a1 // does something something
-abc1337 // the most imporant argument of them all!

This could also be done without feeding Args.Txt via STDIN as grep supports reading files with:

lab46:~/shell$ grep '1' Args.Txt
-a1 // does something something
-abc1337 // the most imporant argument of them all!

Oh, and to find out how to enable expert mode!

lab46:~/shell$ grep 'expert' Args.Txt
-43x0R // Enables expert mode
Pagers

Pagers are used to, as I would describe them, “Buffer outputs in a way that a human can read them without going mad”

In short, More feeds 1 screens worth of information at a time, and can only advance in the file, while less feed 1 screens worth of information at a time, but can both advance and go back to what was already passed.

More information on more and less can be found in their man pages: http://unixhelp.ed.ac.uk/CGI/man-cgi?more http://unixhelp.ed.ac.uk/CGI/man-cgi?less

Quotes

These are what you have to use when people refused to

KISSBNOLTDEW

(See Week 3)

For example to use 'cat' on “Long File $PATH for Shell Lab.text” without using blackslashes, Tab completion or WildCards, you would:

lab46:~/shell$ cat /var/public/unix/shell/'Long File $PATH for Shell Lab.text'
Good work! You're done!
Web Pages. Oh my!

On lab46, Apache is configured to use the <server Ip or domain>/~user/ configuration(This is default if I recall correctly?) to allow each user the ability to host their own Web space.

To place files in your web space place them in the “public_html” Directory of your home folder.

For example, here are some of the contents of my “public_html” directory:

lab46:~/public_html$ ls *.txt
tree.txt  tree2.txt  tree3.txt

And each of those files are able to be accessed by going to

lab46.corning-cc.edu/~mgardne8/<file name>

http://lab46.corning-cc.edu/~mgardne8/tree.txt

http://lab46.corning-cc.edu/~mgardne8/tree2.txt

http://lab46.corning-cc.edu/~mgardne8/tree3.txt

Week 8

The joyous act of scripting!

Make Tedious tasks simple!

Save time and money!

Get your very own script today!

only 4 easy payments of nothing!

But wait, if you call in the next 20 years, we'll throw in some additional Nothing! A value of ABSOLUTELY NOTHING!

Running scripts

make sure the script file can be executed via it's permissions.

chmod +x <file>

then it's as simple as

./scriptname.sh
shabangs

To prevent using code meant for one shell being executed in another shell,(This could cause undesired results, or just plain not work) shabangs are placed on the _First_ line of the script.

The format for a shabang is

#!/path/to/shell -options

For these scripts bash will be used, so the shabang would be:

#!/bin/bash
Scripting Quick Reference
echo

Used to print text to the output:

Echo "Text"

Note: You can use the -n parameter to not print a newline character after the output

read

saves the next input as a variable

read Number12
echo $Number12
let

Doing (simple) Mathematics

let var1=$var1+var2
if/elif/else

Basic If selection Paramaters (As stolen from Lab6http://lab46.corning-cc.edu/haas/spring2013/unix/labs/lab6)

Symbol Description
-lt is less than
-gt is greater than
-eq is equal to
-le is less than or equal to
-ge is greater than or equal to
-ne is not equal to
if [ "$var1" -gt "$var2" ]; then
  echo "some text"
elif [ "$var1" -lt "$var2"]; then
  echo "some other text"
else
  echo "some else text"
For

The numeric version that is quite much like C++

let f=100
 
for((k=0; f>0; k++)); do
  echo "$k"
  let f=$f-$k
  echo "$f"
done
lab46:~$ ./testscript.sh
0
100
1
99
2
97
3
94
4
90
5
85
6
79
7
72
8
64
9
55
10
45
11
34
12
22
13
9
14
-5

The list version

for firstName in Jack Bob Fred Bill Murry James; do
  echo "$firstName Is a first name believe it or not!"
done
lab46:~$ ./testscript.sh
Jack Is a first name believe it or not!
Bob Is a first name believe it or not!
Fred Is a first name believe it or not!
Bill Is a first name believe it or not!
Murry Is a first name believe it or not!
James Is a first name believe it or not!
Quick Script to generate a simple webpage based on file in your current directory

Week 9

Week 10

Week 11

Week 12

Week 13

Slowly
Formating
And
Posting
EVERYTHING!

Oh, and generating example to use my Opiu that corolate to lab46, because I did everything on my home “ArchPI”

Portfolio

Please note that these are old and may not be current or even correct at this point.

opus/spring2013/mgardne8/start.txt · Last modified: 2013/08/25 12:16 by 127.0.0.1