Using BBEdit to `touch` files

46 views
Skip to first unread message

@lbutlr

unread,
Mar 21, 2020, 1:59:16 AM3/21/20
to BBEdit Talk
This might be useful to someone even though it is only tangentially related to BBEdit. I spent quite a bit of time (let’s not talk about the hours I spent trying to subtract 86,400 seconds from the current date in seconds repeatedly. I did get it working, but egads!) juggling bad ideas before I came up with this solution.

I do quite a bit in the BBEdit shell worksheets and I often need to do is touch files to update the date stamp and I have a situation where I have several hundred files that I need to date stamp with today’s date, yesterdays date, etc back for 3 years.

The file names are in the form “nn?n? Name of the file”

1 name of file 1
2 name of file 2
...
99 name of file 99
100 name of file 100

And I need to execute a touch command along the lines of:

touch -t 202004200000 "1 name of file 1"
touch -t 202004190000 "2 name of file 2"
...
touch -t 201912220000 "99 name of file 99"
touch -t 201912210000 "100 name of file 100”

This is the solution I came up with, finally. It does require that you install dateutils on your Mac to get gdate (brew install dateutils)

touch -t `/usr/local/bin/gdate --date='today - 99 days' +'%Y%m%d0000’` "99 name of file 99”

It is trivial to replace the 99 with the index number of the file. If the file doesn’t have an index number, you can use Text => Add/Remove Line Numbers.

Hope this comes in handy for someone.


--
'How come you know all that stuff?' 'I ain't just a pretty face.'
'You aren't even a pretty face, Gaspode.’


Rod Buchanan

unread,
Mar 21, 2020, 10:51:01 AM3/21/20
to bbe...@googlegroups.com

I think the existing date command could have also given you what you want:

date -j -v -99d +"%Y%m%d0000"
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/D02D2F1F-9A58-4C00-8B98-EAABF5B3692E%40kreme.com.

--
Rod

@lbutlr

unread,
Mar 21, 2020, 5:11:41 PM3/21/20
to BBEdit Talk
On 21 Mar 2020, at 06:24, Rod Buchanan <li...@sofstats.com> wrote:
> date -j -v -99d +"%Y%m%d0000”

That’s interesting, I’ve never seen that syntax for the date command.

It’s less readable, but doesn't require gdate to be installed.


--
Advance and attack! Attack and destroy! Destroy and rejoice!


Rod Buchanan

unread,
Mar 21, 2020, 7:51:07 PM3/21/20
to 'Duane Murphy' via BBEdit Talk

My guess it is from macOS' BSD heritage. Definitely not what I'm used to on our Linux boxes, or what I remember (been a while) on AIX.
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/EF52148A-0383-47C2-9AFD-0E95DE32F7FD%40kreme.com.

--
Rod



--
Rod

GP

unread,
Mar 22, 2020, 5:03:04 PM3/22/20
to BBEdit Talk
If you look at the documentation for Linux, Open Systems POSIX, MacOS, and FreeBSD versions of date, you'll find the MacOS and FreeBSD are pretty much exact duplicates.  What differences there may be look to be just differences between software versions.

Linux and POSIX look to be the same "slim" version of date. While the MacOS version should be able to execute a POSIX compliant date command, that version has quite a bit of added on bells and whistles.
Reply all
Reply to author
Forward
0 new messages