**************************************************************** ******************************* lss **************************** **************************************************************** #!/bin/sh PATH=/local/bin:/usr/local:/usr/ucb:/usr/bin:/u/csc/bin:/bin export PATH LS=/usr/ucb/ls; SORT="sort +3nr" # List filenames in order of non-increasing byte size. # Don't descend directories unless the files in them are explicitly listed. # This rigamarole needs to be here. Delete at your own risk. # (The for loop is fast; no external commands are called.) # We can't just do "ls -ld $*" because if there are no arguments, all we get is # drwx------ 4 wayne 1024 Sep 24 15:46 . # which isn't what we intended. Thus, if there are no arguments, then list # everything in the current directory; otherwise, list everything that's # listed on the command line, but don't descend any directories. But now # we need to recognize if no *files* were listed, but options to ls(1) were # listed. So we have to erase all the options before asking "was there # anything on the command line?" The loop is fast; no external commands # are called. files= opts= for i # a "for" with no list defaults to "$@" do case "$i" in -[aAbcFLnpqu]) opts="$opts $i" ;; -*) echo "unsupported option $i" >&2 exit 1 ;; *) files="$files $i" # this is WRONG if $i contains spaces, ;; # but there's no easy way around it. esac done case "$files" in "") $LS -l $opts | $SORT ;; *) $LS -ld $opts $files | $SORT ;; esac You need to set the environment variable TRASH to some directory at login time, eg. "$HOME/.trash". This implementation uses the "global save directory". This is probably the easiest way to do it. "srm" just moves all of it's arguments to $TRASH. "unrm" simply moves things from TRASH back to the current directory. (Note that it doesn't check to see if this is the directory it was removed from; you *could* do this, but it wasn't necessary for this assignment. Of course, if you implemented "srm" to keep things in the current directory but just "hide" them, then this check is implicit.) And of course "trash" just removes the entire directory heirarchy starting at $TRASH. Note that it's not good enough to just "/bin/rm $TRASH"; you MUST do "rm -rf $TRASH", in case their are entire directories in $TRASH that were srm'd. ******************************************************************** ********************************** srm ***************************** ******************************************************************** #!/bin/sh # if there are options, just exec the regular rm(1) case "$1" in -*) exec /usr/bin/rm "$@" ;; esac mv "$@" $TRASH ******************************************************************** ********************************* unrm ***************************** ******************************************************************** #!/bin/sh for i do mv "$TRASH/$i" "$i" done ******************************************************************** ********************************* trash **************************** ******************************************************************** #!/bin/sh cd /bin/rm -rf $TRASH mkdir $TRASH chmod 700 $TRASH # be paranoid, don't let anybody in to the TRASH directory.