Table of Contents

unix Keywords

Types of files (UNIX)

Definition

There are several types of files in the unix environment.

Demonstration

Regular Files: These are a common file within unix. It is a plain collection of bytes of data. Directory: These are a special type of file as they only contain other files. You do not work on a directory directly. Special Files: These are commonly known as the device files on unix. They are usually only owned by root and cannot be modified by the user.

File Manipulation (Unix)

There are several ways to manipulate files in an Unix system. Manipulation ranges from removing, creating, sharing, storing, copying, and editing.

Demonstration

Removing a file:

lab46:~$ rm file.txt
lab46:~$

Creating a file:

lab46:~$ touch file.txt
lab46:~$

Changing sharing settings on a file:

lab46:~$ chmod 777 file.txt
lab46:~$

Copying a file:

lab46:~$ cp file.txt file2.txt
lab46:~$

Editing a file (using vim):

lab46:~$ vim file.txt
~
~
~
~
~
~
~
~
~
~
~
~
Default                 0,0-1   All

Saving a file (with vim):

Random Text Here
~
~
~
~
~
~
~
~
~
~
:save file.txt

Text Processing

There are many commands for processing text within unix. Text Processing is the manipulation of text within the unix system.

Demonstration

grep, sort, tail, less, more, and echo.

Echo

Echo is a text manipulation tool that reads text back to the user. It is very useful for editing files without opening them in a text editor.

lab46:~$ echo hello
hello
lab46:~$
Sort

Sort is a nifty little tool that allows you to sort a file of random values and sort them by different means. Using -d will sort them by the dictionary, -n numerically, ect.

thakes3@lab46:~$ ls | sort -d
Backups
Cprog
Desktop
Documents
Downloads
Foxtrot
Maildir
Source_Code
Universe
Unix
bin
file.pie
pop
public_html
src
thakes3@lab46:~$ 
Tail

Tail is a neat little tool that allows you to read the last 10 lines of a file (by default). Several invocations allow you to manipulate and change what the tool does.

thakes3@lab46:~/Source_Code/ed_editor_vineeth$ tail GNU\ Public\ License.txt 

10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

NO WARRANTY

11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS
thakes3@lab46:~/Source_Code/ed_editor_vineeth$ 
Less

less is a filter for paging through text, based on the more command. It is different to more because it does not need to read in the entire file before editing

The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Preamble

The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.

Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and modification follow.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
GNU\ Public\ License.txt 
:q
thakes3@lab46~$:
More

More is a more primitive version of less that reads in the entire file before opening it for editing.

The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Preamble

The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to sh
are and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any 
other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your
 programs, too.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free 
software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free progr
ams; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain respo
nsibilities for you if you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, r
eceive or can get the source code. And you must show them these terms so they know their rights.

We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someo
ne else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' re
putations.

Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, i
n effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and modification follow.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public Licen
se. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, 
a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limita
tion in the term "modification".) Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the o
utput from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends 
on what the Program does.
--More--(26%)
:q
thakes3@lab46:~$
Grep

grep is an amazing tool that allows you to search for patterns in both files and folders. You can also search for a string or certain cases.

thakes3@lab46:~$ who | grep thakes3
thakes3  + pts/23       2012-04-27 22:47 00:39        2264 (172.16.198.142:S.0)
thakes3  + pts/32       2012-04-27 22:48   .          2569 (172.16.198.142:S.1)
thakes3@lab46:~$

The Unix Shell

The Unix Shell refers to the command programming language that speaks directly to the operating system in order to complete several tasks.

Different Shells

There are many different types of Unix Shells. A few important ones include:

Bourne shell (sh) - Was written by Steve Bourne of Bell labs and is available on every unix operating system C shell (csh) - Was written in the University of California, and is a shell written in C code that uses C code to execute scripts and such. TC shell (tcsh) - Is a public domain shell, and it has all of the functionality of the C shell with the emac's style editing of command line Korn shell (ksh) - This shell is also a public domain shell that uses both the c and the tc shell's features but with a shell programming language similar to the bourne shell. Bourne Again SHell (bash) - Is a public domain shell under the GNU project and has features from both the c shell and the ksh shell, yet directly programmable like the bourne shell.

Job Control

The ability to multitask on a Unix command line interface is very important. Having such abilities allows us to work on several things at once and allows us to be more versatile and efficient with whatever we are working on. For this we have such tools that allow us to switch easily between jobs.

Demonstration

Backgrounding and Foregrounding are a very nice way to run things in the background while working on the console at hand. Let's say I want to download a large file, like the iso file for Ubuntu (12.04 just came out). By adding a '&' to the end of the command, it is able to start in the background while I continue on other things.

lab46:~$ wget ubuntu* &
lab46:~$

Now I have my prompt back I am able to continue working. To resume that task all I need to do is type 'fg'.

lab46:~$ fg

[ =========>              ] 26%

Screen is another amazing multitasking tool that allows us to have multiple cli's open at once. It allows us to switch between screens and work on multiple files at once by splitting the terminal down. To open a screen just type in 'screen', as an alias in lab46 is already in place. This will open a new cli with a completely different .bash_history.

The Unix Programming Environment

The Unix interface is a special one in that it was designed by programmers for programmers. It holds several tools in it's system to both create and maintain code and provide an environment for others to do the same. From text editors to compilers, the Unix environment is designed for programming.

Demonstration

The Unix programming environment has tools created by those beautiful folks over at GNU, that allow compiling upon the installation of the os. This is very useful as in some instances people cannot access the internet or do not have the means to get another compiler.

The GNU Compiler Collection (GCC) contains front ends for C, C++, Objective-C, Fortran, Java, Ada, and Go, as well as many other languages.

The native text editors such as pico or vi, are very powerful tools. They allow easy editing, quick saving, and several helpful tools such as syntax highlighting, finding, over riding, and other great tools that systems such as a windows platform may not come with.

In most platforms of unix, there are easy to use tools to download and install applications written by other peoples in repositories. Such tools include apt-get, aptitude, yum, ect.

Compiler, Assembler, Linker , Loader

These are some of the stages of compilation in the C programming language. They all provide a specific roll in creating programs that run on the computer.

Demonstration

Compiler - Does the lexical analysis by breaking the code into pieces and then checks them for correctness. It then generates a lower level code from the code written. It then looks for possible flaws in the programs logic, and then generates assembly code.

Assembler - Translate the assembly code given from the compiler into the system specific object code.

Linker - Links the object code with some other libraries to make it run-able

Loader - Executes the program on a system specific platform

Pattern Matching

Pattern matching is a neat little process that allows us to decipher text from either files or other processes outputting text. We can choose to display what we want to display.

Demonstration

Pattern matching in unix is quite fun really. We can look for common identifiers between files, such as the tailing file type or the use of vowels.

For this example I have created a file named file.txt that holds several words.

This is the inside of the document

Puppy
Kitty
Cow
sheep
elephant
alligator

Now I will make use of the command “grep” and it's ability to match certain patterns within words. I will grep for the vowel 'o' and what words contain them

lab46:~$ grep [o] file.txt
Cow
alligator
lab46:~$

unix Objective

unix Objective

State the course objective

Definition

In your own words, define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.