If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > File List

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-17-04, 02:37
renga renga is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
File List

How to get the list of files from the specified directory between two given date using shell script
Reply With Quote
  #2 (permalink)  
Old 03-17-04, 03:28
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Extract from man page :

Quote:
`su' allows one user to temporarily become another user. It runs
command (often an interactive shell) with the real and effective user
id, group id, and supplemental groups of a given USER.


By default, `su' does not change the current directory. It sets the
environment variables `HOME' and `SHELL' from the password entry for
USER, and if USER is not the super-user, sets `USER' and `LOGNAME' to
USER. By default, the shell is not a login shell.

Any additional ARGs are passed as additional arguments to the shell.



`-'
`-l'
`--login'
Make the shell a login shell. This means the following. Unset all
environment variables except `TERM', `HOME', and `SHELL' (which
are set as described above), and `USER' and `LOGNAME' (which are
set, even for the super-user, as described above), and set `PATH'
to a compiled-in default value. Change to USER's home directory.
Prepend `-' to the shell's name, intended to make it read its
login startup file(s).
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-18-04, 01:34
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: File List

Quote:
Originally posted by renga
How to get the list of files from the specified directory between two given date using shell script
Hello,

U can make use of "find" command with option -ctime or -atime or -mtime according to ur requirement .
Please see man find for detailed information.

--cheers,
Pooja
Reply With Quote
  #4 (permalink)  
Old 03-18-04, 02:52
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Oops!, my previous post was for anoyher thread
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 03-18-04, 04:08
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
You can use find or the bash/ksh '-nt' and '-ot' operators.

With find :
Code:
#
# Find files between two dates
#

Usage() {
   if [ -n "$1" ]; then
      echo "$*"
      echo ""
   fi
   echo "Usage: $(basename $0) from_date [to_date]"
   echo "   from_date : YYYY/MM/DD"
   echo "   to_date   : YYYY/MM/DD (Def=from_date)"
   echo ""
   echo "List files between from_date 00:00.01 "
   echo "and to_date 23:59.59"
   exit 1
}

[ $# -eq 0 -o $# -gt 2 ] && Usage "Invalid argument count"
[ $# -eq 1 ] && set "$1" "$1"

Fdate="$(echo "$1" | tr -d '/')0000.00"
Tdate="$(echo "$2" | tr -d '/')2359.59"


[ ${#Fdate} -ne 15 ] && Usage "Invalid 'from_date'"
[ ${#Tdate} -ne 15 ] && Usage "Invalid 'to_date'"

Ffile=/tmp/from.$$
Tfile=/tmp/to.$$

touch -t $Fdate $Ffile
touch -t $Tdate $Tfile

find . -type f -newer $Ffile ! -newer $Tfile  -ls
rm -f $Ffile $Tfile
With -nt and -nt operators :
Code:
#
# Find files between two dates
#

Usage() {
   if [ -n "$1" ]; then
      echo "$*"
      echo ""
   fi
   echo "Usage: $(basename $0) from_date [to_date]"
   echo "   from_date : YYYY/MM/DD"
   echo "   to_date   : YYYY/MM/DD (Def=from_date)"
   echo ""
   echo "List files between from_date 00:00.00 "
   echo "and to_date 23:59.59"
   exit 1
}

[ $# -eq 0 -o $# -gt 2 ] && Usage "Invalid argument count"
[ $# -eq 1 ] && set "$1" "$1"

Fdate="$(echo "$1" | tr -d '/')0000.00"
Tdate="$(echo "$2" | tr -d '/')2359.59"

[ ${#Fdate} -ne 15 ] && Usage "Invalid 'from_date'"
[ ${#Tdate} -ne 15 ] && Usage "Invalid 'to_date'"

Ffile=/tmp/from.$$
Tfile=/tmp/to.$$

touch -t $Fdate $Ffile
touch -t $Tdate $Tfile

for file in $(ls -t)
do
  [ "$file" -ot $Ffile ] && break
  [ "$file" -nt $Tfile ] && continue
  ls -ld $file
done
rm -f $Ffile $Tfile
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On