Table of Contents

BIGDADDY's SEMESTER Opus

LAB46 FALL 2011

The 411

As a second semester student at Corning Community College, I am looking forward to learning the fundamentals of UNIX/Linux. Before I enrolled in the Computer Science program at CCC, I was a Store Manager for an automotive repair business. Three years ago I created a computer repair business and have been very successful on a part time basis. I decided that a career change was something that I wanted to persue, and enrolled at CCC. I hope to increase my knowledge of computers and networking and receive a degree. From there I hope to either persue my business full-time or find a career in the Computer Science field.

Part 1

Entries

September 1, 2011

LOL

Today I learned how to enter the email client called “Apline”. I would say that it is a very simple email program, that once you have learned some basic's is very easy to navigate. I struggled with entering the proper commands and then also found it difficut to move back to the menu after entering my inbox. Once I understood the basic keyboard shortcuts for composing messages, sending messages, and viewing messages I was off and running. I also tested the email client for delivering mail outside of the Lab46 network, and sending a message to my inbox from home. Both email test's were sucessfull in reaching there destination.

This was significant for me because accessing my class email is a productive and usefull task.

September 8th, 2011

Today I spent some time on the “man” or manual command. I have found this to be one of the most useful tools when casting spells with UNIX. With so many command prompt possibilities in UNIX it is impossible to memmorize all of the commands and flags. The manual command will open a help screen for that specific command, show you how it is entered, and will also list all of the flags and definitions pertaining to the command you have entered. To execute this command you simply type “man”(space)“command”; for example, if I wanted the manual page for the listing command (ls), I would enter the command as you see below.

lab46:~$man ls

If I wanted to learn more about the command “cat”, I would type the following:

lab46:~$man cat

When bringing up the manual page on a particular command it will define the command, list and define all flags associated with the command, give you a detailed description of the command, and also tell you the correct layout or proper use of the command.

I did find it challenging to sometimes understand the proper format for executing commands as expained in the manual, but I believe that to be more of an issue with my lack of paitence. This is probably one of the most important or significant commands available to the user. It's most significant use to me would be that with this command I do not have to memmorize all flags associated with each individual command. The “man” command is a huge resource at your fingertips and available at anytime.

September ,26th 2011

Today I learned the basic's of Shell Scripting in UNIX/Linux using the “vi editor”. Using “vi” the class wrote a shell script that converted Decimal base 10 to Binary base 2. Although I cannot recall from memory all the programming commands that made this possible, I was able to understand the process of making the progam do what we wanted. This was significant to me because I thought it was really exciting to brainstorm an idea, and implement that idea to code format via Vi text editor. It was also very exciting to see that the script we wrote worked and converted numbers perfectly.

September 29th, 2011

Today I learned about creating a chat bot through a Vi Text Editor, shell script. Creating a bot to communicate with other users on the chat forum is significant to me because you are communicating directly with a computer, via a pre-defined program script. It almost seems as if the chat bot has artificial intellegence and is communicating with you independently. I personally seem to be a little overwhelmed with the code syntax required for writing a shell script, but I am getting better every time I use it. Eventually I would like to further develop my chat bot as a project for the class.

Topics

Part 1:                                                             Part 2:                                                Part 3:
1.) Listing                         7.) File Types                  1.) Vi Text Editor               7.) Job Control       1.) Compiler                  7.) C       
 
2.) Remote Host                     8.) Regular Files               2.) Insert Mode                  8.) Tab Completion    2.) Regular Expression        8.) Compressing/Decompressing
 
3.) Killing a process               9.) Directory Files             3.) Command Mode                 9.) Viewing           3.) Ownership                 9.) Shell Scripting
 
4.) Local Host                     10.) Pseudo Files                4.) Foregrounding a process     10.) The Unix Shell    4.) Permissions               10.) Text Processing
 
5.) Home Directory                 11.) Removing Files              5.) Multitasking                11.) Copying           5.) Moving/Renaming           11.) Object Code
 
6.) Current Working Directory      12.) Backgrounding a process     6.) Signals                     12.) Creating          6.) VI Extended Command Mode  12.) Linker
 

Keyword 1

Listing:

The list command allows the user to see the names of files and subdirectories in your current working directory. The command for listing is represented by the abreviation “ls”. When using list in UNIX/Linux you can also apply some flags to the listing command. Flags are commands typed in after the list command that will provide specific information taylored to your needs. I have noted most of the “ls” command flags below. The first block defines each flag, and the second block shows the commands as they would be typed at the command prompt.

ls -l --> Lists in long format and provides much more information
ls -a --> List's all files
ls -s --> Gives the size of the files
ls -t --> Sorts files by the time modified rather than by file name
ls -f --> Marks directories with a trailing slash, and executable files with a trailing asterisk
ls -r --> Recursively lists subdirectories
lab46:~$ls -a
lab46:~/ls -s
lab46:~/ls -t
lab46:~/ls -l
lab46:~/ls -f
lab46:~/ls -r

Keyword 2

Remote Host:

Remote Host's are computers that are not accessed by end-user's directly, but instead are accessed from a different location, via the internet. In most casses remote host's are referred to as servers. A servers primary role is to store data that can be retrieved from a end-user, or multiple end-users, through a remote connection over a network. A remote host can also be a user's computer that is accessed over the internet for purposes such as remote control operations, and file transfers. For a computer system to be considered a “Remote Host” it has to have some software that provides the structure or protocol for a browser based working enviroment, such as a server based operating system, or a application process that establishes a remote connection to another PC.

For example:

From my home in Horseheads, I can access Corning Community College's Lab46 UNIX/Linux terminal. I have to run application software, like Putty, on my computer in order to log on to the Lab46 server. Putty is a software system that provides a UNIX/Linux based shell or working enviroment that will allow me to communicate remotely to the College's UNIX/Linux server. Once connected to the server, Putty will allow me to access or “retrieve” data over the internet, and without being anywhere near the college's direct network. In this scenario, both computers, once connected could be considered a Remote Host.

Keyword 3

Killing a Process:

The “kill” program in UNIX/Linux is a very powerful command that can send a signal to a process or terminate it entirely. Programs by nature will constantly run until the user commands the program to stop, or the program finishes its task. However, sometimes a program will freeze up and not allow the user to communicate through the keyboard. Usually executing a “^C” (Ctrl C) or typing “quit” at the command prompt will send and interrupt signal to the running process and terminate the program. In some cases a running program may encounter a error and freeze any input from a keyboard. In this situation executing “^C” or typing “quit” at the command prompt will not work. This is one time where the “kill” command will be useful. Terminating background processes is also another useful way to use the “kill” command. Background processes do not read or accept commands from the keyboard and the background program cannot be accessed directly. This situation is very common and a great exercise for the “kill” command. To kill a process you first have to determine what the “PID” or Process ID is. This can be done by typing the “ps” command at the prompt. This command will list all running currently running processes, and also display's the PID number. Once you have located the PID number of the process you want to kill you would then type, at the command prompt, kill [PID].

This is an example of how it would look at the command line:

lab46:~$ ps
User     PID   %CPU %MEM   VSZ   RSS   TTY     STAT  START  TIME  COMMAND
ccaccia  23078  0.0  0.1  13668  2044  pts/60   SNs  Sep27  1:11   irssi
lab46:~$ kill 23078
lab46:~$ ps
User     PID   %CPU %MEM   VSZ   RSS   TTY     STAT  START  TIME  COMMAND

lab46:~$

Typing the command: “kill 23078” would kill or terminate to process running on PID# 23078 as seen above.

Keyword 4

Local Host:

Local hosts are the computers that a program or application is physically running on. For example, if you're at home on your PC and open your web browser your machine is considered to be the local host because you are running the application on the same machine. Local hosts, like remote hosts, are identified by their IP address. The IP address for a local host is always “127.0.0.1”. The reason for this is because the 127.0.0.1 IP address is considered to be a “loopback” address. Any data or information sent to it will be routed directly back to the local machine.

Keyword 5

Home Directory:

The home directory is a directory that contains files for a specific “userid”. When logging into the UNIX/Linux server, by default you are put in your home directory. Therefore you can say that the home directory is by default your current working directory as soon as you login. If you “cd” into a different directory then you are moving out of your home directory and the new directory you have entered then becomes the current working directory. At anytime, if you want to get back to your home directory, simply type the command “cd” without a following directory name and you will be taken back to your home directory.

lab46:~$ pwd
/home/userid ----> (default Home Directory)
lab46:~$ cd bin
lab46:~/bin$ pwd
/home/userid/bin ----> (new current working directory)
lab46:~/bin$ cd
lab46:~$ pwd
/home/userid ----> (back to default Home Directory)
lab46:~$

Keyword 6

Current Working Directory:

The current working directory is defined as the “default” directory used as a command line. To change your current directroy you have to type the command “cd” (change directory) followed by the directory name you want to enter. To display the current working directory you enter “pwd” at the command line, which will list the name of the directory you are currently in. UNIX/Linux is a hierarchical file system. This means that all directories and files are created from a default home directory and are built from there. In the example below I have shown what happens when you display the current working directory and also change it. To return to the default root directory simply entering the command “cd” by itself will take you there.

lab46:~$ cd tmp
lab46:~/tmp$ cd bin
lab46:~/tmp/bin$ pwd
/home/userid/tmp/bin
lab46:~/tmp/bin$ cd
lab46:~$

Keyword 7

File Types:

A file is defined as “Any source, with a name, from which data can be read”. A file in UNIX/Linux is the core of it's exsistance. Everything as related to UNIX, is a file. There are three basic file types in UNIX/Linux, a regular or ordinary file, a directroy file, and a special or pseudo file. UNIX is a hierarchical system of files, some files are stored as text, some files are designed to be executed, and some files serve a purpose for a specific program or process. Reguardless of the purpose each file serves, I think it is important to understand that creating and deleting files

In UNIX you can determine what type of file you have by executing the ls -l command. Executing this command will bring up a list of all files in the working directory. The “-l” is added to the ls command because it will provide more information on that directory such as permissions and file types. When looking at the result of your ls -l command you want to look at the first position on the permission line. If it is blank (-) then you are looking at a ordinary or regular file, if it is a (d) or (l) then it would be a directory file, and anything else would be considered a special or pseudo file.

lab46:~$ ls -l
total 4 
lrwxrwxrwx 1 ccaccia lab46   17 Aug 28 10:37 Maildir -> /var/mail/ccaccia
drwxr-xr-x 2 ccaccia lab46 4096 Sep 29 16:39 bigdaddy
-rw-r--r-- 3 ccaccia Lab46    6 Sep 08 16:14 motd
crw-r--r-- 4 ccaccia Lab46    9 Aug 29 12:14 pseudo file
lab46:~$ 

The first digit of the permission line indicates file type. In this example I have surrounded the file type with a “(_)”. I have also cut out all data with the exception of the file permission.

(l)rwxrwxrwx  (l)= Link Directory File (Still directory)
(d)rwxr-xr-x  (d)= Directory File
(-)rw-r--r--  (-)= Regular or Ordinary file
(c)rw-r--r--  (c)= special or pseudo file

Keyword 8

Regular Files:

Regular files are the most common files and are also what most people associate with the word, file. Regular files consist of data that is written to some sort of storage device, like hard Optical storage disc's, or hard drive disc's. Regular files can also be broken down in to two types of files, text and binary files. Text files are lines of data containing language characters like letters, numbers, punctuation, symbols, spaces, and tabs. Binary files do not contain text based files, but instead, they contain data that only makes sense to programs, when executed. Binary files contain the computer instructions for executing a program, and text files would be the data stored as a result of the user accessing or editing a file within a specific program. For example: the program “vi text editor” is stored as a binary file, because it is a file that the computer has to execute to open a program. The binary file for the text editor creates the shell for the program to operate, and stores the text data a user creates or edit's while using the program. Once you have created a shell script or a few lines of notes, you then save the file you created or edited for later use as a text file. Files such as video, music, pictures, spread sheets are stored as Binary files because they rely on another program, or process to interpret and execute the file.

Keyword 9

Directory Files:

Directory files are the organizational tool for the UNIX/Linux operating system and create the infrastructure of the Hierarchical filesystem. These files do not contain or hold regular data, but instead are used to access and organize other files. Along with organizing and accessing the file system, directory files can also exist within each other. Directory files can be created and deleted by the end-user depending on their specific needs. Directory files could be viewed as houses in a neighborhood, each house contains data for a specific purpose and is then organized for access by programs, processes, or end-users. This is repeated for each house in the neighborhood, some houses contain device files, some contain regular files, some contain special files, and some contain more directories with files or another directory inside of them. Each house in the neighborhood stores data for an specific purpose, and like houses are numbered, directory files are also assigned names for identification later. In my opinion, I feel directory files are the bone structure to the entire UNIX/Linux system. Without this file type all data stored in an operating system would be un-organized and difficult, if not impossible, to access quickly when needed.

Keyword 10

Pseudo Files:

Pseudo files are very unique to the UNIX/Linux operating system. As discussed earlier in my opus, both Regular files and Directory files house data on a storage device. Because they hold data they will vary in size. Directory files in particular could require a lot of space on a storage device because they contain regular files, Pseudo files, and other directory files. Pseudo files, on the other hand, do not require much space on a storage device because they do not “store data”. These types of files, in most cases, are designed to communicate directly with the kernel of a computer system. Pseudo files exist to provide a service for a physical hardware device, such as a keyboard, printer, monitor, and hard drives. Pseudo files consist of many different types of files. A device file, or special file for example, is the software's representation of a hardware device in, or connected to the computer system. Another type of pseudo file is called a “named pipe”. Theses file types allow you to connect the output of one command or process to the input of another. The last pseudo file type I will mention is a “Proc File”. A proc file is designed to allow the user to view and sometimes edit data within the kernel. Proc files allow for direct communication and translation between computer's device processes, and the end-user.

Keyword 11

Removing Files:

Removing files in the UNIX/Linux system depends on the file type your removing. Directory files require a specific “remove” command that is slightly different from removing other file types. To remove a directory you will need the command, “rmdir”, which is short for “remove directory”. Removing all other file types requires the UNIX/Linux command, “rm”, or “remove”. There is a particular format that needs to be followed in order remove a file. At the command line prompt in UNIX you have to follow correct syntax by typing the command, followed by a space, then an “option” (if needed), then the name of the file type you want to remove. Adding an option after the command will allow you to specifically remove certain parts of files within a directory. In the manual page for removing files the syntax format is listed as: rm [OPTION]… FILENAME or DIRECTORY. Options are not a necessary requirement for removing a file, however, using an option can remove files, tailored specifically to your needs. In the example below I have displayed the process for removing a regular file, and also a directory.

lab46:~$ ls
Maildir  bigdaddy  bin  closet  irc
lab46:~$ cd bin
lab46:~/bin$ ls
test
lab46:~/bin$ rm test
rm: remove regular file `test`? (y)
lab46:~/bin$ cd
lab46:~$ ls
Maildir  bigdaddy  bin  closet  irc
lab46:~$ rmdir bin
lab46:~$ls
Maildir  bigdaddy  closet  irc
lab46:~$ 

sadf

Keyword 12

Backgrounding a Process:

Running programs in UNIX/Linux is a process of reading input from a keyboard and then writing the output to a monitor. This is a process UNIX/Linux describes as reading from stdin, or standard input, and then writing to stdout, or standard output. Most command based programs in UNIX are processed sequentially, or the command is input and the user is left waiting for that command to execute to standard output before you can type another command. Programs that run this way are called Foreground processes, meaning they run in the foreground and need to complete execution before moving on to another command. In most situations this is the type of environment a end-user will operate within. However, sometimes programs take a long period of time to execute and complete a commanded task. Rather than wait for the program to write to standard output, you can send the program to the background, to finish it's task. This allows the end-user to continue with another command in the foreground, while the computer executes the original program in the background. This is a very powerful tool in UNIX because it essentially allows you to multi-task in a command based operating environment. Once the original program completes it's assignment it will then send the result to standard output and appear on your display. As a end-user it is very important, when running background processes, to be alert as to when the standard output is sent to the monitor because it will appear on your UNIX terminal, mixed in with whatever commands you are currently working on in the foreground. To send a program to the background to execute you need to add a “&” (ampersand) to the end of the command. Providing the command was entered properly, the process will be sent to the background for completion. At times a background process may produce a standard error because it's trying to read from standard input, which does not exist in a background process, and may pause indefinitely waiting for the end-user to input the required data. The only thing possible in this situation would be to bring the background process to the foreground. This can be completed by using the command “fg %(job#)”. Once this command is executed the selected background process will be moved to the foreground, and then be available for standard input.

As a side note, if you're not sure if you have a background process running you can type “jobs -l” at the command prompt and the system will display to output what current processes are running in the background.

Below I have displayed an example in the UNIX environment for sending processes to the background, listing all processes currently running in the background, and then bringing the background process to the foreground. I will be executing a chat bot program, and then sending it to the background to process so I can continue with another command. Once I have completed the multi-tasking I will then bring the background process back to the foreground.

lab46:~$ ls
Maildir  bigdaddy  bin  src  motd  closer  public_html 
lab46:~$ cd bigdaddy
lab46:~/bigdaddy$ ls
bigdaddybot.sh  script1.sh  script2.sh  script3.sh  notes  commands
lab46:~$ ./bigdaddybot.sh &
[1] 6599
lab46:~/bigdaddy$ pwd
home/userid/bigdaddy
lab46:~/bigdaddy$ jobs -l
[1]+ 6599 Running    ./bigdaddybot.sh &
lab46:~/bigdaddy$ fg %1
./bigdaddybot.sh
^C  --> The bot is on a continuous loop and will run until ^C is entered
lab46:~/bigdaddy$ jobs -l
lab46:~/bigdaddy$

Objectives

Objective 1

Create an executable program what will launch me into my Alpine e-mail client without typing “alpine” at the command prompt. I would also like this executable program to be password protected.

Method

Using Vi Text Editor, create a shell script titled, “e”, that resides in my home directory and when executed, will take me directly to my Alpine inbox.

Measurement

Use shell script command code to create a password to access my Alpine email client. Using “if” and “fi” statements to provide or deny access to Alpine email inbox. If access is accepted you will be sent to Alpine immediately, if you mistype your password, you will be prompted to enter it again. Failing to enter the password correctly a second time will result in a “Goodbye” message and the program will terminate putting you back to the home directory command prompt.

Analysis

It took some time to understand the “if” and “fi” but success was ultimately achieved. The program works perfectly, entering the correct password at the first prompt will launch you into Alpine. Entering in incorrect the first time will prompt you to enter again. If the second password entry is correct you are taken to the Alpine login, and if entered incorrectly you will see a statement telling you “Access is denied…GOODBYE”. Failure to enter the correct password after the second time will terminate the program and put you at the command prompt of your home directory.

There is definitely room for improvement here! When successfully routed to the Alpine e-mail client you are prompted to enter your alpine password as well. It would be nice to have the shell script insert that password for you, being that you already entered a password when prompted by the shell script. I named the file “e”, for e-mail, to shorten the time you would normally use to enter in the six characters of “Alpine”. When executing the program in your default home directory the command to launch the script is: ( ./e ), reducing the number of characters from six to three.

For this example the correct password = tom

lab46:~$ ./e
Please enter your password: c
Access Denied

Please enter your password: cab
Access Denied.... GOODBYE
lab46:~$
lab46:~$ ./e
Please enter your password: t
Access Denied

Please enter your password: tom
Access Granted
Welcome "userid"... routing you to Alpine email client:

(Alpine login password:  ---> Opens Alpine home page)

lab46:~$

Experiments

Experiment 1

Question

How do I move a file from the current working directory to my home directory?

Resources

mv manual page, built into UNIX

mvdir manual page, built into UNIX

Hypothesis

According to the manual page on the mv or move command, when moving files from the working directory to the home directory, at the command prompt you will need to type “mv”… “filename” … “destination directory” and then press enter.

Experiment

I am going to test my hypothesis using a program called “Putty” which, will provide a UNIX/Linux environment to execute the mv commands. I will create a directory file called “testdir” and a regular file named “test” within my created directory. First I will move the “testdir” to my home directory, then will move the file “test” from within the testdir to the home directory. Upon completion both the testdir and the file test should reside seperatly in my home directory.

Data

Process worked well. I created a directory called “testdir” inside of another directory called “closet”. I changed directories to “closet” and typed the “ls” command to make sure the testdir was there, and it was. I typed the following in: mv testdir /home/ccaccia, and the move was sucessful. I changed directories back to my home directory and typed the “ls” command to view the files. Sure enough the directory testdir was now in my home directory. At the command prompt I then typed: mv /testdir/test /home/ccaccia, this moved the test file from my testdir directory to the home directory. I again typed the “ls” command at the home command prompt and both “testdir” and “test” where now seperated in my home directory.

Analysis

Based on the data collected my hypothesis was correct and worked well. There were no shortcomings in the experiment that I noticed.

Conclusions

Moving directory files or regular files in UNIX/Linux is really a very easy process. While performing the experiment I did learn that you do not have to “cd” into a directory if you want to move a file out of that directory. Simply typing in the “directory/file” would move that file from within the directory to the destination directroy, saving me a step.

Experiment 2

Question

How do we view a text file in UNIX/Linux

Resources

http://www.math.utah.edu/lab/unix/unix-commands.html

cat manual page within UNIX library

Hypothesis

Based on what I have read, to view a text file in UNIX/Linux, at the command prompt you type: cat “filename”. This standard input should take that text file and print it to standard output on my monitor.

Experiment

I am going to test this experiment using a ssh shell program called “Putty” from home to access the UNIX/Linux server. Once logged on to the server I will use the UNIX command environment to perform the experiment.

Data

lab46:~$ls
Maildir  bin  e  motd  src  test  tmp  bigdaddy
lab46:~$ cat test
This is a test.
This text file was created by yours truly, for purposes of casting spells in UNIX
I am now a full blown cat slayer

lab46:~$

Analysis

Based on the data collected, my hypothesis was correct! Bingo, bango, bongo…

Conclusions

This really was a very basic experiment. I find in incredible that by simply typing the word “cat” followed by a text document will send to standard output a copy of a text aquired through standard input. Like I said… really basic, but really neat as well.

Experiment 3

Question

Can I change the file permission on a directory I created, and will that also change the file permissions for text files within the directory?

Resources

Hypothesis

Based on what I have read I should be able to change file permissions for directories and regular files. According to what I have read, I will not be able to change the permissions in a file by changing the permission of the directory file it is in. However, I should be able to change the permissions for a file within a directory, while in my home directory. I should not have to “cd” into the directory that contains the file.

Experiment

I am going to test this experiment by loggin on to the UNIX/Linux server and applying my theory. I plan on changing a file permission of a directory, then through “ls -l” review the file permissions for regular files within the directory to see if they automaticaly changed as well. Then I will try and change the file permission for a file within a directory that is not my current working directory.

Data

lab46:~$ mkdir testdir
lab46:~$ cd testdir
lab46:~/testdir$ touch test
lab46:~/testdir$ touch test2
lab46:~/testdir$ ls -l
-rw-r--r-- 1 ccaccia lab46   0 Sep 15 14:15 test
-rw-r--r-- 1 ccaccia lab46  10 Sep 15 14:15 test2
Lab46:~/testdir$ cd
lab46:~$ chmod 777 testdir
lab46:~$ cd testdir
lab46:~/testdir$ ls -l
-rw-r--r-- 1 ccaccia lab46   0 Sep 15 14:15 test   --> File permission did not change
-r--r-- 1 ccaccia lab46  10 Sep 15 14:15 test2  --> File permission did not change
lab46:~/testdir$ cd
lab46:~$ chmod 777 testdir/test
lab46:~$ cd testdir
lab46:~/testdir$ ls -l
-rwxrxxrxx 1 ccaccia lab46   0 Sep 15 14:15 test ---> File permission **did** change!
-rw-r--r-- 1 ccaccia lab46  10 Sep 15 14:15 test2
lab46:~/testdir$ cd
lab46:~$

Analysis

The hypothesis was correct! I was not able to change file permissions for a directory and that change also be made for the regular files within the directroy. I was however able to change the file permission for a file not in my current working directory.

Conclusions

I really enjoyed this experiment. It really helped me see what I could and could not do when it comes to changing file permissions.

Part 2

Entries

October 20th, 2011

I have decided to install Ubuntu, Linux on my personal laptop at home. In the process of installing the operating system, I could not get the wireless network card to function. Today, I took my laptop to class and had my professor take a peek at it. I learned how to install a device driver in Linux using a terminal screen. This was of significance to me because I was able to take the fundamentals of what I have learned this semester and apply it in the “real world”. Although I was not able to complete the necessary process on my own, the help I received was priceless. Come to find out… it was not a driver issue in the end. It ended up being an issue of the kernel not seeing a needed file. Once we copied the necessary file to the proper location the wireless card took off and started to function properly. On a side note… I am enjoying the new operating system!

October 27th, 2011

Today I learned how the Unix/Linux shell terminal is really a CLI or command line interpreter. It forced me to see the terminal session slightly differently. I found it really interesting that the command prompt in a terminal session is really a CLI program waiting for me to enter a command and interact with the operating system. Once a command has been entered it is then up to the command line interpreter to interpret the command and execute it. This was significant to me because it connects the dots if you will with the statement that a command line prompt is where our Unix spells are cast. It finally makes sense!

October 17th, 2011

Today We created a small shell script using Unix/Linux in my Computer Essentials class. We used a Unix/Linux based operating system called Ubuntu. This operating system was downloaded and installed on a USB flash storage device. When the computer system boots the the USB flash device, the Ubuntu Unix/Linux operating system loads. The professor then instructed the students to open a terminal session and enter the text editor, nano. Once in nano, we were instructed to enter a basic shell script to demonstrate the programing capabilities of the Unix/Linux operating system. This was significant to me because once that terminal session opened up and the command prompt appeared, it was off to the races. It was great to know how the text editor operated and also the basic Unix commands to help navigate the process.

October 10th, 2011

Today I spent some time trying to understand the difference between a compiler and interpreter in Unix/Linux. I found that an interpreter's purpose is to interpret a command to machine language or binary. A compiler also interprets a human based code to machine language but also creates an executable file. The purpose of the executable file is to make a program code file run. I believe an interpreter will process the code line by line, whereas a compiler will run a source code as a separate program. I still have quite a bit to understand about both the compiler and interpreter but I really felt like the process is starting to click.

UNIX Topics

Part: 2

Keywords:

  1. VI Text Editor
  2. Insert Mode
  3. Command Mode
  4. Foregrounding a Process
  5. Multitasking
  6. Signals
  7. Job Control
  8. Tab Completion
  9. Viewing
  10. The UNIX Shell
  11. Copying
  12. Creating

Keyword 1

Vi Text Editor:

Vi text editor is a “screen-oriented” text editor that allows you to create text files and also programing files for bash or C. It operates within two different types of modes; Insert mode, and Normal Mode. To open vi text editor you need to enter “vi [filename]” at the command prompt in the terminal. Once vi opens, by default, you are in normal mode. Normal mode will allow you to use keyboard shortcuts to edit or perform command operations. Insert mode will allow you to physically edit or create a text body. Vi Text Editor's main advantage is that because command operations and the actual text editor work independently from each other, it allows the user to always have there hands on the keyboard. Vi was developed by Bill Joy in 1976, and was actually called “ex” at that time. Ex version 1.1 was released in March of 1978 and was not given the name we know it by today, vi, until version 2.0 was released in 1979 by Second Berkely Software Distribution.

Keyword 2

Insert Mode:

Insert mode or “input mode” as it is referred to, works as the actual text editor or word processor in vi. Once this mode has been initiated, the user can insert and edit text as necessary. When you open vi text editor, by default, you are placed in Command Mode. To initialize Insert Mode from command mode, the user has twelve different options to select from. The only difference in these twelve options is where the cursor will show up in the text body. Below I have documented six of the most common possibilities.

Initializing Insert Mode from Command Mode in Vi Text Editor:
 
press:
      a = changes to insert mode, after cursor position
      A = changes to insert mode, end of current line
      i = changes to insert mode, before cursor position
      I = changes to insert mode, start of current line
      o = changes to insert mode, below current line
      O = changes to insert mode, above current line

Once Insert Mode has been initialized and your cursor has been inserted for text editing in the text body, vi text editor is now in word processing mode. At this point pressing “a” will result in an “a” being typed into the text body. Anything entered into the text at this point is being directly inserted into the editing buffer of the program and you will know you're in Insert Mode because the word “INSERT” will appear at the bottom of the text editor. To get back to Command Mode from Insert Mode you simply just press the “esc” key on the keyboard. You will notice that the word “INSERT” will then disappear from the bottom of the text editor and your ready to prompt a command.

Keyword 3

Command Mode:

Command Mode in the vi text editor is where the keys typed are interpreted as commands. By default the vi text editor starts in Command Mode. In insert mode the typed key or text is directly added to the editing buffer of the program, and each key typed will be displayed in output, exactly the way it was typed. In command mode this is not the case. When the vi text editor was created, typical peripherals, like a mouse, where not used. So without a mouse, a system needed to be developed that would provide the user with access to commands and text editing, using one keyboard and the same keys. Command mode is the system that allows the user to do this. Command mode is entered by pressing the “esc” key on your keyboard. You will know that you are in command mode when the word “INSERT” is missing from the bottom of the text editor. In insert mode, pressing the keys: “dd” would result in the output on the screen to display the letters “dd” in your text body. When in command mode, pressing the keys: “dd” would not result in displaying the “dd” letters in the text body, but instead, “dd” will be interpreted as a command to delete the entire line your cursor is on. Command Mode has numerous commands prompted by typed letters or keys on the keyboard. This mode allows you to save your work, delete or copy line text, decide where the text cursor displays, and exit the program. Command mode and insert mode existing side by side and working together is what makes the vi text editor program a strong word processor. Without both mode's the program would not function efficiently and would probably not be used in today's world.

Keyword 4

Foregrounding a process:

Foregrounding a process in the Unix/Linux shell is part of the multitasking ability the operating system has when running processes. There are two ways to run a process in UNIX/Linux; Foregrounding a process, and backgrounding a process. Foregrounding processes are different from backgrounding processes, in that some foreground processes provide an interface for the user to interact with the process or program and most importantly, only one foreground process can be executed and completed at a time. Starting a foreground process only requires the user to type a command at the shell prompt. For example, the command “ls” is a process that will list all files in the current working directory. When “ls” is typed at the command prompt, as a user, you have just commanded that process to run in the foreground and you will not be able to enter another command until “ls” has finished its execution. While most commands are best suited for executing in a foreground environment, sometimes you will run a process that runs indefinetly until commanded to stop. This is why Unix/Linux is such a powerful multitasking operating system and also why backgrounding and foregrounding a process is so vital. In the example below a process was commanded to run from the foreground. The “&” symbol after the process will start the program in the background of the operating system. To bring the running program to the foreground, the command “fg” needs to be entered at the prompt. This will immediatly bring the running process to your foreground. In the example, the process being run is a chat bot. This process will run indefinetly until the user terminates the program. Because it will continue to run on its own and a foreground process can only complete one command at a time, the terminal shell will just hang up. To send the process back to the background, the user will need to press “^z”, which will suspend or stop the process and a command prompt will show up in the foreground. At the prompt, the user would then enter “bg”, which sends the running process to the background. One thing to keep in mind while foregrounding and backgrounding processes, is that the foregrounding process always takes priority over the backgrounding process.

lab46:~$ ./bigdaddybot.sh &
[1] 20096                              //--->started running process in background//
lab46:~/ jobs
[1]+  Running     ./bigdaddybot.sh &   //---> Shows Background Process//
lab46:~/ fg
./bigdaddybot.sh                       //---> Process was brought to foreground//
_^z
[1]+   Stopped    ./bigdaddybot.sh     // ---> <ctrl>z suspended the process//
lab46:~/ bg
[1]+ ./bigdaddybot.sh &
lab46:~/ jobs
[1]+  Running     ./bigdaddybot.sh &   //---> Process is now sent back to background//

Keyword 5

Multitasking in Unix:

Unix/Linux, by definition, is a multitasking operating system. There are many different ways that the operating system multitask's, but the best way of demonstrating the multitasking ablility would be through the foregrounding and backgrounding commands. In the Unix/Linux terminal session the command prompt exists in the foreground environment. Processes that are started in the foreground, would need to complete, in the foreground before another command can be initiated. Although this works for a lot of the UNIX/Linux commands, sometimes a process will continue to run, until commanded to terminate. In this situation, the running process will need to be multitasked to the background so that the user will be able to continue working on the foreground. It is important to know that running processes in the foreground, carry priority over processes running in the background. The ability for processes to be sent to the background to run and complete, while the user can be active in the foreground is what forms the backbone of multitasking in Unix. To start a process in the foreground, the only thing the user needs to do is login to there screen session and type a command. To run a process in the background, the user will need to add a “&” after the program or command. Once a process has been sent to the background from the foreground, it will continue to run until commanded to terminate or an encounter of an error. To bring the process back to the foreground the user will have to press “ctrl z”, which suspends the process, and then pressing “fg” will foreground the process. If the user needs to send the same process back to the background, the command “bg” would be typed at the command prompt. Below I have provided a screen session example of backgrounding and foregrounding a process.

lab46:~$ ./bigdaddybot.sh
^z
[1]+ Stopped     ./bigdaddybot.sh 
lab46:~/ bg
[1]+ ./bigdaddybot.sh &
lab46:~/ jobs
[1]+  Running     ./bigdaddybot.sh
lab46:~/ fg
./bigdaddybot.sh
^z
[1]+  Stopped    ./bigdaddybot.sh
lab46:~/ bg
[1]+  ./bigdaddybot.sh &
lab46:~/

Keyword 6

Signals:

Signals in Unix are a very powerful way of killing a process. A signal is by definition, a “asynchronous” notification that tells a process or program to terminate it's execution. This is accomplished by entering a certain key combination at a terminal command prompt, that causes the operating system to send an interrupt signal which will either suspend or terminate a running process. There are many different signals in Unix that all send specific interrupt signals to a program or process, that result in changing the “normal flow” of it's execution. The most common key combinations in the Unix/Linux operating system for sending an interrupt signal are ctrl-c, and ctrl-z. When a process is running, whether it be in the background or foreground, pressing ctrl-c will result in the operating system sending a INT signal (SIGINT) which causes the process to terminate. There are many other signals that will also stop a process, and even some signals that suspend a process. Pressing ctrl-z at the command prompt, while a process is running, will only suspend the process's execution. This is seen best when bringing a background process to the foreground. To complete this task the ctrl-z key combination is pressed at the command prompt to suspend the active process. Only then are you able to enter the “fg” command, bringing the process to the foreground. Signals are a great tool when a process encounters an error while executing. After encountering an error like this the user would not be able to enter a command at the prompt, the screen just seems to be frozen. Pressing ctrl-c, will result in an override kill signal, sent to the process, to terminate itself. Once the signal has been applied by the operating system the process terminates and the user's screen should be ready for a command. In the terminal shell below I have demonstrated a process that causes the O.S. to send a suspend interrupt signal, ctrl-c, to the foreground process, terminating the running program.

lab46:~$ ./bigdaddybot.sh   
_                               ---> Program has started running in the foreground, cursor just blinks...
^C                              ---> Ctrl-c executed,operating system sent a SIGINT kill signal to the process 
lab46:~/                        ---> Program was terminated, command prompt is ready.

Keyword 7

Job Control:

Job control in Unix/Linux can be defined as, and operating systems ability to execute multiple processes or programs at the same time. When using a Unix/Linux terminal, a user will by default, only have one process running at a time. Most commands can be executed by letting the program or process to take control of the terminal and then return control of the terminal back to the end-user when the task or command has completed. This is all done in the foreground of the Unix/Linux shell. However, some processes need time to execute and will not terminate until the process has completed, or the end-user terminates the program. In this situation, if the program or process is running in the foreground, then the terminal will not be available to the end-user until the said process either completes, or is terminated. This is why Unix/Linux uses a “background” command. Executing these types of processes in the background allows the terminal to be used for a different purpose. Foregrounding and Backgrounding is the fundamental core of job control in the Unix/Linux system. It allows the operating system to run a process in parallel with another process. Processes or programs that are running in the background are output to display when the command “jobs” is typed at the command prompt. Below I have started two text editors, nano and vi, in the background. In the foreground, I typed the command “jobs” at the command prompt and the list of running processes in the background is displayed. This is the “job control” environment of the Unix/Linux operating system.

lab46:~$ jobs               --->No jobs listed
lab46:~/nano &              ---> Started "nano" in background
[1] 28171
lab46:~/ vi &               --->Started "vi" in background
[2] 28172
[1]+  Stopped       nano
lab46:~/ jobs               ---> Job Control in UNIX
[1]-  Stopped       nano
[2]+  Stopped       vi
lab46:~/

Keyword 8

Tab Completion:

Tab completion is a utility of command line interpreters (CLI) that automatically fills in partially typed commands. To understand exactly what tab completion does, it is important to first understand what a command line interpreter is. A command line interpreter or CLI, is a program that lets end-users interact with the operating system by entering commands at a terminal command prompt. In Unix the CLI is the terminal session where the end-user is permitted to enter a command. Tab completion is a utility built into the CLI, that allows the end-user to only type a few characters of the command that, followed by pressing the “tab” key, will automatically complete the rest of the command. In a situation where the end-user hits the “tab” key and there are multiple choices to pick from, the user can type a few more characters and press “tab” again to filter the correct command. The tab completion utility is basically a shortcut key that speeds up efficiency when the user is typing a command that is very long.

lab46:~$ ls
Desktop   Downloads   Music   Public   Videos
Documents   examples.desktop   Pictures   Templates
lab46:~/cat examples.desktop

[Desktop Entry]
Version=1.0
Type=Link
Name=Examples
Comment=Example content for Ubuntu
URL=file:///usr/share/example-content/
Icon=folder
X-Ubuntu-Gettext-Domain=example-content

lab46:~/cat e "press Tab"        ---> Pressing the Tab key results in the next line
lab46:~/ cat examples.desktop    ---> cat e, then tab, = cat examples.desktop

Keyword 9

Viewing:

Viewing in Unix, refers to the ability to view the contents of a text file. In Unix the command for viewing a file is “cat”. Typing “cat” followed by the file you want to display to output, will result in the file displaying it's contents in your terminal. It is important to mention that you cannot use this command for a directory file, because a directory file is not a text file. It is only a container for other directories and files. The command “cat” is a program that when executed will send the contents of a text file to your display. Below I have demonstrated the cat program in Unix.

lab46:~$ ls
Desktop   Music   Videos   Templates  Documents
examples.desktop   Bin   Temp   
lab46:~$ cat examples.desktop   ---> we want to display this text file

[Desktop Entry]
Version=1.0
Type=Link
Name=Examples
Comment=Example content for Ubuntu         ---> Using the "cat" program we displayed the file examples.desktop in the terminal
URL=file:///usr/share/example-content/
Icon=folder
X-Ubuntu-Gettext-Domain=example-content

lab46:~$

Keyword 10

The Unix Shell:

The Unix shell by definition is a command line interpreter that creates a end-user interface for the Unix Operating System. So the Unix shell is a command prompt based program that hides the detail of the operating system by using a terminal session to execute commands. There are many different types of Unix shell's that are in use today. The most common Unix shell used is the login shell. This is the shell that is created when an end-user logs in to a terminal session. When you see a command prompt in Unix, it means the shell is ready for a command to be entered. Once you enter the command, the shell interprets the command and is then responsible for it's execution. Some other common Unix shells include sh, fish, C shell, and bash. The terminal session below is a login shell that is executing the “ls” command. The end-user has typed the command at the prompt, and now it is the shells responsibility to interpret and execute the command. Once the command has been executed, if sucessful, will bring up another command prompt or the command will be followed with an error to indicate failure.

lab46:~$ ls                                       ---> Command executed in the Unix shell
Documents   Music   Videos   Templates   Public
Desktop   Downloads   examples.desktop   Pictures   
lab46:~/                                          ---> Command was successful

lab46:~/ ld                                       ---> Command was mis-typed
ld: no input files                                ---> Command failure notification
lab46-~/
lab46:~/ 

Keyword 11

Copying:

Copying files in Unix/Linux is accomplished by applying the “cp” command at your terminal prompt. This command allows you to copy files and place them in another directory file. You can also use the “cp” command to copy one directory to another, by attaching a “-r” to the “cp” command. The proper syntax to copy a file would be; cp (file) (destination). The proper syntax for copying a directory to another directory would be; cp -r (directory) (dest. directory). There are many command attachments you can add to make the copy program achieve various tasks. The “cp” and “cp -r” commands however, are the most commonly used. In the terminal shell below I have demonstrated how to copy both regular files and directory files to a different location. (Note: files in parentheses are indicated as directory files.)

lab46:~$ ls
bill  bin  bob  (other)  test  test2  (tests)  tim  tmp  (unixplay2)
lab46:~/ cp test other    ---> copying the file test to the destination directory, other
lab46:~/ cd other
lab46:~/other$ ls
test                     ---> test is now copied to the directory, other
lab46:~/other$ cd
lab46:~$ cp test tests   ---> copying the file test to the directory, tests
lab46:~$ cp test2 tests  ---> copying the file test2 to the directory, tests
lab46:~$ cd tests
lab46:~/tests$ ls
test  test2              ---> both files, test and test2, have been copied to the tests directory
lab46:~/tests$ cd
lab46:~$ cp -r tests unixplay2  ---> using cp -r to copy the directory tests, to the directory unixplay2
lab46:~$ cd unixplay2
lab46:~/unixplay2$ ls
(tests)                        ---> directory tests has been copied to the directory, unixplay2
lab46:~/unixplay2$ cd
lab46:~$

Keyword 12

Creating:

Creating text files in Unix/Linux can be achieved a few different ways. Files can be created when using a text processing program like Vi or Nano or they can be created using the command “touch” at your terminal shell command prompt. The proper syntax for creating a file using the “touch” program would be; lab46:~$ touch (filename). Once the command has properly been run, the new file will be created within the current working directory. Creating a directory file requires a different command. The “mkdir” or make directory command is required when making new directories. The proper syntax for the “mkdir” command in Unix/Linux is; lab46:~$ mkdir (directory name). This will result in a new directory being created in the current working directory. In the terminal shell below I have created both a regular file and a directory file, using the “touch” and “mkdir” commands. (Note: Directory files are encapsulated within parentheses)

lab46:~$ ls
(Documents)  (bin)  (music)  examples.desktop  (tmp)  program.sh  (videos)
lab46:~$ touch file1                            ---> Created new file1
lab46:~$ touch file2                            ---> Created new file2
lab46:~$ ls
(Documents)  (bin)  (videos)   program.sh            
(music)  examples.desktop  (tmp)  file1  file2  ---> New files have been created
lab46:~$ mkdir test1                            ---> Created new directory, test1
lab46:~$ mkdir test2                            ---> Created new directory, test
lab46:~$ ls
(Documents)  (bin)  (tmp)  (music)  (videos) examples.desktop 
program.sh  file1  file2  (test1)  (test2)                    ---> Two new directory files created
lab46:~$

unix Objective

Objective

Familiarity with the structure of UNIX systems

The structure of Unix Systems is a hierarchical filesystem that uses a command line interpreter to execute processes and programs.

Method

The method I will use for measuring successful academic/intellectual achievement of this objective will be using a terminal session to create text files within directories and then work from the last directory in, deleting all text files and directory files until I have deleted all files created. This method will demonstrate the hierarchical system Unix is. (Note: directory files will be encapsulated within parentheses.)

Measurement

lab46:~$ls
(unix) (Downloads)
lab46:~$ cd unix
lab46:~/unix$ 
lab46:~/unix$ touch file1
lab46:~/unix$ mkdir test1
lab46:~/unix$ cd test1
lab46:~/unix/test1$ touch file2
lab46:~/unix/test1$ rm file2
lab46:~/unix/test1$ ls -l
total 0
lab46:~/unix/test1$ cd /home/user/unix
lab46:~/unix$ ls
(test1)
lab46:~/unix$rmdir test1
lab46:~/unix$ ls
file 1
lab46:~/unix$ rm file1
lab46:~/unix$ ls -l
total 0
lab46:~/unix$ cd 
lab46:~$ ls
(Downloads) (unix)
lab46:~$ rmdir unix
lab46:~$ ls
(Downloads)
lab46:~$

Analysis

This was really a great exercise for using CLI commands to create and delete regular files and directory files. I felt that I did pretty good throughout the measurement. I realized that I couldn't delete a directory file unless the files within the directory where deleted individually. I wonder however, if there may be an issue with the permissions on the files within directories preventing me from deleting the directory before deleting the file within. Next time I might alter the permissions on all created files to see if there might be a more efficient way of completing the objective.

Experiments

Experiment 1

Question

Can multiple test files be copied from one directory to another using the “cp” command?

Resources

http://www.computerhope.com/issues/ch000766.htm

cp manual page, incorporated within Unix/Linux

Hypothesis

Based on what I have read about copying files from the manual page and the web, you should be able to copy as many files as you want from one directory to another. I think the result of the experiment will be that all files I list after the “cp” command will be copied to the directory listed as the dest. directory. The command I will be typing at the command prompt will be as follows: cp (filename) (filename) (filename) (filename) (dest.directory). According to the resource data, there is no limit on the number of files that can be copied from one directory to another.

Experiment

I am going to test my hypothesis by opening a terminal session and attempting to copy four files from my home directory to a directory I have created, called tests. The files I will be attempting to copy are named: test, test2, tim, and tmp.

Data

Success! I started by creating four files using the “touch” command at the terminal prompt. The files I created where named test, test2, tim, tmp. I then created a new directory file within my home directory called, tests. Next I typed the following command at the prompt, lab46:~$ cp test test2 tim tmp tests, and pressed enter. I immediately received another command prompt indicating that the experiment had worked successfully. I changed directories so that the current working directory was tests, and typed the “ls” command. All four files where listed in both my home directory and now in the new directory called tests.

lab46:~$ touch test
lab46:~$ touch test2
lab46:~$ touch tim
lab46:~$ touch tmp
lab46:~$ mkdir tests
lab46:~$ ls
test  test2  tim  tmp  (tests)
lab46:~$ cp test test2 tim tmp tests
lab46:~$ ls
test  test2  tim  tmp  (tests)
lab46:~$ cd tests
lab46:~/tests$ ls
test  test2  tim  tmp
lab46:~$

Analysis

Based on the data collected:

My hypothesis was correct and I didn't run into any shortcomings.

Conclusions

In conclusion… I found that copying multiple files from one directory to another is not only possible, but not very challenging either.

Experiment 2

Question

Using the “cp -r” command can I copy multiple directory files from my home directory to another directory at the same time?

Resources

http://www.itd.umich.edu/itcsdocs/s4148/

cp manual page built into Unix/Linux

Hypothesis

Based on what I have read from the copy manual page in Linux and also the web page listed above I should be able to copy more than one directory at a time. It proved not to be a problem when copying regular text files, so I don't expect that multiple directory files will be an issue either

Experiment

I am going to test my hypothesis by using a terminal session and creating multiple directories using the mkdir command. I will then try and copy multiple directories to one directory within my home directory

Data

lab46:~$ ls
Documents  Downloads  Music  Videos
lab46:~$ mkdir copytoo other tests unixplay2
lab46:~$ ls
Documents  Downloads  Music  Videos  copytoo
other  tests  unixplay2
lab46:~$ cp -r other tests unixplay2 copytoo
lab46:~$ cd copytoo
lab46:~/copytoo$ ls
other  tests  unixplay2
lab46:~/copytoo$ cd
lab46:~$

Analysis

Success! My hypothesis with copying multiple directories worked like a charm.

Conclusions

In conclusion I have discovered that using the cp -r command can copy multiple directories and well as regular files at one time. I also discovered that when using the mkdir command to create new directories, you can also create multiple directories within your current working directory at the same time.

Experiment 3

Question

Can I create an executable program what will launch me into my Alpine e-mail client without typing “alpine” at the command prompt?

Resources

Hypothesis

Based on what I have read about shell scripting I should be able to write a shell script that will accomplish my proposed question above. I should be able to use shell script command code to create a password to access my Alpine email client. Using “if” and “fi” statements to provide or deny access to Alpine email inbox. If access is accepted you will be sent to Alpine immediately, if you mistype your password, you will be prompted to enter it again. Failing to enter the password correctly a second time will result in a “Goodbye” message and the program will terminate putting you back to the home directory command prompt.

Experiment

Using Vi Text Editor, create a shell script titled, “e”, that resides in my home directory and when executed, will take me directly to my Alpine inbox.

Data

For this example the correct password = tom

lab46:~$ ./e
Please enter your password: c
Access Denied

Please enter your password: cab
Access Denied.... GOODBYE
lab46:~$
lab46:~$ ./e
Please enter your password: t
Access Denied

Please enter your password: tom
Access Granted
Welcome "userid"... routing you to Alpine email client:

(Alpine login password:  ---> Opens Alpine home page)

lab46:~$

Analysis

It took some time to understand the “if” and “fi” but success was ultimately achieved. The program works perfectly, entering the correct password at the first prompt will launch you into Alpine. Entering in incorrect the first time will prompt you to enter again. If the second password entry is correct you are taken to the Alpine login, and if entered incorrectly you will see a statement telling you “Access is denied…GOODBYE”. Failure to enter the correct password after the second time will terminate the program and put you at the command prompt of your home directory.

Conclusions

There is definitely room for improvement here! When successfully routed to the Alpine e-mail client you are prompted to enter your alpine password as well. It would be nice to have the shell script insert that password for you, being that you already entered a password when prompted by the shell script. I named the file “e”, for e-mail, to shorten the time you would normally use to enter in the six characters of “Alpine”. When executing the program in your default home directory the command to launch the script is: ( ./e ), reducing the number of characters from six to three.

Part 3

Entries

November 15th, 2011

Today I learned how to compress and decompress a file in Linux/UNIX. Using the command line utilities gzip, and gunzip I successfuly compressed a file and decompressed it. This is significat to me because while working on my Opus I found myself to be strugling with the concept.

November 17th, 2011

Today I dove into the wonderful and exciting world of data mining! We performed a class project by taking different file formats and extracting specific strings of characters using command line utilities like grep and sed. This was very significant for me being that the data we were manipulating was real world data. I helped perform magical spells to extract data and now… I am amazing!

November 22nd, 2011

Today we learned about some networking tools in UNIX like netstat and ifconfig. This was very significant to me being that my new found passion in life is the world of networking. It has always been very easy for me to execute network commands in a dos shell, but it was really very interesting and rewarding to say that I now could navigate the command prompt networking utilities in Linux/UNIX.

November 29th, 2011

Today I spent a lot of time playing with regular expressions. This was significant to me because the entire concept of regular expressions was like a foreign language. After banging my head several times, bothering the professor, and pulling some hair out I was able to accomplish the task at hand! Yeah baby! I was very excited about the achievement!

unix Topics

Part 3:

Keywords:

  1. Compiler
  2. Regular Expressions
  3. Ownership
  4. Permissions
  5. Moving/Renaming
  6. VI Extended Command Mode
  7. C
  8. Compressing/Decompressing
  9. Shell Scripting
  10. Text Processing
  11. Object Code
  12. Linker

Keyword 1

Compiler:

A compiler is a computer program that translates programming language into machine language the computer can understand and execute. Most compiler programs will also create a executable file that will allow the end-user to execute or run the translated program. For this example I used the chmod program as a compiler for a password program called password.sh. I first created the shell script using the Vi text editor and then executed the chmod command using the code chmod 700 password.sh. This compiled the program and made it an executable file.

lab46:~$cd example
lab46:~/example$ ls
password.sh
lab46:~/example$ chmod 700 password.sh
lab46:~/example$ ./password.sh

Enter the magic Pass-phrase: bob
Access Granted
What's going on?
lab46:~$

Keyword 2

Regular Expression:

Regular expressions provide the ability for “matching strings of text” whether the text is characters, words, or specific patterns of text. Each assigned expression character will match characters specifically and uniquely. For example: the “^” symbol will match the beginning of a line, the “$” will match the end of the line, the “.” symbol will match any single character, and the “*” will match zero or more of the previous. Each regular expression symbol has a specific matching purpose. The command line below uses many utilities and regular expressions to extract specifically matched data to output.

lab46:~$ cat spring 2012-20111103.html | grep 'ddtitle' | sed 's/^\(.*\)  

 ---> Regular Expressions used: /  *  ^  \  .  \(   \) 

Keyword 3

Ownership:

Ownership is what tells the end-user who has administrative ownership of a specific file within a directory. You can view the ownership properties by using the “ls -l” command from your working directory. In the example below I have opened a directory named closet. Within that directory there are three regular text files. The third field, named ccaccia in the example, indicates who has administrative ownership or rights of the files.

lab46:~$ cd closet
lab46:~/closet$ ls -l
-rw------  1 ccaccia lab46  56 Sep 6 16:37 cake
-rw------  1 ccaccia lab46 752 Sep 6 16:11 df
-rw-r--r-- 1 ccaccia lab46  26 Sep 6 15:45 skelton 
lab46:~/closet

Keyword 4

Permissions:

Permissions in the UNIX filesystem determine who can read, write, or execute a file. When the command “ls -l” is typed and executed at a command prompt it will list the properties of the current working directory. The first field in the output of the command is the file type and permission block. There are a total of ten digits, one for the filetype and nine for the permission block. These nine digits are divided evenly and respectively between three categories called user, group, and other. The “user” category is the file permission for the directory owner, the “group” category is the file permission for the group, and the “other” category is the file permission for the world. Each three digit category can be assigned a file permission to either read ®, write (w), or execute (x). In the example below you will notice three files in a directory called closet. For the file named “skeleton”, you will notice that the file permission is, rw-r–r–. This defines the user is having permission to read and write. The group has permission to only read, and the other also only has permission to only read. The file named “cake” you will notice that the user has the only permission to read and write the file.

lab46:~$ cd closet
lab46:~/closet$ ls -l
-rw------  1 ccaccia lab46  56 Sep 6 16:37 cake
-rw------  1 ccaccia lab46 752 Sep 6 16:11 df
-rw-r--r-- 1 ccaccia lab46  26 Sep 6 15:45 skelton 
lab46:~/closet

Keyword 5

Moving/Renaming:

Moving and renaming files in Linux/UNIX is really a very simple file. As you can see in the example below, I have opened a directory named “closet” and executed the “ls” command. There are four text files and two directories located within this directory. The first text file is called “aples” and needs to be renamed to the correct spelling of “apples”. To perform this daunting task we will need to use the Linux/UNIX “mv” command. By typing: mv aples apples, at the command prompt you essentially rename the aples file to apples. If we wanted to move a file to another directory, we also need to use the “mv” command. In the example below I typed: mv mvme tacocat, at the command prompt and the file “mvme” was moved to the directory, “tacocat”. This is how you move or rename files in Linux/UNIX.

lab46:~$ cd closet
lab46:~/closet$ ls
aples  cake  help  mvme  skeleton  tacocat  trickery
lab46:~/closet$ mv aples apples                      ---> Renamed aples to apples
lab46:~/closet$ ls
apples  cake  help  mvme  skeleton  tacocat  trickery
lab46:~/closet$
lab46:~/closet$ mv mvme tacocat                      ---> Moved file: mvme to directory: tacocat
lab46:~/closet$ ls
apples  cake  help  skeleton  tacocat  trickery
lab46:~/closet$ cd tacocat
lab46:~/closet/tacocat$ ls
mvme  wand  wang                                     ---> File: mvme new location
lab46:~/closet/tacocat$

Keyword 6

VI Extended Command Mode:

The VI text editor, as covered earlier, is the best text editor ever! Extended command mode is achieved from regular command mode, and cannot be initiated from Insert mode. To enter extended command mode you hold down the shift key and press the semicolon/colon key. Once in extended command mode, the text editor can save your file and exit the program. Pressing the “w” key will save your file, and typing the “q” key will exit the text editor. These keys can be typed individually or at the same time to accomplish the command execution. Below I have duplicated a VI text editor box. At the bottom-left you will notice the colon followed, respectively by the “w” and “q” characters. This will save the current file and exit VI Text Editor.

~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

Keyword 7

C:

C is a lower level programming language developed for creating programs. C was designed and developed between 1969 and 1973 by the famous Dennis Ritchie. C has had the biggest impression on the development of programming languages. It is considered by many to be the root for many other programming languages. Below I have included the first program that I wrote in C called “hello”. When the program is called at the command prompt the source code instructs the program to output or return the phrase, “Hello, World!”. I have also executed the program to show the result.

lab46:~$ cd c
lab46:~/c$ ls
a.out  datatypes  datatypes.c  hello  hello.c  test
lab46:~/c$ cat hello.c
#include <stdio.h>

int main(_)
{
   print("Hello, World!\n");
   
   return(0);
}
lab46:~/c$
lab46:~/c$ 
lab46:~/c$ ./hello
Hello, World!
lab46:~/c$  

Keyword 8

Compressing/Decompressing:

Compressing and decompressing files basically take a file and make it smaller than the original size. This is done to help conserve on hard drive space as well as conserving bandwidth if being sent over a network. Decompressing a file is taking a smaller compressed file and extracting it back to its original size. In Linux/UNIX a file can be compressed using the “gzip” command. Typing this command followed by the name of the file being compressed will wrap the file up into a smaller compressed file. Using the “gunzip” command followed by the file name will decompress the file and return to the original file size. Below I have compressed and decompressed a file in a directory called closet.

lab46:~$ cd closet
lab46:~/closet$ ls
apples  cake  help  skeleton  tacocat  trickery 
lab46:~/closet$ gzip apples
apples.gz  cake  help  skeleton  tacocat  trickery
lab46:~/closet$ gunzip apples.gz
lab46:~/closet$ ls
apples  cake  help  skeleton  tacocat  trickery
lab46:~/closet$

Keyword 9

Shell Scripting:

Shell scripting is programming code written in a terminal or shell at a command line prompt. Shell scripts are programs that are created to make something happen at the command prompt. Below I have written a shell script using the VI text editor and bash. This program when executed at a command prompt will ask me for the magic pass-phrase. If the incorrect pass-phrase is typed then the shell script will notify me with a “Access Denied” statement. If I type the correct pass-phrase when prompted then I will receive a message stating that access was granted and then the script will return to standard output the word “hi”.

lab46:~$ cd bash
lab46:~/bash$ ls
script3.sh  script4.sh  script5.sh
lab46:~/bash$ cat script3.sh
#!/bin/bash
echo
echo
echo -n "Enter the magic pass-phrase: "
read passphrase
if [ "$passphrase" = "bob" ]; then
      echo "Access Granted"
else
      echo "Access Denied"
      exit 1
fi
echo "hi"
exit 0

lab46:~/bash$
lab46:~/bash$ 

Keyword 10

Text Processing:

Text processing is the act of creating a document or file using a word processing program. Linux/UNIX has two primary text processing programs, nano, and VI text editor. Processing text is achieved by opening a word processing program, typing text, and then saving the typed text as a file name. In the example I have created a sample VI text editor program and have typed some text.

lab46:~$ vi text
Hello, this is a test!  We are typing text into a word processing
program and demonstrating text processing!  Weee... this is fun!
~
~
~
~
~
~
~
~
~
~
~
~
~
--INSERT-- 
lab46:~$ 

Keyword 11

Object Code:

Object Code is produced when a compiler transforms a program into an executable file. Object code is code created by the compiler to serve the purpose of translating source code into machine language so that an executable file can be created. It is considered to be very close to machine language and is also the last step in creating an executable program.

Keyword 12

Linker:

A linker is a program involved with the program compiling process. A linker is a program that links source code with object code to form a executable program. Also programmers can split large programs into modules for more efficient development. Eventually these modules will have to be linked or connected back together to create a final executable program. The linker is the program that connects all the modules back together.

unix Objective

Objective

Exposure to command-line tools and utilities. Command line utilities and tools are commands entered at the command prompt that accomplish some task within the terminal session.

Method

The method I will use for measuring successful academic/intellectual achievement of this objective is compressing and decompressing a file, viewing the file, renaming the file, and finally moving the file into a different directory. Once I compress the file I will move it to another directory, decompress the file and then view it.

Measurement

lab46:~$ cd closet
lab46:~/closet$ ls
apples cake help skeleton tacocat trickery
lab46:~/closet$ cat cake
1)kit
2)sugar
3)va jay jay
Louis Armstrong is best friends with tacocat!
lab46:~/closet$ gzip cake
lab46:~/closet$ ls
apples cake.gz help skeleton tacocat trickery
lab46:~/closet$ mv cake.gz trickery
lab46:~/closet$ ls
apples help skeleton tacocat trickery
lab46:~/closet$ cd trickery
lab46:~/closet/trickery$ ls
cake.gz  hugebluepen  secret
lab46:~/closet/trickery$ gunzip cake.gz
lab46:~/closet/trickery$ ls
cake  hugebluepen  secret
lab46:~/closet/trickery$ cat cake
1)kit
2)sugar
3)va jay jay
Louis Armstrong is best friends with tacocat!
lab46:~/closet/trickery$

Analysis

Well things really seemed to go well with this objective. I don't see much room for improvement at this point, but I suppose there is always room to complicate this further. I really feel that I demonstrated UNIX utilities in a command-line.

Experiments

Experiment 1

Question

Can I rename more than one file at a time?

Resources

Hypothesis

Based on what I've read I do not think that I will be able to rename two files at the same time. After searching the manual page I don't see an argument I could add to accomplish this either.

Experiment

I am going to test my hypothesis in the lab46 command line prompt.

Data

lab46:~$ cd closet
lab46:~/closet$ ls
apples help skeleton  test1 test2 tacocat trickery
lab46:~/closet$ mv test1 test3 test2 test4
mv: target `test4' is not a directory
lab46:~/closet$

Analysis

Based on the data collected:

  • My hypothesis was correct!
  • There is really not anymore going on than I thought after researching.
  • I'm not really sure this was the best experiment to perform but it was a legitmate question, and even though the result wasn't what I hoped… it was a legitmate result.

Conclusions

My conclusion in this experiment was that other than answering a question it was a failure.

Experiment 2

Question

Can I change file permissions to read, write, and execute for the user, but only read privilege for the group and other category?

Resources

manual page on chmod

Hypothesis

Based on what I have read, there should be no problem executing the chmod command followed by the number 744 and the file name to change the file permissions.

Experiment

I am going to test my experiment in a cli command prompt terminal in lab46

Data

lab46:~$ cd closet
lab46:~/closet$ ls -l
-rw------- 1 ccaccia lab46  57 Nov 30 22:24 apples
-rw------- 1 ccaccia lab46 752 Sep  6 16:11 help
drwxr-xr-x 1 ccaccia lab46  39 Nov 30 21:09 tacocat
lab46:~/closet$ chmod 744 help
lab46:~/closet$ ls -l
-rw------- 1 ccaccia lab46  57 Nov 30 22:24 apples
-rwxr--r-- 1 ccaccia lab46 752 Sep  6 16:11 help
drwxr-xr-x 1 ccaccia lab46  39 Nov 30 21:09 tacocat
lab46:~/closet$

Analysis

Based on the data collected:

  • Yes… my hypothesis was correct and applicable
  • There was a little more going on than I expected. When I changed the permission for user to make the file read, write, and execute the file name color turned green. It seems that by allowing the user to have execution privilege's it has also compiled the program. Neat!

Conclusions

I can conclude that as long as you have ownership of a given file, it is very easy to change the permissions for the user, group, and other categories.

Experiment 3

Question

Can I install a Linux/UNIX opensource operating system on my personal laptop?

Resources

Hypothesis

Based on my research this should really be an exciting experiment. I should be able to install a Linux based operating system on my personal laptop without a hitch.

Experiment

I am going to download a full install .iso image to a usb drive and install the operating system

Data

It took a few attempts to install the operating system. I didn't have any problems with the .iso image or booting from the USB device, but I did have a few video driver glitches, possibly driver problems. After the third time formating the hard drive and installing Ubuntu, eveything finaly seemed to fire off. I did have a problem with the laptop wireless card driver but with some help from the proffessor, we were able to get that working by placeing a device driver code in the appropriate directory. I believe the wireless NIC driver installed by default with Ubuntu was not compatable with the laptop manufacturer.

Analysis

Based on the data collected:

  • Yes… my hypothesis was correct and applicable
  • As I stated within the data field, I did have a few video driver issues that finally worked themselves out and also the wireless NIC card would not work at first
  • There is room for improvement. I will have to play with the Linux OS to become more comfortable with it.

Conclusions

In conclusion I would feel comfortable stating that Linux/UNIX is really for a end-user with some computer knowledge. It seems that to be effective in troubleshooting simple problems, you really need to be comfortable in front of a command line terminal prompt.