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

  How would you define an enterprise

How does this guide or limit the scope of an enterprise system implementation project?

  Comparison of wireless lan and lan

Assume your local hospital has decided to extend their offices to another department of the building where it is difficult to have cables installed.

  Consider a version of the bounded buffer problem

Consider a version of the bounded buffer problem in which there is two producer processes (P1and P2) and one consumer processes (P3) all sharing the same buffer. Assume that the size of the buffer is n=4, and that we start with a completely empty buf..

  Write an exploit / attack for the scanf function.

Write an exploit / attack for the scanf function. Explain how the given buffer overflow attack works. Hint: write second program that spits out input.

  How could you try to solve this problem using a gui

Open a Command Prompt (MS-DOS Prompt) window and complete the following activities. As always, be sure to cite any sources you use in your response.

  Drawbacks and benefits of a peer to peer network

Describe to Champions the drawbacks and benefits of a peer-to-peer network. What can be shared between hosts?

  Define the shortest job first

For shortest job first, if the scheduler assigns a task to the processor, and no other task becomes schedulable in the meantime, will the scheduler ever.

  Describe the fundamental components of a distributed system

Compare and contrast the advantages and disadvantages of at least 2 distributed system architectures.

  Software faults - windows xp

Analysis shows that there are about five faults per 1000 lines of code in carefully made programs, which means that one million lines of codes will have 5000 faults.

  Distinguish between the internet, intranets, extranets.

Explain how database processing differs from file (sequential) processing.

  Protecting the company data

Suppose you work for a small, one office loan business. Your data is critical, and a fire or other disaster could destroy all of your computer documents.

  Implementation and effects of different scheduling policies

In this lab we explore the implementation and effects of different scheduling policies discussed in class on a set of processes/threads executing on a system. The system is to be implemented as a Discrete Event Simulation

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