Results 1 to 5 of 5

Thread: File List

  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: File List

    How to get the list of files from the specified directory between two given date using shell script

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Extract from man page :

    `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.

  3. #3
    Join Date
    Dec 2002
    Posts
    104

    Re: File List

    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

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Oops!, my previous post was for anoyher thread
    Jean-Pierre.

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

Posting Permissions

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