OPS435 Lab 1 - Bash
FOCUS: Your first BASH program.
PART A - Perform the following steps
- Login to your linux system and open a terminal window.
- Write down the output of the following command:
echo $PATH
- Edit your .bashrc file (located in your HOME directory) and set up your PATH by adding the following lines at the end of the file:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:. export PATH
- Close your terminal window and open a new one.
- Again write down the output of the following command:
echo $PATH
- Make a directory named bin in your HOME and change into it.
- Create a shell script with the following contents:
#!/bin/bash # BASH script to free up disk space by deleting no longer needed files echo "Disk space in use by this account: $(du -sh ~/ | cut -f1)" echo echo This program will free up disk space used by the KDE help system and Firefox echo cache, terminate Firefox, delete your Beagle index, and release any Firefox echo -e "lock files. OK to proceed? (Y/N) \c" read LINE if echo $LINE | grep -qi Y then rm ~/.kde/share/apps/khelpcenter/index/* >/dev/null 2>&1 rm ~/.mozilla/firefox/*/Cache/* >/dev/null 2>&1 killall firefox firefox-bin >/dev/null 2>&1 find ~/.mozilla -name '*lock*' -exec rm {} \; >/dev/null 2>&1 rm -rf ~/.beagle >/dev/null 2>&1 echo "Cleanup complete -- disk space used by your account: $(du -sh ~/ | cut -f1)" else echo "Cleanup aborted" fi
- You should save this script inside your bin directory.
- Name it cleanup and give yourself execute permissions.
- Change back into your HOME directory.
- Run the script by typing in cleanup at the prompt and make a note of the output.
- Now ssh to a matrix server using the command:
ssh -CX matrix.senecac.on.ca
- Again run the cleanup script and make a note of its output.
- Examine the script and once you understand how it works, proceed to PART B.
PART B - Answer the following questions
and and email them to your teacher in ASCII text format. Be sure to follow your teacher's guidelines for submitting labs. What is your full name and nine digit Seneca student ID? What were the permissions you set on the script? Show the output of the "ls -l cleanup" command. What was the PATH you set? Show the results of steps 2 and 5 from PART A. Why is it important to place your PWD (shown as a dot) at the end of your path? What version of BASH did you use to run the script? Hint: the bash shell is like any other command (like ls, mv, cat, etc...). Use the man command (i.e. the "man pages") to get help regarding the bash shell and search how to determine the version. Explain the purpose of creating a bin directory inside your HOME. Besides HOME, PATH and USER name two other commonly used global variables and explain their purpose. What is your Matrix quota? And how much have you used?