如何在上周获得bash sunos的日期

发布于 2025-02-13 16:38:55 字数 422 浏览 1 评论 0 原文

这是我的问题:我有一个备份bash脚本,需要访问带有日期名称的文件夹:backup_01072022。

我使用 date =`tz = gmt +24 date +%d%m%y` 当我需要访问昨天的备份文件夹时。

现在,我想访问上周的备份文件夹:

date =`tz = gmt +168日期 +%d%m%y` ,它不起作用,它显示了今天的日期。

我读到TZ不适合+144以上的值。

sunos 6.8 中,还有其他操纵日期吗?

注意:

sunos 6.8

版本的 date util:8.5

版本的bash:4.1.11(2)-Release

Here is my issue: I have a backup bash script that needs to access a folder with a date in its name for example : backup_01072022 .

I used date=`TZ=GMT+24 date +%d%m%Y` when i needed to access the backup folder of yesterday.

Now I want to access the backup folder of last week :

date=`TZ=GMT+168 date +%d%m%Y` , it doesn't work , it show today's date.

I read that TZ doesn't work for a value above +144.

Is there any other way of manipulating dates in SunOS 6.8 ?

Notes :

SunOS 6.8

version of the date util : 8.5

version of bash : 4.1.11(2)-release

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梓梦 2025-02-20 16:38:57

这将取决于系统上 date 的版本。

使用 GNU日期(V 8.26):

$ TZ=GMT date '+%d%m%Y'
06072022                        # today

$ TZ=GMT date '+%d%m%Y' -d 'last week'
29062022

$ TZ=GMT date '+%d%m%Y' -d '7 days ago'
29062022

注意:我将其保留为OP,以确定是否应调整显式 tz 设置(或根本使用)

This'll depend on the version of date on your system.

With GNU date (v 8.26):

$ TZ=GMT date '+%d%m%Y'
06072022                        # today

$ TZ=GMT date '+%d%m%Y' -d 'last week'
29062022

$ TZ=GMT date '+%d%m%Y' -d '7 days ago'
29062022

NOTE: I'll leave it up to OP to determine if the explicit TZ setting should be adjusted (or used at all)

禾厶谷欠 2025-02-20 16:38:57

我似乎还记得Sunos随附Perl,因此,如果您没有支持 date - date =“ ...” ,您应该能够做:

date=$(perl -MPOSIX -e '
    print POSIX::strftime "%d%m%Y", localtime time-(60*60*24*7)
')

I seem to recall SunOS comes with Perl, so if you don't have a date that supports --date="...", you should be able to do:

date=$(perl -MPOSIX -e '
    print POSIX::strftime "%d%m%Y", localtime time-(60*60*24*7)
')
2025-02-20 16:38:57

多亏了有用的委托和答案,我能够使用它来实现它的工作:

/usr/gnu/bin/date -d "last week" '+%d%m%Y'

事实证明,我没有使用 gnu date util,直到我明确指定它,而这既不是 - date nor -d 为我工作。
如果不是 gnu日期,我仍然无法弄清楚我默认使用的util日期。

Thanks to the helpful commments and answers I was able to make it work using :

/usr/gnu/bin/date -d "last week" '+%d%m%Y'

It turns out I was not using the GNU date util until I specified it explicitly, and that's neither --date nor -d was working for me.
I still can't figure out what date util I was using by default if not GNU date.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文