Linux Bash cleanUp.sh Script Purpose: This is about keeping a directory free of
ID: 3738133 • Letter: L
Question
Linux Bash cleanUp.sh Script Purpose: This is about keeping a directory free of "junk" files. To be specific, we want to remove files that are backups and auto-saved versions Procedure: 1. Create a file "cleanUp.sh". Use this file to write your script. 2a. Develop a bash function called cleanUp() that deletes all backup and auto- save files from the given directory 2b. Assume that names of back up files end in either: (1) ~ or (2) .bak and (3) auto-save files have names beginning with a #. 3. Develop a test harness that tests the cleanUp() procedure. The test() procedure should: (1) create a new directory named TEST in the current directory (2) create a few files (say a 4 each of names chosen by you) that fit the three categories of junk files in TEST (3) Is -I the TEST directory (4) invoke cleanUp TEST, and again (5) Is -I the TEST directory. For your answer: 1. Copy-paste the result of Is - in the TEST directory prior to running your script. 2. Copy-paste the command line you used to run your script. 3. Copy-paste the result of Is-l in the TEST directory after running your script. 4. Copy and paste your cleanUp.sh file to the answer field for this question. The construction must be your ownExplanation / Answer
# Code for cleanup.sh script
# removing junk files
# make it executable and then run it
#!/bin/bash
cleanUp(){
if(rm $1/*~ $1/*.bak $1/#*); then # if successfully remved return 0
return 0
else # else return -1
return -1
fi
}
test(){
mkdir test1; # creating a test directory
touch test1/file1~; # creating junk files
touch test1/file2~;
touch test1/file3.bak;
touch test1/file4.bak
cleanUp test1; # calling cleanUp function
return 0;
}
test
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.