Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q-Write generalized bash-shell scripts that are able to work correctly on any Unix/Linux computer, with any user account, and starting from any working directory without

Q-Write generalized bash-shell scripts 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:

Use environment variables, string patterns, and wild-card characters to generalize the script, make sure possible errors are handled correctly.

image text in transcribed

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 filel file2 file3 ...etc., the script shall not actually delete these files, but instead it shall move them to a /home/user- name/trash directory. Also, the script shall do the following: 1. When it starts, it shall check for the existence of directory /home/user-name/trash, if it does not exist, the script must create it, along with a hidden recovery record file. 2. If the script is called with a -c switch, then it shall check the trash directory for all files older than 30 days and delete them, updating the recovery record file. 3. If the script is called with a -r switch followed by a list of files (e.g. srm -r filel file2 file3 ..etc.), or a wildcard file pattern (e.g. srm -r 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 and updating the recovery record file. 4. If the script is called with a -h switch followed by a list of files (e.g. file3 ...etc), or a wildcard file pattern (e.g. srm -h file*) then it shall do the same as the -r switch, but all matching files shall be recovered to the current directory. srm -h file1 file2 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 filel file2 file3 ...etc., the script shall not actually delete these files, but instead it shall move them to a /home/user- name/trash directory. Also, the script shall do the following: 1. When it starts, it shall check for the existence of directory /home/user-name/trash, if it does not exist, the script must create it, along with a hidden recovery record file. 2. If the script is called with a -c switch, then it shall check the trash directory for all files older than 30 days and delete them, updating the recovery record file. 3. If the script is called with a -r switch followed by a list of files (e.g. srm -r filel file2 file3 ..etc.), or a wildcard file pattern (e.g. srm -r 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 and updating the recovery record file. 4. If the script is called with a -h switch followed by a list of files (e.g. file3 ...etc), or a wildcard file pattern (e.g. srm -h file*) then it shall do the same as the -r switch, but all matching files shall be recovered to the current directory. srm -h file1 file2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions