Updated find to list script

This is an update to the earlier script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<span style="color: #333399;">#!/bin/sh
# v1 jcz 30-dec-2009
# This is a silly little script that will search 
# for files of a certain type and create a text file of the results
# TODO: 
#  - Everything
# - Fix this script to run under cygwin 1.7.X after working fine under 1.5.X
 
############################
# enable for debugging #####
############################
# set -vx
 
############################
#  Global script variables block
############################
# Date and other variables pretty self explanatory, S is seconds
# date format is currently YYYYMMDD_HHMMSS
 dater=$(date +%Y-%m-%d_%H:%M:%S)
 dayer=$(date +%a)
 namer=$(whoami)
 hoster=$(hostname)
 directory=$(pwd)
 filenamer=$(date +%Y%m%d_%H%M%S).txt
# sets day of the week for incremental backups
 set $(date)
 
############################
#  Clear the screen and introduce the user to the script
############################
 
clear
echo ""
echo "WELCOME TO THE FIND TO LIST SCRIPT"
echo ""
 
############################
#  Wait for the user to enter a new file extension and capture the value as a variable
############################
echo ""
echo -n "Enter file extension to search for, without the leading dot (e.g. txt): "
read fileext
echo ""
echo ""
 
############################
#  Wait for the user to enter a new file destination
############################
echo -n "Enter a new log file destination without ending slash (e.g., /cygdrive/c ): "
read filedest
echo ""
echo ""
 
############################
#  Create the file for the script named after the file extension
############################
echo "----" >> $filedest/$filenamer
# echo "----" > $filedest/$fileext_files_from_$directory_on_$dater.txt
echo "File created on: "$dater  >> $filedest/$filenamer
echo "Script was run in: "$directory >> $filedest/$filenamer
echo "By user: " $namer  >> $filedest/$filenamer
echo "Searching for files ending in: " $fileext >> $filedest/$filenamer
echo "This file was written to: " $filedest/$filenamer >> $filedest/$filenamer
echo "The command issued was: find . -name '*.'$fileext -type f -print0 | xargs -0  stat -c 'file: %N | bytes: %s | modtime: %y | changetime: %z'" >> $filedest/$filenamer
echo "***************************"  >>$filedest/$filenamer
echo "" >> $filedest/$filenamer
 
find . -name '*.'$fileext -type f -print0 | xargs -0  stat -c 'file: %N | bytes: %s | modtime: %y | changetime: %z' >> $filedest/$filenamer
 
echo -n "Hit enter to continue "
read none
 
echo ""
echo "* Now I will show you the file and be done"
echo ""
echo -n "Hit enter to list or Ctrl-c to quit "
read none
less $filedest/$filenamer</span>
<span style="color: #333399;">#!/bin/sh
# v1 jcz 30-dec-2009
# This is a silly little script that will search 
# for files of a certain type and create a text file of the results
# TODO: 
#  - Everything
# - Fix this script to run under cygwin 1.7.X after working fine under 1.5.X

############################
# enable for debugging #####
############################
# set -vx

############################
#  Global script variables block
############################
# Date and other variables pretty self explanatory, S is seconds
# date format is currently YYYYMMDD_HHMMSS
 dater=$(date +%Y-%m-%d_%H:%M:%S)
 dayer=$(date +%a)
 namer=$(whoami)
 hoster=$(hostname)
 directory=$(pwd)
 filenamer=$(date +%Y%m%d_%H%M%S).txt
# sets day of the week for incremental backups
 set $(date)

############################
#  Clear the screen and introduce the user to the script
############################

clear
echo ""
echo "WELCOME TO THE FIND TO LIST SCRIPT"
echo ""

############################
#  Wait for the user to enter a new file extension and capture the value as a variable
############################
echo ""
echo -n "Enter file extension to search for, without the leading dot (e.g. txt): "
read fileext
echo ""
echo ""

############################
#  Wait for the user to enter a new file destination
############################
echo -n "Enter a new log file destination without ending slash (e.g., /cygdrive/c ): "
read filedest
echo ""
echo ""

############################
#  Create the file for the script named after the file extension
############################
echo "----" >> $filedest/$filenamer
# echo "----" > $filedest/$fileext_files_from_$directory_on_$dater.txt
echo "File created on: "$dater  >> $filedest/$filenamer
echo "Script was run in: "$directory >> $filedest/$filenamer
echo "By user: " $namer  >> $filedest/$filenamer
echo "Searching for files ending in: " $fileext >> $filedest/$filenamer
echo "This file was written to: " $filedest/$filenamer >> $filedest/$filenamer
echo "The command issued was: find . -name '*.'$fileext -type f -print0 | xargs -0  stat -c 'file: %N | bytes: %s | modtime: %y | changetime: %z'" >> $filedest/$filenamer
echo "***************************"  >>$filedest/$filenamer
echo "" >> $filedest/$filenamer

find . -name '*.'$fileext -type f -print0 | xargs -0  stat -c 'file: %N | bytes: %s | modtime: %y | changetime: %z' >> $filedest/$filenamer

echo -n "Hit enter to continue "
read none

echo ""
echo "* Now I will show you the file and be done"
echo ""
echo -n "Hit enter to list or Ctrl-c to quit "
read none
less $filedest/$filenamer</span>