Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    71

    Unanswered: file from a specified date

    I have list of files like below.looking for easier way to find files from a specified day.
    -rw-rw-rw- 1 me91p01 e9100p1 64638 Mar 24 07:13 032404_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 55917 Mar 25 07:12 032504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 26 07:12 032604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 27 06:05 032704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 28 06:04 032804_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 44631 Mar 29 07:09 032904_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 60534 Mar 30 07:13 033004_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 90288 Mar 31 07:12 033104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 159030 Apr 1 07:12 040104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 2 07:12 040204_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 3 06:06 040304_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 4 06:04 040404_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54378 Apr 5 07:10 040504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 77976 Apr 6 07:17 040604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54891 Apr 7 07:13 040704_ALI.TXT


    for eg. to list file from March 28 till today i was trying it backwards.

    find . -name "[0-9]*.TXT" -mtime -11 -exec ls -l {} ;
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 3 06:06 ./040304_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 44631 Mar 29 07:09 ./032904_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54891 Apr 7 07:13 ./040704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 4 06:04 ./040404_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 60534 Mar 30 07:13 ./033004_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 77976 Apr 6 07:17 ./040604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 159030 Apr 1 07:12 ./040104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54378 Apr 5 07:10 ./040504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 28 06:04 ./032804_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 90288 Mar 31 07:12 ./033104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 2 07:12 ./040204_ALI.TXT

    above doesn't display in right order plus not a good way to do
    can someone suggest better and short solution. how about newer option in find
    command?

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You can use the -newer option of the command find.
    Try and adapt the following script :

    Code:
    #!/usr/bin/sh
    # lss - List files from a certain date
    # Arg: From date, yyyymmdd (default today)
    
    from_date=${1:-`date +'%Y%m%d'`}0000.00
    from_file=/tmp/from.$$
    
    touch -t $from_date $from_file 
    find . -name "[0-9]*.TXT" -newer $from_file -exec ls -l  {} \;
    rm -f $from_file
    Attention, files created At 00:00.00 on From date will not be displayed.
    If this a problem for you, modify the script to use the previous day 23;59;59 as from date.
    Jean-Pierre.

  3. #3
    Join Date
    Sep 2003
    Posts
    71
    Thanks aigels for quick help as always

    it still doesn't give me sorted listing in ascending order of file creation.
    I need to further all files based on filedate
    ..........
    listfile.sh 20040325
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 3 06:06 ./040304_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 44631 Mar 29 07:09 ./032904_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54891 Apr 7 07:13 ./040704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 4 06:04 ./040404_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 60534 Mar 30 07:13 ./033004_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 77976 Apr 6 07:17 ./040604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 159030 Apr 1 07:12 ./040104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54378 Apr 5 07:10 ./040504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 55917 Mar 25 07:12 ./032504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 26 07:12 ./032604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 27 06:05 ./032704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 28 06:04 ./032804_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 90288 Mar 31 07:12 ./033104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 2 07:12 ./040204_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 57456 Apr 8 07:11 ./040804_ALI.TXT

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    I don't know how to sort easily the file list.

    The following script uses another method to list files from a date (doesn't use 'find'), but it is valid only for bash and ksh.
    Code:
    #!/usr/bin/ksh
    # lss - List files from a certain date
    # Arg: From date, yyyymmdd (default today)
    
    from=${1:-`date +'%Y%m%d'`}
    
    from_date=${from}0000.00
    from_file=/tmp/from.$$
    
    touch -t $from_date $from_file 
    
    ls -ltr | awk '$9 ~ /[0-9]*.TXT/ {print $9 "|" $0}' | \
    while IFS='|' read file infos
    do
       [ -z "$from_confirmed" -a "$file" -ot $from_file ] && continue
       echo $infos
       from_confirmed=YES
    done
    rm -f $from_file
    Jean-Pierre.

  5. #5
    Join Date
    Sep 2003
    Posts
    71
    man you have wealth of info. Thanks a lot
    liked your trick , worked for me , i use korn shell

    listfile2.sh 20040325
    -rw-rw-rw- 1 me91p01 e9100p1 55917 Mar 25 07:12 032504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 26 07:12 032604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 27 06:05 032704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 40527 Mar 28 06:04 032804_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 44631 Mar 29 07:09 032904_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 60534 Mar 30 07:13 033004_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 90288 Mar 31 07:12 033104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 159030 Apr 1 07:12 040104_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 2 07:12 040204_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 3 06:06 040304_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 101061 Apr 4 06:04 040404_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54378 Apr 5 07:10 040504_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 77976 Apr 6 07:17 040604_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 54891 Apr 7 07:13 040704_ALI.TXT
    -rw-rw-rw- 1 me91p01 e9100p1 57456 Apr 8 07:11 040804_ALI.TXT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •