Question: Objectives: The objective of this assignment is to apply what you learned in the previous labs about Linux commands and shell programming by writing some

Objectives:
The objective of this assignment is to apply what you learned in the previous labs about Linux commands and shell programming by writing some bash shell scripts.
What to Do:
Write generalized bash-shell script that are able to work correctly on any Unix/Linux computer, with any user account, and starting from any working directory without any modification, to carry out each of the following tasks:
Hint: Use environment variables, string patterns, and wild-card characters to generalize your script.
Question: Safe Delete (srm):
When you use the standard "rm" command in Linux, it will delete the specified files, with no chance for recovering them back later. Write a script (called srm) that will safely delete the file(s) passed to it as command-line argument(s). For example, typing: "srm file1 file2 file3...etc.", the script shall not actually delete these files, but instead it shall move them to a trash directory and record their original paths and names in a hidden recovery record file called trash/.srm.
At its start, it shall always check for the existence of the directory: /home/user-name/trash, and the file: /home/username/trash/.srm, if they do not exist, the script must create them. At any change to the contents of the trash, the script shall update the recovery record file accordingly. The script shall also accept switches that modify its behavior to do the following:
If the script is called with a -c switch, first it shall check the trash directory for all files older than 60 days and permanently delete them, and then perform its normal task.
If the script is called with only -r switch, then it shall list all the recoverable files in the trash.
If the script is called with a -b switch followed by a list of files (e.g. srm -b file1 file2 file 3...etc.), or a wildcard file pattern (e.g. srm -b file*) then it shall not remove the files, but rather it shall recover the matching files in the trash, by moving them back to the same directories they were deleted from.
If the script is called with a -w switch followed by a list of files (e.g. srm -w file1 file2 file3...etc), or a wildcard file pattern (e.g. srm -w file*) then it shall do the same as the -b switch, but all matching files shall be moved to the current work directory.
If the -c switch appears in the command with any of the other switches, the script shall not delete anything from the trash; i.e. any other switch shall override the -c switch.
If conflicting switches appear in the command, then only the leftmost one shall execute.
Objectives: The objective of this assignment is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!