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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Traversing thru dirs and deleting files based on date ravi2082 Shell Programming and Scripting 5 07-18-2007 04:28 PM
Count of files based on date? sbasetty Shell Programming and Scripting 6 01-11-2007 03:02 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 Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-18-2008
psiva_arul's Avatar
psiva_arul psiva_arul is offline
Registered User
  
 

Join Date: Jul 2007
Location: Bangalore, India
Posts: 97
How to listout the files based on group by the date...?

Hi,

How to listout the files based on group by of date...?

suppose if have list of 10 files which was created by on today(Apr 18) and yesterday(Apr 17 ) in my personal directory like this

if i issue ls -rtl | grep "Apr 18" list out the file which was created/updated only on Apr 18th.

Actual files listing
=============

-rwxrwxrwx 1 geae users 278 Apr 17 06:07 sendmail.ksh
-rw-rw-r-- 1 geae users 15 Apr 17 06:26 P.txt
-rw-rw-r-- 1 geae users 375 Apr 17 07:12 simple.ksh
-rwxrwxrwx 1 geae users 375 Apr 17 10:04 dates.ksh
-rwxrwxrwx 1 geae users 555 Apr 18 01:12 IN.txt
-rwxrwxrwx 1 geae users 400 Apr 18 01:13 date_convert.ksh
-rw-rw-r-- 1 geae users 562 Apr 18 01:13 Updt_IN.txt
-rw-rw-r-- 1 geae users 590 Apr 18 02:43 Dir_File.txt
-rwxrwxrwx 1 geae users 1667 Apr 18 02:45 noofdir.ksh
-rw-rw-r-- 1 geae users 301 Apr 18 03:00 date.txt


Now i want to list out the based on the date and count the no of files basded on the date like this

Expected list of output
=================
[UDate: Apr 17 => No of Files:4[/U]
-rwxrwxrwx 1 geae users 278 Apr 17 06:07 sendmail.ksh
-rw-rw-r-- 1 geae users 15 Apr 17 06:26 P.txt
-rw-rw-r-- 1 geae users 375 Apr 17 07:12 simple.ksh
-rwxrwxrwx 1 geae users 375 Apr 17 10:04 dates.ksh

Apr 18 => No of files: 6
-rwxrwxrwx 1 geae users 555 Apr 18 01:12 IN.txt
-rwxrwxrwx 1 geae users 400 Apr 18 01:13 date_convert.ksh
-rw-rw-r-- 1 geae users 562 Apr 18 01:13 Updt_IN.txt
-rw-rw-r-- 1 geae users 590 Apr 18 02:43 Dir_File.txt
-rwxrwxrwx 1 geae users 1667 Apr 18 02:45 noofdir.ksh
-rw-rw-r-- 1 geae users 301 Apr 18 03:00 date.txt


So, How can list out the files based on the date?

Thanks and Regards,
Siva. P
Bangalore
  #2 (permalink)  
Old 04-18-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Script

This works for me:
Code:
ls -ltr | tail +2 > tempfile
token=`head -1 tempfile`
count=1
while read line
do
 dt=`echo $line | awk '{print $6" "$7}'`
 if [ "$dt" != "$token" ]
 then
  echo "$dt => No of files: $count"
  token=$dt
  count=1
 else
  count=`expr $count + 1`
 fi
done<tempfile
  #3 (permalink)  
Old 04-21-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
One liner

Code:
ls -ltr | tail +2 | awk '{print $6" "$7}' | uniq -c
  #4 (permalink)  
Old 04-21-2008
psiva_arul's Avatar
psiva_arul psiva_arul is offline
Registered User
  
 

Join Date: Jul 2007
Location: Bangalore, India
Posts: 97
list out the file group by date wise

Hi Krishnamath,

Thanks for your response, your command has retruning correct values but it retruend wrong output for some dates which is in single value date(Dec 5)

i have checked with some ordinary command

ls -rtl | grep "Dec 5" -- it won;t work why because we need to give 5 blank space in between month and date if the value of the date is single digit
instead of that we can use ls -rtl | grep "Dec 5" (its working)

how can we avoid the problem.

we should have to use the double blank spaces if the date of value is single digit.


Thanks and Regards,
Siva.P
Bangalore
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 06:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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