-n days ago - Unix
This is a discussion on -n days ago - Unix ; Hi,
I need to go e.g. 30 days back in time, and then archive files from
that day.
For example - today it's 2006/12/18. How can I go back to 2006/11/18?
What I need is just variables - date +%Y%m%d ...
-
-n days ago
Hi,
I need to go e.g. 30 days back in time, and then archive files from
that day.
For example - today it's 2006/12/18. How can I go back to 2006/11/18?
What I need is just variables - date +%Y%m%d - just -n days ago. I
don't have GNU date.
Running Sun 5.8.
Thanks.
-
Re: -n days ago
find is capable of locating files created/modified n days ago (or more
than/less than n if you use +/-)
find /somedir -mtime 30 -print
"thomasriise" wrote in message
news:1166446578.052590.313110@79g2000cws.googlegro ups.com...
> Hi,
>
> I need to go e.g. 30 days back in time, and then archive files from
> that day.
>
> For example - today it's 2006/12/18. How can I go back to 2006/11/18?
>
> What I need is just variables - date +%Y%m%d - just -n days ago. I
> don't have GNU date.
>
> Running Sun 5.8.
>
> Thanks.
>
-
Re: -n days ago
thomasriise wrote:
>Hi,
>
>I need to go e.g. 30 days back in time, and then archive files from
>that day.
>
>For example - today it's 2006/12/18. How can I go back to 2006/11/18?
>
find / -mtime -30 > /tmp/archive_files
tar cvTf /tmp/archive_files archive.tar
The first line creates a listing of the files to be backed up that have
been modified within the last 30 days.
The second line creates the archive (using Gnu tar) based on that file.
try "man find" for other ways of doing things like this but the above
method is what I use.
Adjust accordingly.
Good luck,
Steve
-
Re: -n days ago
Hi, and thanks for your answer.
Yes, I know the find and the m/atime command - but what I actually want
to is to go to my logdir 30 days ago.
Today I can e.g. make variables
date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I
do the same 30 days ago?
-
Re: -n days ago
On Tue, 19 Dec 2006 01:22:39 -0800, thomasriise wrote:
> Hi, and thanks for your answer.
>
> Yes, I know the find and the m/atime command - but what I actually want to
> is to go to my logdir 30 days ago.
>
> Today I can e.g. make variables
> date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I do
> the same 30 days ago?
I don't have a Solaris system to check its date command, but on my AIX
boxes I can manipulate the 'TZ' environment variable to slew the date
output:
$ date
Tue Dec 19 13:19:47 CUT 2006
$ TZ=240 date
Sat Dec 9 13:19:53 2006
--
George Baltz N3GB
Computer Sciences Corp Rule of thumb: ANYthing offered
@NOAA/NESDIS/IPD by unsolicited email is a hoax,
Suitland, MD 20746 ripoff, scam or outright fraud.
-
Re: -n days ago
thomasriise wrote:
>
> Today I can e.g. make variables
> date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I
> do the same 30 days ago?
I remember a non-Solaris system having a date command that could
take relative expressions like "30 days ago" on their command line.
Sounds like it's time to download some GNU versions ...
-
Re: -n days ago
Doug Freyburger wrote:
> thomasriise wrote:
>>
>> Today I can e.g. make variables
>> date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I
>> do the same 30 days ago?
>
> I remember a non-Solaris system having a date command that could
> take relative expressions like "30 days ago" on their command line.
> Sounds like it's time to download some GNU versions ...
date -j -v -30d will do it on FreeBSD...
But the SunOS 5.8 man page for date doesn't show it having that
capability.
Incidentally, http://www.freebsd.org/cgi/man.cgi is kind of neat for
checking man pages across many kinds of Unix systems.
--
Warren Block * Rapid City, South Dakota * USA
-
Re: -n days ago
* thomasriise :
> What I need is just variables - date +%Y%m%d - just -n days ago. I
> don't have GNU date.
perl -e '($d,$m,$y)=(localtime(time-30*24*60*60))[3,4,5];printf"%04d%02d%02d",$y+1900,$m+1,$d'
might give a off-by-one result around midnight when DST change occured
in the last 30 days.
-
Re: -n days ago
> perl -e '($d,$m,$y)=(localtime(time-30*24*60*60))[3,4,5];printf"%04d%02d%02d",$y+1900,$m+1,$d'
- Thanks andrew, your one-liner worked like a charm! In the meantime, I
wrote this little perl util:
---------------------------------------------
#!/usr/bin/perl
#
#simulate gnu "date --date '1 day ago'
#
#
use Time::Local;
my ($ctime) = time;
$ctime -= 30*24*60*60;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
localtime($ctime);
printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
---------------------------------------------
-
Re: -n days ago
"thomasriise" wrote in message
news:1166612502.164229.240680@t46g2000cwa.googlegr oups.com...
>> perl -e
>> '($d,$m,$y)=(localtime(time-30*24*60*60))[3,4,5];printf"%04d%02d%02d",$y+1900,$m+1,$d'
>
> - Thanks andrew, your one-liner worked like a charm! In the meantime, I
> wrote this little perl util:
>
> ---------------------------------------------
> #!/usr/bin/perl
> #
> #simulate gnu "date --date '1 day ago'
> #
> #
> use Time::Local;
> my ($ctime) = time;
> $ctime -= 30*24*60*60;
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
> localtime($ctime);
> printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
> ---------------------------------------------
Much easier to do
#!/usr/bin/perl
use POSIX 'strftime';
print strftime "%Y%m%d\n", localtime(time - 24*60*60);
--
Posted via a free Usenet account from http://www.teranews.com