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 > Problem Unix (i am not expert on use of Unix)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-06-04, 06:32
sistemi sistemi is offline
Registered User
 
Join Date: Apr 2004
Posts: 6
Unhappy 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?
Reply With Quote
  #2 (permalink)  
Old 04-06-04, 07:40
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: Problem Unix (i am not expert on use of Unix)

Quote:
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"
Reply With Quote
  #3 (permalink)  
Old 04-06-04, 08:28
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Re: Problem Unix (i am not expert on use of Unix)

Quote:
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.
Reply With Quote
  #4 (permalink)  
Old 04-06-04, 10:02
sistemi sistemi is offline
Registered User
 
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]
Reply With Quote
  #5 (permalink)  
Old 04-06-04, 11:28
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: Problem Unix (i am not expert on use of Unix)

Quote:
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...
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