Unix 2
MCIS 5013(030) – Unix Operating System Summer I, 2018
Page 1 of 4
Project 2- bash script (200 Marks)
No Name, ID and section name: 2 point deduction
No output is provided: 10 point deduction,
Don’t copy other students’ work
Expected Output
<< MCIS 5013 – Unix Operating System >> date: wed June 20, 2018
Directory info analysis Report
===========================================================================
A. Current Directory: /home/jongyk/UnixShells
B. New Directory Created at: /home/jongyk/UnixShells/9123
C. File information
0) Total Number of files: 22
1) Directory files: 0
2) Plain text files: 10
3) Files have Read only permission: 3
4) Files have Read and Write permissions: 4
5) Files have Execute only permissions: 2
6) File have length of zero: 0
7) Others: 0 files
D. Disk usage of this di: 50 Kb
E. Biggest 5 files in directory: Lab3.class , Lab4.java, Lab5.class
==========================================================================
Reported by: Jongyk
Objective: Write a bash shell script that copies all files from your UnixShells to
workngDir and analyze the new directory information such as number of files categorized
by file permission and disk usage.
MCIS 5013(030) – Unix Operating System Summer I, 2018
Page 2 of 4
Direction
1. Make sure you are current directory on bash by issuing command echo $0
2. Write a bash shell script name “DirAnalyze+your 4 digit ID”
#File name should be DirAnalyze+1864
3. The script need to be started with a line #! /bin/bash
4. Create a file named DirAnalyze_id.sh
. put your name, section name and simple description for the assignment
. print Title and date at the same line use echo command
. Print Title and date at the same line use echo command and cut command
<< MCIS 5013 Directory Analysis Report >> Date: wed June 20, 2018
Eg.
Wed June 20 17:48:15 CDT 2018 to Wed June 20, 2018
a. Display current directory
b. Create new directory and copy files
. Create a new directory with the mkdir command, you will get new directory name
by type in when you run DirAnalyze+dir.sh
. in order to get file names from the keyboard you can use read command
For example:
#! /bin/bash
read newdir #read a file name from the keyboard
echo $newDir #display name of directory
mkdir $newDir #Create new directory
cp *.* $newDir #copy *.* file to the new directory
cd $newDir #Change directory to new dir
MCIS 5013(030) – Unix Operating System Summer I, 2018
Page 3 of 4
c. Sample shell script to loop through all files
#!/bin/bash
for f in * #for all files in this directory
do
echo "Processing $f file..."
#take action on each file. $f store current file name
ls –al $f
done
d. Analyze file information (duplicate count for each file is allowed)
#!/bin/bash
dir=0 #variable for count directory
for f in * #for all file in this directory
do
echo "Processing $f file..."
#take action on each file. $f store current file name
if [ -d $f ] # count number of directory files
then
echo "Directory file"
let dir=dir+1
fi
if [ -r $f ] # a file has read permission
then
echo "Read permission"
let readCnt = readCnt+1
fi
…
ls –al $f
MCIS 5013(030) – Unix Operating System Summer I, 2018
Page 4 of 4
done
echo $dir
echo $readCnt
f. File inquiry Operator
-f file is a regular file (not a directory or device file)
-s file is not zero size
-d file is a directory
-r file has read permission (for the user running the test)
-w file has write permission (for the user running the test)
-x file has execute permission (for the user running the test)
g. Find the top five biggest files
Using array structure or any other method you use in bash
h. Disk usage
Use du command
5. Submission (Three files)
Upload
a. Your shell script DirAnalyze+Your four digit id ( eg. DirAnalyze+1864)
b. DirAnalyze+yourID.doc (Captured result screen)
c. Your script should be runnable on the bash
d. Upload your two files on the Black board
e. Late submission will not be accepted