The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to listout the files based on group by the date...? psiva_arul UNIX for Dummies Questions & Answers 3 04-21-2008 09:03 AM
Traversing thru dirs and deleting files based on date ravi2082 Shell Programming and Scripting 5 07-18-2007 04:28 PM
Remove files based on date hshapiro UNIX for Dummies Questions & Answers 4 12-09-2005 12:21 PM
script to view files based on date krahuliyer Shell Programming and Scripting 6 10-05-2005 04:51 AM
Moving files based on creation date dgoyea UNIX for Dummies Questions & Answers 1 06-28-2001 05:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-09-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
Count of files based on date?

Hi Friends,

Can anyone help me with this:
To get the count of files that are existing in a directory created on a perticular date like in the example (01/08) .(having same pattern for the filename)

ex:
FileName Creted Date

FILE001 01/08/2007
FILE005 01/06/2007
TXT003 01/08/2007
FILE005 01/08/2007

I need count i.e "2" (FILE001 and FILE005 created on 01/08)

I have used ls -l | grep -c ^- It is retrieving all the files in the directory,


Thanks in advance

Sam
  #2 (permalink)  
Old 01-09-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Of course it is retreiving all the files. In your command you are just running 'ls -l|grep -c ^-'. This lists all files in the directory, then just filters out plain files (removes dirs/pipes/devices).
You'll need to filter for files created on the 8th first to do what you want. Use find or grep to get the files that you want first and then run the count.
  #3 (permalink)  
Old 01-10-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
I have tried using find

find . -name FILE001*.* | grep -c ^
It gives an error can you please correct me.

How can we filter the files based on the created date?
  #4 (permalink)  
Old 01-10-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
If you know the date, and are running manually, you can just grep for the date:
ls -l | grep -c "Jan 8"

-Edit
Better:
find . -type f | xargs ls -l | grep -c "Jan 8"
To prevent descent into subdirectories, just search the site for non-recursive find or something like that
-/Edit

Last edited by blowtorch; 01-10-2007 at 07:38 PM..
  #5 (permalink)  
Old 01-11-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Maybe not your requirement, but a general solution to count number of files as per date:
Code:
$cat test1
#!/bin/ksh
ls -l | grep "^-" | awk '{
key=$6$7
freq[key]++
}
END {
for (date in freq)
        printf "%s\t%d\n", date, freq[date]
}'
Here is some sample input:
Code:
$ls -l | grep "^-"
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test.cpp
-rw-r--r--    1 admin    other             3 Aug 16 07:56 test.cpp.z
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test.txt
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test1.cpp
-rw-r--r--    1 admin    other             3 Aug 16 07:56 test1.cpp.z
Output:
Code:
$./test1
Aug16   2
Jul30   3
Regards,
Tayyab
  #6 (permalink)  
Old 01-11-2007
Krrishv Krrishv is offline
Registered User
  
 

Join Date: Dec 2006
Location: CA,United States
Posts: 186
checkout this

ls -ltr|grep "^-"|tr -s " "|grep -i 'jan 8'|cut -d " " -f7,8,10
  #7 (permalink)  
Old 01-11-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
Thank you very much It worked.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0