Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.mac.misc > #374 > unrolled thread
| Started by | Robert Peirce <bob@peirce-family.com> |
|---|---|
| First post | 2011-06-12 12:54 -0400 |
| Last post | 2011-06-14 22:00 -0400 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.sys.mac.misc
touch for you BSD gurus Robert Peirce <bob@peirce-family.com> - 2011-06-12 12:54 -0400
Re: touch for you BSD gurus Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> - 2011-06-12 20:26 -0400
Re: touch for you BSD gurus Robert Peirce <bob@peirce-family.com> - 2011-06-13 07:57 -0400
Re: touch for you BSD gurus Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> - 2011-06-13 21:57 -0400
Re: touch for you BSD gurus Robert Peirce <bob@peirce-family.com> - 2011-06-14 22:00 -0400
| From | Robert Peirce <bob@peirce-family.com> |
|---|---|
| Date | 2011-06-12 12:54 -0400 |
| Subject | touch for you BSD gurus |
| Message-ID | <bob-F0B857.12544012062011@5ad64b5e.bb.sky.com> |
I have two backup systems for my photos. I try to keep them synchronized. I use tar to create a compressed file of any photos taken since a TS (time stamp) file. Then I touch TS to bring it to today. The problem is, depending on how good I am about adding photos to my library, some photos may already be older than the time stamp. One solution is to manually touch TS to make sure it is old enough. A better way would be if I could touch TS with a date, say, one month earlier. Obviously, I could create the appropriate date string and use "touch -t date TS," but I would really prefer to be able to just specify a negative increment. The man page doesn't indicate this as an option. Is there any way to do it?
[toc] | [next] | [standalone]
| From | Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> |
|---|---|
| Date | 2011-06-12 20:26 -0400 |
| Message-ID | <nospam.News.Bob-F405BF.20261212062011@news.eternal-september.org> |
| In reply to | #374 |
In article <bob-F0B857.12544012062011@5ad64b5e.bb.sky.com>,
Robert Peirce <bob@peirce-family.com> wrote:
> I have two backup systems for my photos. I try to keep them
> synchronized. I use tar to create a compressed file of any photos taken
> since a TS (time stamp) file. Then I touch TS to bring it to today.
>
> The problem is, depending on how good I am about adding photos to my
> library, some photos may already be older than the time stamp. One
> solution is to manually touch TS to make sure it is old enough. A
> better way would be if I could touch TS with a date, say, one month
> earlier.
>
> Obviously, I could create the appropriate date string and use "touch -t
> date TS," but I would really prefer to be able to just specify a
> negative increment. The man page doesn't indicate this as an option.
> Is there any way to do it?
You can do this with a little script
#!/usr/bin/env bash
typeset delta="$1"
shift
touch -t $(date -v ${delta} +%Y%m%d%H%M.%S) "$@"
Now give the file a name (mytouch) and make it executable
(chmod +x mytouch).
Using the "man date" -v option, you can specify a negative time
offset to the current time.
So if you want to back date the file by 1 month you would
mytouch -1m image1.jpg image2.jpg image3.jpg ....
What to move the time back a year
mytouch -1y image1.jpg image2.jpg image3.jpg ....
Just a couple of days
mytouch -7d image1.jpg image2.jpg image3.jpg ....
Want to move forward in time, change the minus to a plus :-)
The valid suffix values are "y, m, w, d, H, M or S", for year,
month, week, day, Hour, Minute, Second.
Have fun.
[toc] | [prev] | [next] | [standalone]
| From | Robert Peirce <bob@peirce-family.com> |
|---|---|
| Date | 2011-06-13 07:57 -0400 |
| Message-ID | <bob-A36DFD.07572913062011@5ad64b5e.bb.sky.com> |
| In reply to | #377 |
In article
<nospam.News.Bob-F405BF.20261212062011@news.eternal-september.org>,
Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> wrote:
> You can do this with a little script
>
> #!/usr/bin/env bash
> typeset delta="$1"
> shift
> touch -t $(date -v ${delta} +%Y%m%d%H%M.%S) "$@"
>
> Now give the file a name (mytouch) and make it executable
> (chmod +x mytouch).
I'm doing something like that.
I=`date -v+9m -v-1y "+%y%m%d"`
touch -t ${I}2359 TS
I was hoping there might be an arg I could give directly to touch.
I had to add 9 mos and subtract 1 year to have it handle year end
properly. For example, trying to go 3 months back from 2/11 resulted in
11/11 instead of 11/10.
[toc] | [prev] | [next] | [standalone]
| From | Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> |
|---|---|
| Date | 2011-06-13 21:57 -0400 |
| Message-ID | <nospam.News.Bob-8E77F7.21570213062011@news.eternal-september.org> |
| In reply to | #379 |
In article <bob-A36DFD.07572913062011@5ad64b5e.bb.sky.com>,
Robert Peirce <bob@peirce-family.com> wrote:
> In article
> <nospam.News.Bob-F405BF.20261212062011@news.eternal-september.org>,
> Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> wrote:
>
> > You can do this with a little script
> >
> > #!/usr/bin/env bash
> > typeset delta="$1"
> > shift
> > touch -t $(date -v ${delta} +%Y%m%d%H%M.%S) "$@"
> >
> > Now give the file a name (mytouch) and make it executable
> > (chmod +x mytouch).
>
> I'm doing something like that.
>
> I=`date -v+9m -v-1y "+%y%m%d"`
> touch -t ${I}2359 TS
>
> I was hoping there might be an arg I could give directly to touch.
not that I know of. But then again a simple script as I showed
above gives you your own mytouch command. That is the beauty of
Unix. The ability to combine simple commands into more complex
forms that suit your needs.
> I had to add 9 mos and subtract 1 year to have it handle year end
> properly. For example, trying to go 3 months back from 2/11 resulted in
> 11/11 instead of 11/10.
I do not have any problems using any number of months to go back
years. For example:
date -v -165d
Thu Dec 30 21:51:55 EST 2010
date -v -530d
Wed Dec 30 21:52:59 EST 2009
[toc] | [prev] | [next] | [standalone]
| From | Robert Peirce <bob@peirce-family.com> |
|---|---|
| Date | 2011-06-14 22:00 -0400 |
| Message-ID | <bob-E8AB43.22001814062011@5ad64b5e.bb.sky.com> |
| In reply to | #384 |
In article <nospam.News.Bob-8E77F7.21570213062011@news.eternal-september.org>, Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> wrote: > I do not have any problems using any number of months to go back > years. For example: > > date -v -165d > Thu Dec 30 21:51:55 EST 2010 > > date -v -530d > Wed Dec 30 21:52:59 EST 2009 You're right! I don't know why it didn't work right for me the first time. I just tried date -v -7m and got Sun Nov 14 21:57:46 EST 2010 I wonder if the formatting had anything to do with it.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.mac.misc
csiph-web