Write a shell script called lss

Assignment Help Operating System
Reference no: EM131478606

1) Write a shell script called "lss" that will list all the files in the current directory in decreasing order of the number of bytes in the file.  It does not need to take any arguments. Ex:

$ lss          -rwxrwxr--    1 wayne   faculty      385 Nov 29  1996 lss     -rwxrwxr--    1 wayne   faculty       42 Mar  9  1990 nf

This was a previous assignment.

The "lss" command written in the previous assignment didn't take any arguments.  Re-write it so that it will work if given command line arguments. More specifically:    

(a) If given no arguments, "lss" should give a "ls -l" listing sorted by decreasing byte count.   

(b) It should accept as many of "ls"'s options as it can, and pass those options on to "ls".  But be careful; options like "-s", "-i", or "-g" may really foul up your sorting if you try to accept them.  It is OK to decide not to accept options like that, if you think it would be too hard, messy, or inefficient to support them. Any option not accepted should cause "lss" to print an error message and halt. (Document your decisions and reasons behind them.)  Note that if there are options, but no filenames, then it should work as in (a), but additionally with the options passed to "ls".

c) Any other arguments should be interpreted as filenames, and *only* those filenames listed should be processed. Directories should NOT be descended unless the files inside those directories are explicitly listed.    

(d) It should be as "bulletproof" as possible. It should either print the list in the required order, or fail gracefully.  THIS IS IMPORTANT. Here are some examples, executed in ~wayne/pub/ics54/a3.lss.dir    

$ ls -l    

total 2     drwxr-xr-x   2 wayne         512 Sep 25 23:58 dir

-rw-r--r--   1 wayne           3 Sep 25 23:59 file    

lrwxrwxrwx   1 wayne           4 Sep 25 23:58 symlink -> file    

$ lss

drwxr-xr-x   2 wayne         512 Sep 25 23:58 dir

2) Some people complain that Unix doesn't have an "un-delete" program.  Write a suite of shell scripts called "srm", "unrm", "lsrm", "durm", and "trash".  "srm" is a "safe" version of "rm" --- rather than actually removing files, it moves them to a safe place; "unrm" un-removes a file if it hasn't been trashed; and "trash" actually removes all files that are currently safe-rm'd, recovering the disk space. "lsrm" takes no arguments and performs "ls -l" on all files that are currently in the trash, and "durm" runs "du" on the trashcan to let you know how much disk space would be recovered by running "trash".  If "srm" is invoked with a directory, then the entire directory heirarchy should be safe-rm'd.  (But it's not necessary to be able to "unrm" individual files in asrm'd directory; being able to unrm the entire heirarchy, as a whole, is good enough.  In other words, you only need to be able to "unrm" names that were explicitly srm'd.)  Furthermore, if "srm" is called on a path, it is not necessary to remember the entire path; in that case, "unrm" should only work with the current directory.  If "srm" is called with any options, you may simply exec the regular /bin/rm.  "trash", "lsrm", and "durm" take no arguments.  Both "srm" and "unrm" may be called with many arguments, eg "srm *".  (But of course "unrm" won't usually be called with "*" --- why?)         

You should try to make them reasonably fast; if an "srm" takes too long, and you are the impatient type (as most programmers are), then you are unlikely to use it regularly.  Thus design is important.  Two obvious possible designs are: (1) have a single, global, safe-rm directory where all srm'd files go; (2) leave srm'd files in the directory in which they lived, but "hide" them somehow.  The design is up to you.  Your mark will depend good design and implementation decisions.  (It is possible to do a good job using either of the above suggested designs, or you can even think of an entirely new one if you want).  You should clearly document each design decision and reasons behind it, and what advantages and disadvantages it has compared to others.         

Some other things to think about: what do you do if "srm" is called on a filename that is already srm'd?  Does the old srm'd file get trashed?  (For this assignment, that would be OK, but a production version, if you were going to release it to the general Unix community, would probably need versions of srm'd files.)  Comment on any important design decisions (like this one) that you make.  Make sure you think carefully; there are easy ways to do this question, and hard ways. 

Hints for #2: define an environment valiable (at login time, in your .login or .profile) called TRASH which tells the scripts where to find the trashcan(s);think about how this variable would need to be changed if somebody else ran them; the scripts should fail gracefully if TRASH is not defined; think about how they would work (or fail) if the trashcan resides on a different partition than the files being srm'd (especially if the file being srm'd is very big).

Reference no: EM131478606

Questions Cloud

Coupon rate be on the company bonds : Ghost Rider Corporation has bonds on the market with 12 years to maturity, a YTM of 5.8 percent, and a current price of $956.
How can a subjective approach assist the educator : write a research and reflection paper. How can a subjective approach assist the educator/caregiver in planning a comprehensive curriculum?
Research appropriate insurance plans : Research, identify, and describe appropriate insurance plans for a small business. This involves interviewing an insurance broker and/or searching the library.
Discuss the nature of stock as an investment : Discuss the nature of stock as an investment. Do most stockholders play large roles in the management of the firms in which they invest? Why or why not?
Write a shell script called lss : Write a shell script called "lss" that will list all the files in the current directory in decreasing order of the number of bytes in the file
Discuss the role of finance in the healthcare industry : Discuss the role of finance in the healthcare industry. Consider your current or future position within the healthcare industry.
What is the yield to maturity of the bond : May Industries has a bond outstanding that sells for $830. The bond has a coupon rate of 7.00 percent and 10 years until maturity.
Create a strong and unified thesis statement : Create a strong and unified thesis statement related to conformity, deviance, and social control that you can then support and substantiate.
What is anderson definition of nationalism : What is Anderson definition of nationalism? can we apply his definition of nationalism to non -westerm world

Reviews

len1478606

4/29/2017 5:49:11 AM

Notes: Questions 1 and 2 are worth equal value. You scripts should be well commented within, and you must also provide external documentation similar to a Unix "man" page for each command. (Question number 2 can have a single man page for all commands.) All scripts and documentation must be submitted electronically using the "submit" command described in assignment 2. Your late penalty will be calculated on the submission date/time.

Write a Review

Operating System Questions & Answers

  Implementation of algorithms for process management

The Shortest Job Next (SJN) algorithm queues processes in a way that the ones that use the shortest CPU cycle will be selected for running rst.

  Develop a user mode command interpreter

Develop a user mode command interpreter which support list-short.

  Memory allocation in operating system

Analysis and implementation of algorithms for memory allocation in operating system, Explain First- t and best- t methods are used in memory allocation in operating systems.

  Stand alone child process

Forking the child process

  Write a multi-threaded program

Write a multi-threaded program to solve producer and consumer problem

  Marginal and average cost curves

n a competitive market place (pure competition) is it possible to continually sell your product at a price above the average cost of production.

  Simulating operating systems scheduling

Simulate the long-term scheduler, the short-term scheduler and the I/O scheduler of the computer using the First-Come-First-Serve algorithm.

  Issues with trusted platform module

Research paper discussing the issues with Trusted Platform Module (TPM)

  Threads

Explain a complication that concurrent processing adds to an operating system.

  Design and programming

Use the semaphore methods to control the concurrency of the solution

  Virtual machines

Virtual machines supported by a host operating system

  Discuss an application that benefits barrier synchronization

Discuss an application that would benefit from the use of barrier synchronization

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd