#!/bin/sh ## ## Nautilus ## SCRIPT: F1c_anyfile4Dir_LIST_FILESdirs-all_1LEV_WITHtypeDESCs_find-f_for-loop-file.sh ## ## PURPOSE: Lists ALL files in a directory (including 'hidden' files) ## --- with their file-type as revealed by the 'file' command. ## ## METHOD: Uses the 'find' command to get all the files at the level of ## the current directory, i.e. only one-level deep. ## ## Then performs a loop over those filenames (which can include ## directory files and special files), putting the output of the ## 'file' command, for each file, in a text file. ## ## Shows the text file using a text-file viewer of the user's ## choice. ## ## HOW TO USE: In Nautilus, select any file in the 'navigated-to' directory. ## Then right-click and choose this Nautilus script to run. ## ## Started: 2011jul15 ## Changed: 2012feb29 Changed the script name in the comment above. ## 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_dirFILESlist_1lev_ls-A_for-file.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 FILES (and their FILE-TYPES) under/in the directory ${CURDIR}/ --- ONE-LEVEL only. ........................................................................... " > "$OUTFILE" ################################################################# ## Generate the list of filenames --- in the current directory ## (one level) --- using 'find'. ################################################################# FILENAMES=`find . -maxdepth 1 -type f -name '*' -print | sort` ################################################################# ## For each filename, in a for-loop, apply the 'file' command ## to get the filetype to put in the listing. ################################################################# IFS=" " for FILENAME in $FILENAMES do file "$FILENAME" >> "$OUTFILE" done ##################################### ## Add a trailer to the listing. ##################################### SCRIPT_BASENAME=`basename $0` SCRIPT_DIRNAME=`dirname $0` echo " ....................................................................... This list was generated by script $SCRIPT_BASENAME in directory $SCRIPT_DIRNAME Used the command find . -maxdepth 1 -type f -name '*' -print | sort to get the list of filenames in the current directory (one-level, NOT recursive) --- including 'hidden' files, if any. Applied the 'file' command in a 'for' loop to get the file-type of each file. ..................... $DATETIME ............................ " >> "$OUTFILE" ################### ## Show the list. ################### ## . $HOME/.gnome2/nautilus-scripts/.set_VIEWERvars.shi . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi . $DIR_NautilusScripts/.set_VIEWERvars.shi $TXTVIEWER "$OUTFILE" &