Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    6

    Unhappy Unanswered: Problem Unix (i am not expert on use of Unix)

    How I can obtain a list of files having same year?
    For example :all files of directory /tmp/pippo/ having creation year 2003?

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: Problem Unix (i am not expert on use of Unix)

    Originally posted by sistemi
    How I can obtain a list of files having same year?
    For example :all files of directory /tmp/pippo/ having creation year 2003?
    ls -la /tmp/pippo | grep 2003 - simplest way
    If you would like grep by date column only you need to use "awk"

  3. #3
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320

    Re: Problem Unix (i am not expert on use of Unix)

    Originally posted by ika
    ls -la /tmp/pippo | grep 2003 - simplest way
    If you would like grep by date column only you need to use "awk"
    There are two problems with this solution :
    1) A filename may contains the year
    2) For files newer than 6 months, ls don't display the year

    The following script use find to select the files.
    Code:
    year=${1:-`date +%Y`}
    
    syear=`expr $year - 1`
    since_date=${syear}12312359.59
    since_file=/tmp/since_${year}.$$
    
    byear=`expr $year + 1`
    before_date=${byear}01010000.00
    before_file=/tmp/before_${year}.$$
    
    touch -t $since_date $since_file 
    touch -t $before_date $before_file 
    
    find . ! -name . -prune ! -newer $before_file -newer $since_file | xargs ls -lad
    
    rm -f $since_file $before_file
    Run this script with the requested year as argument (default is current year).
    If you want to include files in sub-directories, remove '! -name . -prune' from the options of the find command.
    Jean-Pierre.

  4. #4
    Join Date
    Apr 2004
    Posts
    6

    Re: Problem Unix (i am not expert on use of Unix)

    thanks you very much!!
    There are two problems with this solution :
    1) A filename may contains the year
    2) For files newer than 6 months, ls don't display the year

    The following script use find to select the files.
    Code:
    year=${1:-`date +%Y`}
    
    syear=`expr $year - 1`
    since_date=${syear}12312359.59
    since_file=/tmp/since_${year}.$$
    
    byear=`expr $year + 1`
    before_date=${byear}01010000.00
    before_file=/tmp/before_${year}.$$
    
    touch -t $since_date $since_file 
    touch -t $before_date $before_file 
    
    find . ! -name . -prune ! -newer $before_file -newer $since_file | xargs ls -lad
    
    rm -f $since_file $before_file
    Run this script with the requested year as argument (default is current year).
    If you want to include files in sub-directories, remove '! -name . -prune' from the options of the find command. [/SIZE][/QUOTE]

  5. #5
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: Problem Unix (i am not expert on use of Unix)

    Originally posted by aigles
    There are two problems with this solution :
    1) A filename may contains the year
    2) For files newer than 6 months, ls don't display the year

    The following script use find to select the files.
    Code:
    year=${1:-`date +%Y`}
    
    syear=`expr $year - 1`
    since_date=${syear}12312359.59
    since_file=/tmp/since_${year}.$$
    
    byear=`expr $year + 1`
    before_date=${byear}01010000.00
    before_file=/tmp/before_${year}.$$
    
    touch -t $since_date $since_file 
    touch -t $before_date $before_file 
    
    find . ! -name . -prune ! -newer $before_file -newer $since_file | xargs ls -lad
    
    rm -f $since_file $before_file
    Run this script with the requested year as argument (default is current year).
    If you want to include files in sub-directories, remove '! -name . -prune' from the options of the find command.
    As I said that is the simples (primitive) solution with many disadvantages but very quick...

Posting Permissions

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