#!/bin/ksh ## ## SCRIPT: filesel_info4allfiles_4dir_showBYgui ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################## ## ## PURPOSE: For a given Directory (like $HOME or /local/scratch ) ## (passed in var $1), this script creates an 'ls -al' info report, ## for the files in that directory. ## ## Prompts the user (with 'xconfirm' or a similar Tk GUI) for 3 ## sort options: name sort, age-sort, size-sort ## ## Puts the report into a temp-file ## and shows the report file with shofil_ver2.tk (the 'xpg' utility). ## ## Checks for 1 argument and checks that the directory exists. ## In either case, if not, Pops an 'xconfirm' error msg and exits. ############################################################################## ## ## CALLED BY: file_select_gui_ver2.tk in $FEDIR/tkGUIs ############################################################################## ## ## CALL FORMAT (example): ## ## $FEDIR/scripts/filesel_info4allfiles_4dir_showBYgui /local/scratch/$USER ## ############################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 29nov2001 Based on 'filesel_edit_text' & ## 'filesel_info4allfiles_4mask_showBYgui.old2001nov30PREL1' & ## 'diruse_files_onelevel_sizesort_bygui' & ## 'diruse_files_onelevel_agesort_bygui' ## in $FEDIR/scripts. ## Updated by: Blaise Montandon 03dec2001 Added $XPG_MSG to the trailer of ## each of the three sort report opts. ## Updated by: Blaise Montandon 10jan2002 1) Use 'ls -lAp' twice with 'grep' to ## show dirs first, then files. ## 2) When field9 (filename) contains ## embedded blanks, awk shows only ## first segment of filename. ## For now, do not use awk formatting. ## ## Updated by: Blaise Montandon 08apr2004 To avoid a bug in new SGI 'sort' ## in IRIX 6.5.22, changed several cases ## of 'sort -k5nr' to ## 'sort +4 -5nr'. ############################################################################## THISHOST=`hostname` ############################################################################# ## Set scripts pathname in case this toolchest is not started from ## the nnsFEAmenu system --- and a $FEDIR utility script (or help) is needed. ############################################################################# if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi ############################################################ ## Assure that the DISPLAY variable is set. ## Set to do X-displays on this host. ############################################################ # # if test "${DISPLAY}" = "" # then # DISPLAY="$THISHOST:0" # export DISPLAY # fi ############################################################ ## If this is a remote login, ## set X-display to the remote host. ############################################################ # if test ! "$REMOTEHOST" = "" # then # REMOTEHOST1=`echo $REMOTEHOST | cut -d. -f1` # DISPLAY="$REMOTEHOST1:0" # export DISPLAY # fi ############################################################ ## Set DIRNAME var from $1 -- and check that it is not null. ############################################################ ## FOR TESTING: # set -x DIRNAME="$1" if test "$DIRNAME" = "" then # -font $CONFIRM_FONT \ xconfirm -c -header "NO_INPUT_warning" \ -B Dismiss \ -t "The script $0" \ -t "needs input --- a directory," \ -t "like /local/scratch/$USER ." \ -icon warning > /dev/null exit fi ############################################################ ## Check that the directory exists. ## If not, exit with msg. ############################################################ if test ! -d "$DIRNAME" then xconfirm -c -header "DIRECTORY_NOT_FOUND_warning" \ -B Dismiss \ -t "The directory $DIRNAME " \ -t "was NOT FOUND. It is not known to host $THISHOST." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ############################################################ ## Ask for sort -- by name or age or size? ############################################################ SORT_TYPE=`xconfirm -c -header "SORT by NAME or AGE or SIZE?" \ -b CANCEL -b SIZE -b AGE -B NAME \ -t "In the report, sort the files of directory" \ -t "" \ -t " $DIRNAME" \ -t "" \ -t "by NAME -OR- AGE -OR- SIZE ?" \ -icon warning` # -font $CONFIRM_FONT \ if test "$SORT_TYPE" = "CANCEL" then exit fi ################################################################### ## PREPARE REPORT FILENAME -- in $OUTLIST. ################################################################### . $FEDIR/scripts/set_localoutlist ################################################################### ## Set a common message for the trailer of the 3 reports ## -- in $XPG_MSG. ################################################################### XPG_MSG="\ SELECTING LINES OF THE REPORT -- via a string-pattern: When you browse the report with the 'xpg' utility, you may want to extract/see just those lines that contain a certain string. To do that, you can use the 'ShowAllMatches' button with the plus-or-minus N lines option, with N set to zero (0). Three examples: 1) To see all files containing the string 'out', put the string 'out' (without the quotes) in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. For examples 2 & 3, note that for DIRECTORIES, the permissions info starts with 'd' and usually starts with 'dr' -- in fact, usually 'drwx'. The permissions info for (non-directory) FILES starts with '-' and usually starts with '-r' -- in fact, usually '-rw'. Hence: 2) To see the files-lines and NOT the directory-lines of the report, put '-r' in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. 3) To see the directories-lines and NOT the nondirectory-file-lines of the report, put 'dr' or 'drwx' in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. " ########################################################################## ########################################################################## ## FOLLOWING ARE THREE BIG 'if' SECTIONS --- for ## SORT_TYPE = NAME -OR- AGE -OR- SIZE ########################################################################## ########################################################################## ########################################################################## ## PREPARE THE 'SORT_TYPE = NAME' REPORT. ########################################################################## if test "$SORT_TYPE" = "NAME" then ## FOR TESTING: # set -x LS_OUT_DIRS=`ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - ######################################### ## PREPARE THE 'NAME' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory $DIRNAME SORTED BY ** NAME ** (directory names, then file names; case-sensitive) This report was generated by running the 'ls -lAp' command on $THISHOST . *********** Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- " > $OUTLIST ########################################## ## PREPARE THE 'NAME' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x echo "$LS_OUT_DIRS" >> $OUTLIST echo "$LS_OUT_FILS" >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lAp' command on host $THISHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be accessed via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, SIZE-SORT)'. or 'Show FILE-SIZES 4aDir@AnyHost (ONE level, AGE-SORT)'. Those utilities sort by file size & age -- not by name. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "NAME" ####################################### ########################################################################## ## PREPARE THE 'SORT_TYPE = AGE' REPORT. ########################################################################## if test "$SORT_TYPE" = "AGE" then ## FOR TESTING: # set -x LS_OUT_DIRS=`ls -lApt "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lApt "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - ######################################### ## PREPARE THE 'AGE' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory $DIRNAME SORTED BY ** AGE ** --- NEWEST (or most recently modified) DIRECTORIES AT THE TOP of the directories, and NEWEST (or most recently modified) FILES AT THE TOP of the files. This report was generated by running the 'ls -lApt' command on $THISHOST . ************* Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- " > $OUTLIST ########################################## ## PREPARE THE 'AGE' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x echo "$LS_OUT_DIRS" >> $OUTLIST echo "$LS_OUT_FILS" >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lAp' command on host $THISHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be run via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, AGE-SORT). Since that utility is intended to help with file cleanup, it shows the oldest files first. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "AGE" ####################################### ########################################################################## ## PREPARE THE 'SORT_TYPE = SIZE' REPORT. ########################################################################## if test "$SORT_TYPE" = "SIZE" then ## FOR TESTING: # set -x LS_OUT_DIRS=`ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - ######################################### ## PREPARE THE 'SIZE' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory $DIRNAME SORTED BY ** SIZE ** --- BIGGEST DIRECTORY 'INDEXES' AT THE TOP of the directories, and BIGGEST FILES AT THE TOP of the files. This report was generated by running the 'ls -lAp' command on $THISHOST . ************* Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- " > $OUTLIST ########################################## ## PREPARE THE 'SIZE' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x # echo "$LS_OUT_DIRS" | sort -k5nr >> $OUTLIST # echo "$LS_OUT_FILS" | sort -k5nr >> $OUTLIST echo "$LS_OUT_DIRS" | sort +4 -5nr >> $OUTLIST echo "$LS_OUT_FILS" | sort +4 -5nr >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lAp' command on host $THISHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be accessed via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, SIZE-SORT)'. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "SIZE" ####################################### ################################################################### ## SHOW the 'ls -al' report (sorted by name or age or size). ################################################################### $FEDIR/scripts/shofil $OUTLIST