curl -O -s https://www.labs.cs.uregina.ca/330/Shell/Lab11.zip unzip Lab11.zip
You will be creating a shell script that can explore a directory structure and remove compiled C/C++ programs. Your code will be broken down into tasks:
The script begins by verifying the command-line argument (in one if statement). It ensures that:
If either condition fails, the script stops immediately using exit.
A loop is used to examine every item inside the given directory. Each entry is checked to determine its type:
Instead of using a separate function, the script invokes itself when it encounters a subdirectory. This is done by calling the script using its own filename and passing the new directory as an argument.
It uses the "file" command that inspects file content rather than relying on file extensions or executable permissions.
If the file description contains indicators of a binary executable format (such as ELF on Linux systems), the file is considered a compiled C/C++ program. Hint: use "grep".
Once a file is confirmed to be a compiled executable, it is deleted. You might want to use a flag with the rm to confirm that you want to remove the file. Prior to testing the rm, you might want to use echo to confirm what files will be removed.
In short, the script:
temp05@os1:~/cs330$ ./cleanup.sh Error: Argument is not provided or is not a directory ntemp05@os1:~/cs330$ ./cleanup.sh cleanup.sh Error: Argument is not provided or cleanup.sh is not a directory temp05@os1:~/cs330$ ./cleanup.sh Lab6 rm: remove regular file 'Lab6/bad'? y rm: remove regular file 'Lab6/good'? y temp05@os1:~/cs330$ ./cleanup.sh Lab5 Recursively entering Lab5/Samples rm: remove regular file 'Lab5/Samples/p11'? n rm: remove regular file 'Lab5/Samples/p11b'? n rm: remove regular file 'Lab5/Samples/p11c'? n rm: remove regular file 'Lab5/demo'? n rm: remove regular file 'Lab5/functions.o'? n rm: remove regular file 'Lab5/main.o'? n temp05@os1:~/cs330$
You will be asked to explain at least three lines of code. You will be under more scrunity if you have done something out of the lab presentation.
Submit 2 files to URCourses: