#!/bin/sh ## ## SCRIPT: 05_anyfile4Dir_findFILES-YOUNGEST_allLEVS_find-f-mtime-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 --- ## that have been modified (incl. created) more than N days ago --- ## using the 'find' command with the '-mtime' option. ## ## METHOD: Uses 'zenity' to prompt for the number of days, N. ## ## Puts the output of the 'find' command in a text file, after ## piping the output through a sort on fields 6 and 7, ## date and time. ## ## 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: 2012jun25 Based on FE Nautilus Script ## 05_anyfile4Dir_findFILES-YOUNGEST_allLEVS_find-f-mtime-ls-sort.sh ## Changed: 2012 ## 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_OLDones_find-mtime-ls-sort.txt" if test ! -w "$CURDIR" then OUTFILE="/tmp/$OUTFILE" fi if test -f "$OUTFILE" then rm -f "$OUTFILE" fi ############################################ ## Prompt for N days, using zenity. ############################################ NDAYS="" NDAYS=$(zenity --entry \ --title "\ Enter N days, for this 'files modified long-ago' utility." \ --text "\ Enter an integer. Example: 365 to see files modified more than a year ago. 30 to see files modified (incl. created) more than a month ago." \ --entry-text "365") if test "$NDAYS" = "" then exit fi ##################################### ## Generate a heading for the listing. ##################################### DATETIME=`date '+%Y %b %d %a %T%p'` echo "\ ..................... $DATETIME ............................ List of (non-directory) FILES under the directory $CURDIR --- at ALL levels (recursive) --- files that have been MODIFIED or CREATED more than $NDAYS DAY(s) ago and sorted by date-time so that the OLDEST are at the top. Size Last Modified Permissions Userid Grpid (bytes) Date-time Filename ---------- ------ ------ -------- ------------ ----------- " > "$OUTFILE" ######################################## ## Add the 'find' output to the listing. ######################################## find . -type f -mtime +$NDAYS -name "*" -exec ls -l {} \; | \ sort -k6 -k7 >> "$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 -mtime +$NDAYS -name \"*\" -exec ls -l {} \; | \\ sort -k6 -k7 ..................... $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" &