CGS3767 Assignment 2

Due Friday, March 8
(late 8am on 3/9)

Questions from the text book

Create a text file and answer the following list of questions from chapter 6 of the text book. In addition to writing the answer, include the page in the book where the answer can be found. You must inlcude the answer and the page number of the answer for each question.

2, 5, 6, 8, 9, 10, 11, 13, 17, 18

Working on ocelot

This part of the homework must be done on ocelot. Use the putty program to connect to ocelot.

Putty is a program that can be used to connect to a command prompt window on a remote computer. ocelot.aul.fiu.edu is a computer on the SCIS network that can be access from the internet.

If you want to work from a home computer or laptop then you can download putty for free. Download Putty

Create a folder named cgs3767 in your home directory. Create a sub-directory named hw2. Place all of the files for this part of the homework in the hw2 directory.

Creating Scripts on ocelot

Use the nano editor to create a text file. The nano editor has a list of commands at the bottom of the screen: the ^ character means the CTRL key (^X means CTRL-X). To create a file named myScript, use the command
nano myScript

You will create two scripts. One will create the directories and files, the second will generate some listings.

To make these scripts executable, use the chmod command. For example, if your scripts are named make_script and list_script, then use the following command to make them executable:

chmod u+x make_script list_script

Once you have changed the file to executable, you can execute it at the command line, but you must inlcude a reference to the current directory. For example, if the script is named list_script, execute it with

./list_script

The first line of the script file should be
#!/bin/bash

Removing the starting folder

The first command in the script file should remove the starting folder (and all files and directories in it) for the files you are creating. The script should test if the folder exists. If it does not exist, then do not remove it. On each subsequent run, the old version of the homework folder will be removed, so you can recreate it from the script.

The name of the starting folder will be FIU.

Creating Directories

The next set of commands in the script file should create directories.

Create a directory named FIU. It will have four sub-directories: Arts, Business, Education, Engineering. Do not include spaces in the name of directories.

Under the Arts directory, create three sub-directories: Biology, Math, Psychology.

Under the Business directory, create two sub-directories: Accounting, Management.

Under the Education directory, create two sub-directories: Elementary, Special.

Under the Engineering directory, create three sub-directories: CM, EE, SCIS.

Creating files

The next set of commands in the script file will create some files.

In the SCIS directory, create the following files.

file01.txt, file02.htm, file03.doc, file11.txt, file12.htm, file13.doc, file21.txt, file22.htm, file23.doc, sound01.au, sound02.wav, sound03.mid, sound11.au, sound12.wav, sound13.mid, sound21.au, sound22.wav, sound23.mid, image01.bm, image02.jpg, image03.png, image11.bm, image12.jpg, image13.png, image21.bm, image22.jpg, image23.png

Each file should have a different size.

An easy way to create a small file is by using the echo command and output redirection. After each file is created, add more characters to $text

echo $text > file01.txt

Copying files

The next set of commands in the script file should copy some files to other directories.

Copy files from the SCIS directory to the indicated directory. For each of the following, use a single copy command to copy the indicated files. Use relative references. Use the shortest relative reference that will work.

Save and close the file. If the name of your file is create_script, then run it by typing this command at the prompt: ./create_script

Sorted lisings

Create a second script that will generate the following listings.

In addition to the book's techinque for sorting, there are also options in the ls command for sorting. Look for help information on the ls command by typing ls --help. Type q to exit the help page.

  1. List all the directories with the files that are in them. Use only one command to do this. Do not use tree. Use the echo command to display an appropriate comment before the list.
  2. Generate a long lising of the files in SCIS sorted by size. Use the echo command to display an appropriate comment before the list.
  3. Generate a long lising of the files in SCIS sorted by extension. Use the echo command to display an appropriate comment before the list.
  4. Generate a long lising of the files in SCIS sorted by modification date. Use the echo command to display an appropriate comment before the list.

Save and close the script file.

When you run this script, redirect its output to a file. For example, if the script is named list_script and the output file is to be list_script.out, then use the command

./list_script > list_script.out

Working with directories on Windows

You will create two scripts. One will create the directories and files, the second will generate some listings.

The extension for each of these script files should be .bat

The first line in each script file should be
@echo off

To execute a script, just type its name at the command line. For example, if the script is named myScript.bat, execute it with

myScript.bat

Removing the starting folder

The first command in the script file should remove the starting folder (and all files and directories in it) for the files you are creating. The script should test if the folder exists. If it does not exist, then do not remove it. On each subsequent run, the old version of the homework folder will be removed, so you can recreate it from the script.

The name of the starting folder will be FIU.

Creating Directories

The next commands in the script file will create some directories.

Create a directory named FIU. It will have three sub-directories: Arts, Business, Education, Engineering. Do not include spaces in the name of directories.

Under the Arts directory, create three sub-directories: Biology, Math, Psychology.

Under the Business directory, create two sub-directories: Accounting, Management.

Under the Education directory, create two sub-directories: Elementary, Special.

Under the Engineering directory, create three sub-directories: CM, EE, SCIS.

Creating files

The next commands in the script file will create some files.

In the SCIS directory, create the following files.

file01.txt, file02.htm, file03.doc, file11.txt, file12.htm, file13.doc, file21.txt, file22.htm, file23.doc, sound01.au, sound02.wav, sound03.mid, sound11.au, sound12.wav, sound13.mid, sound21.au, sound22.wav, sound23.mid, image01.bm, image02.jpg, image03.png, image11.bm, image12.jpg, image13.png, image21.bm, image22.jpg, image23.png

Each file should have a different size.

An easy way to create a small file is by using the echo command and output redirection. After each file is created, add more characters to $text

echo %text% > file01.txt

Copying files

The next commands in the script file will copy some files.

Copy files from the SCIS directory to the indicated directory, as follows:

Save and close the script file. If the name of the file is create_script.bat, then execute it from a command prompt with:

create_script.bat

Sorted lisings

Create a second script that will generate the following listings.

  1. List all the directories with the files that are in them. Use only one command to do this. Use the echo command to display an appropriate comment before the list.
  2. Generate a lising of the files in SCIS sorted by size. Use the echo command to display an appropriate comment before the list.
  3. Generate a lising of the files in SCIS sorted by extension. Use the echo command to display an appropriate comment before the list.
  4. Generate a lising of the files in SCIS sorted by modification date. Use the echo command to display an appropriate comment before the list.

When you run this script, redirect its output to a file. For example, if the script is named list_script.bat and the output file is to be list_script_bat.out, then use the command

list_script.bat > list_script_bat.out

Hand In Assignment

You should have several text files: textbook answers, Linux creation script, Linux listing script, Linux listing output, Windows creation script, Windows listing script, Windows listing output. Create a zip file containing these files and upload the zip file to me, as binary: Submitting Homework Online. When you are asked for a username and password, use your webmail username with the password that I sent to you. Upload the file as binary. If you upload as text, nothing will be uploaded. Check that the size of the uploaded file is correct.

You then have a choice for submitting the file.

If you are in the lab, then the ocelot files can be accessed from the U: drive.