Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-19-2012
Registered User
 
Join Date: Apr 2012
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Bug current date modified file

Hi ,

In my directory , i have many days file but i want to see all those which are of todays date.
i tried this but it gives all the files

Code:
mtime -0 |ls -ltr

I tried the below option as well.


Code:
19635   find -iname "*.LOG" -mtime
19636   ls -ltr *.LOG -mtime -1
19637   ls -ltr *.LOG mtime -0

nothing worked.

Can you suggest me how to list all the current days file and want to move them current day file to new directory

Last edited by Scott; 07-19-2012 at 07:39 AM.. Reason: Code tags...
Sponsored Links
    #2  
Old 07-19-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,649
Thanks: 164
Thanked 642 Times in 619 Posts
I assume you mean a calendar day, starting at midnight.
The format for the date in the touch command is YYYYMMDDHHMI; the date command format string gives you midnight when run any time during the day

Code:
 cd /log/directory
 # be sure to make the new day's directory before all this below
 touch -t `date +%Y%m%d0000` dummy
 find . -newer dummy -type f  |
 while read fname
 do
     mv $fname [new directory name goes here]    
 done

Sponsored Links
    #3  
Old 07-19-2012
Registered User
 
Join Date: Apr 2012
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ,

Many thanks it is working. I need few clarification here , what does touch -t is doing here. scripts looks like can be run any day and it will bring the data for current day. can it be modied according to the need let say once in month if i want to move all the file for yesterday or may be 3 days back one. how can we amend here in this file.

Much appreciated.

Thanks

Rajesh
    #4  
Old 07-19-2012
Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 6
Thanked 0 Times in 0 Posts
touch modifies the file's timestamp.
Look here

UNIX man pages : touch ()
Sponsored Links
    #5  
Old 07-19-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
Please post what Operating System and version you have. Do you have the GNU date command?

There is a FAQ on dates here:
http://www.unix.com/answers-frequent...rithmetic.html
Sponsored Links
    #6  
Old 07-19-2012
Registered User
 
Join Date: Apr 2012
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
HI ,

My os is sun solaris 10 64 bit.
Sponsored Links
    #7  
Old 07-19-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
We guess that you don't have the GNU date command, therefore please refer to the FAQ for date arithmetic.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete a row from a file if one column containing a date is greater than the current system date chumsky UNIX for Dummies Questions & Answers 4 07-06-2011 02:07 AM
Test if a file has a last modified date of within the last 24 hours rethink Shell Programming and Scripting 2 03-17-2011 05:04 AM
Finding the modified date time of a file JamesJoe UNIX for Advanced & Expert Users 2 01-30-2011 02:27 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
How do I get the last modified date of a file? akpopa UNIX for Dummies Questions & Answers 2 08-29-2001 03:08 PM



All times are GMT -4. The time now is 12:33 AM.