Table of Contents

Part 3

Entries

November 2011

November 2011

November 2011

November 2011

unix Topics

Home directory

The home directory is YOUR directory. It is where all of a users personal files should be kept the only one with the ability to alter anything in a home directory is the user. (permissions, removing, etc) Permissions can be set for other users to enter the directory at all, and or view anything in the directory. Cd will return the user to the home directory for that user.

lab46:~$ "This is what the prompt looks like in the home directory"

Ownership

Ownership of a file is determined by who created the file. If permissions permit it files can be copied and manipulated from the copy should the owner not want the original file altered.

lab46:~$ touch file
lab46:~$ nano file
lab46:~$ vi file

Pattern Matching

Pattern matching is a very useful skill to posses when working with regular expressions. Being able to find a pattern, and tell the system to alter replace or remove parts of or around that pattern makes data manipulation much more efficient.

lab46:~$ cat spring2012-20111103.html | grep "dddefault"
<TD CLASS="dddefault">Class</TD>
<TD CLASS="dddefault">9:40 am - 11:30 am</TD>
<TD CLASS="dddefault">MW</TD>
<TD CLASS="dddefault">Classroom C203</TD>
<TD CLASS="dddefault">Jan 23, 2012 - May 13, 2012</TD>
<TD CLASS="dddefault">Lecture</TD>
<TD CLASS="dddefault">Barbara L. Squires (<ABBR title= "Primary">P</ABBR>)<A HREF="mailto:squires@corning-cc.edu"    target="Barbara L. Squires" ><IMG SRC="/wtlgifs/web_email.gif" ALIGN="middle" ALT="E-mail" TITLE="E-mail"  NAME="web_email" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=28 WIDTH=28></A></TD>

With this particular example matching the “dddefault” pulls out only the lines with that pattern. The data can be further manipulated to display only the useful information within the file such as the time and location.

Tab Completion

The tab key can be used to complete a stuff. (for lack of a better way to explain it) This is very useful in saving time and effort when typing as all you need for a completion is enough of a matching at the beginning of said stuff.

lab46:~$ cat fi(tab)
"This is an example"

Program vs. Process

A program would be code that has to be compiled in order to perform its functions. A process would be run directly from the shell with no compiling required. An example would be a C tetris program vs. cating a file.

Moving/Renaming

Files can be moved and renamed as long as permissions permit whenever wanted or necessary. For example I went through my home directory and created directories for similar files then proceeded to move those files into the directories. Moving and renaming can be done with “mv.” To move a file use mv file destination. To rename a file use mv file newfile.

lab46:~$ mv file Files
lab46:~$ mv file newfile

Netiquette, Security

Netiquette is as defined by wikkipedia a set of social conventions that facilitate interaction over networks. From a unix standpoint it would be the social interactions on the network. Proper netiquette would would be respecting users privacy if you happen to have root access and just being generally polite while interacting with other users. Security in Unix is done easily and effectively. With every file needing to have permissions set to people beyond the owner and root as long as no one has the password for root or the UID files and information are secure.

Creating

Have you ever wanted to know what it feels like to be able to bring anything your heart desires into existence. With a Linux system you can with little more than a thought. Files of unthinkable power can be created with the touch command, or any text editor.

lab46:~$ touch universe
lab46:~$ vi mountain
lab46:~$ nano ocean
lab46:~$ ./world
Hello, World!

Text Processing

Text processing is essentially typing. A text processor such as vi, or nano can save the typed text for later use. The text in the then file can be changed at any time in any way provided permissions.

lab46:~$ vi file
Hi
Hello
Good day
Hola

Directory

The simplest way I can think to explain directories is to compare them to a windows system. They are kind of like (kind of like) folders in Windows. Directories are used to organize files and I believe they are called directories because of how Linux systems work, with the file system needing paths to locate and utilize files, directories as a term makes sense. You can change directories using the cd command. By itself cd will take you to your home directory, followed by a directory name (cd src) it will take you into that directory, and with a path it will take you wherever you want to go. (cd /home/../usr/games)

lab46:~$ cd src
lab46:~/src$ cd 
lab46:~$ cd /home/../usr/games
lab46:/usr/games$ cd
lab46:~$ 

Copying

Files within a Linux system can be copied. This is necessary for a million different reasons some examples may be the need to have a back up of the file, or needing to send the file to someone else while still having a “copy” of it for yourself. Whatever the reason copying files can be done with cp. The convenient method to copy text from a file or command line to a file is to highlight the desired text and press the middle mouse button (scroll wheel) if your mouse has one if not a simultaneous right and left click should work at the location you want the text. When copying a file the file with by default copy to the current working directory and it will only copy should you chose a new name for the file. Files can be copied from anywhere to anywhere with permissions and a path.

lab46:~$ cp file newfile
lab46:~$ ls
file newfile Files
lab46:~$ cp file Files
lab46:~$ cd Files
lab46:~$ ls
file

Compressing/Decompressing

Files in a Linux system can be compressed and decompressed. The compressing a file can be done with gzip, and decompressing a file can be done with gunzip. Compressing is usually only necessary for really large files and or saving space.

lab46:~$ gzip file
lab46:~$ ls
file.gz
lab46:~$ gunzip file
lab46:~$ ls
file

unix Objective

Objective

Understanding and use of pattern matching. To more efficiently collect, sort, or manipulate data patterns are incredibly useful as you need something to match when using regular expressions.

Method

I will find a file with a bunch of unnecessary data and extract the data that I want.

Measurement

Using the text document I found it was very easy to extract only the data I wanted after finding a pattern to use.

Analysis

Experiments

Experiment 1

Question

Can I use cron to determine the number of users on the system Tuesday and Thursday at 3:00pm with a small shell script.

Resources

UnixMages.com “A run in with Cron”

Hypothesis

I think it will work.

Based on my knowledge of shell scripting provided I do it correctly and my knowledge of cron, provided I do it correctly.

Experiment

I am going to sit in class on Tuesday and Thursday and wait to see if a new file pops up with the number of users contained in it.

Data

I waited in class and my cron1 file updated with the number of users on the system at 3:00 pm.

Analysis

Based on the data collected:

Conclusions

Cron works exactly as I read it to work. Very successful very pleased.

Experiment 2

Question

This was something that I just happened upon and decided to include it as an experiment just to put it in somewhere. So as a question to experimental purposes I am going to propose, can wc -l be used to produce a truly accurate count of users on the system.

Resources

Basic knowledge of commands

Hypothesis

Yes it will work

I know that wc -l produces a count of lines, so it is just a matter of finding the lines that should not be counted, and not counting them

Experiment

I am going to find out manually how many users are on the system, at the moment it is just me so that part is easy. I will then look at the lines that should not be included…(using who as opposed to w here) from there I will use a method of not including them and then count the lines with wc -l.

Data

who | grep -v “NAME” | wc -l 1

Analysis

Based on the data collected:

Conclusions

I can conclude that any count of users I have done throughout the semester has been off by at least 1 possibly more depending on multiple logins and what not due to how wc -l works. I do know now that if I want something that is 100% accurate I have to do a little more work.

Retest

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:

State Experiment

I will be retesting Derik Girard's experiment http://lab46.corning-cc.edu/opus/fall2011/dgirard3/start#experiment_1, his question was can I create a file with a space in the name.

Resources

Evaluate their resources and commentary. Answer the following questions:

Hypothesis

Something to the extent of I believe it can be done with quotes

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

Data

I used touch “experi ment” and created one file named experi ment

Analysis

Answer the following:

Conclusions

Answer the following: