#!/bin/sh ## ## SCRIPT: 05_anyfile4Dir_findFILES-SIZE-SORT_allLEVS_find-f-ls-sort.sh ## ## PURPOSE: Relative to a 'base' directory (the 'current' directory), ## this script lists ALL files in the directory AND in its ## subdirectories at ALL levels below --- ## sorting ALL the files by size. ## ## METHOD: Uses 'find' and 'ls' piped to the 'sort' command. ## ## Puts the output of the 'sort' command in a text file --- ## after piping the output through a reverse-sort on field 5, ## file size. ## ## Shows the text file using a text-file viewer of the ## user's choice. ## ## HOW TO USE: In Nautilus, select any file in the desired 'base' directory. ## Then right-click and choose this Nautilus script to run. ## (See the script name above.) ## ## Created: 2013feb26 Based on FE Nautilus Script ## 05_anyfile4Dir_findFILES-OLD-BIGGEST_allLEVS_find-f-mtime-ls-sort.sh ## Changed: 2013 ## FOR TESTING: (show statements as they execute) # set -x ################################################# ## Prepare the output file. ## ## If the user has write-permission on the ## current directory, put the file in the pwd. ## Otherwise, put the file in /tmp. ################################################# CURDIR="`pwd`" OUTFILE="${USER}_temp_dirFilesRecursiveLIST_SIZE-SORT_find-f-ls-sort.txt" if test ! -w "$CURDIR" then OUTFILE="/tmp/$OUTFILE" fi if test -f "$OUTFILE" then rm -f "$OUTFILE" fi ##################################### ## Generate a heading for the listing. ##################################### DATETIME=`date '+%Y %b %d %a %T%p'` echo "\ ..................... $DATETIME ............................ List of ALL (non-directory) FILES under the directory $CURDIR --- at ALL levels (recursive) --- sorted so that the BIGGEST are at the top. Size Last Modified Permissions Userid Grpid (bytes) Date-time Filename ---------- ------ ------ -------- ------------ ----------- " > "$OUTFILE" ############################################### ## Add the sorted 'find' output to the listing. ############################################### find . -type f -name "*" -exec ls -l {} \; | \ sort -r -n -k5 >> "$OUTFILE" ##################################### ## Generate a trailer for the listing. ##################################### SCRIPT_BASENAME=`basename $0` SCRIPT_DIRNAME=`dirname $0` echo " ........................................................................... This list was generated by script $SCRIPT_BASENAME in directory $SCRIPT_DIRNAME Used command find . -type f -name \"*\" -exec ls -l {} \; | \\ sort -r -n -k5 ..................... $DATETIME ............................ " >> "$OUTFILE" ###################### ## Show the listing. ###################### ## . $HOME/.gnome2/nautilus-scripts/.set_VIEWERvars.shi . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi . $DIR_NautilusScripts/.set_VIEWERvars.shi $TXTVIEWER "$OUTFILE" &