Last Assignment Example

dirName

[code language=”shell”] #!/bin/bash

if [ -z $1 ]; then
dir="/home/mhesser01"
else
dir=$1
fi

function listdir() {
for i in `find $dir -type d`
do
if [ -d $i ]; then
echo $i
fi
done
}

listdir
[/code]

Find Stuff

[code language=”shell”] #!/bin/bash

function setDir() {
if [ -z $1 ]; then
dir=/home/mhesser01
else
dir=$1
fi
}

function today() {
for i in `find $dir -type f -mtime 1`
do
echo $i
done
}

function readable() {
if [ -e errors ]; then
`rm errors`
fi
for i in `find / -size 1 -readable 2>errors`
do
if [ -r $i ]; then
echo $i
fi
done
chmod 644 errors
}

function inode() {
for i in `find $dir -type f`
do
for j in `ls -i $i`
do
echo -e "$j\t\c"
done
echo
done
}

function errors() {
if [ -e errors1 ]; then
`rm errors1`
fi
for i in `find / -type f -writable 2>errors1`
do
if [ -w $i ]; then
echo $i
fi
done
chmod 644 errors1
}

setDir $1

echo -e "1. List all modified files in the past 24 hours. \n2. List all files you have read access to that are larger than 1MB. \n3. List iNode numbers of all the files in the provided path. \n4. Write all Files you have write access, to the errors1 file."
echo -e "What would you like to do?: \c"

read choice
case $choice in
1) today $dir ;;
2) readable $dir ;;
3) inode $dir ;;
4) errors $dir ;;
*) echo -e "That is not a valid selection."
esac
[/code] [code language=”shell”] [/code]