Thursday·25·November·2010
Useful but Unknown Unix Commandline Options: touch -d //at 20:42 //by abe
You may wonder how I manage to write one “Useful but Unknown Unix Something” blog posting per day. Well, I don’t. I write them in bursts, but don’t want to flood Planet Debian and Planet Symlink with more than one such posting a day.
The first bunch of postings were mostly slides (or part of a slide plus what I tell while showing the slide) from my Unknown but Useful Unix Tools talk and written somewhen last week. And this blog posting and yesterday’s blog posting were written in a row, too.
What does that have to do with Unix commandline tools? Well I use Blosxom as blogging engine and it’s based on simple text files lounging around in some directories, and the last modification time stamp is the posting’s date – which is cached after first time seen by the entries_index plugin so that I can fix typos without resetting the posting’s release date. Postings with a modification date in the future won’t be shown before that time.
So how do you set the last modification date to a date in the future? With “touch” from GNU Coreutils of course. Like “date”, “touch” also knows the option “-d” to explicity set a date and time instead of using the current date and time.
Now in my humble opinion the cool feature is that you can easily describe dates by giving touch values like “now + 1 hour”, “12:00 tomorrow” or so:
$ touch bla $ ls -l total 0 -rw-r--r-- 1 abe abe 0 2010-11-23 22:59 bla $ touch -d 'now + 1 day + 23 hours - 42 minutes' bla $ ls -l total 0 -rw-r--r-- 1 abe abe 0 2010-11-25 21:17 bla $
To see all the possibilities you have to describe relative dates with “touch”, “date”, and maybe other GNU Coreutils tools, check that you have “info” installed and call:
$ info '(coreutils.info.gz)Relative items in date strings'
Oh, and this whole story about setting modification dates manually to arbitrary values also means that the “Tattletale Statistics: Blogtimes November 2010” image in my blog’s side bar is absolute nonsense, at least this month. Well, never trust any statistic you haven’t faked yourself. ;-)
But on the other hand, the dates in the example may give a hint when I really wrote that blog posting. Or not. ;-)
And I wonder what my backup tools think about last modification times
in the future. Well, they probably only check for modification dates
newer than last backup and therefore should be fine. *phew*
Tagged as: Blogging, Blosxom, date, dates, GNU Coreutils, Myon, Statistics, touch, UUUCO, UUUT
// show without comments // write a comment
Related stories
Useful but Unknown Unix Tools: cut //at 15:55 //by abe
Just recently someone asked on #debian.de how to extract the 3rd to 8th character out of some string. That reminded me that the GNU Coreutils tool “cut” is also quite unknown.
The solution to his problem is:
$ echo Hurzlipuh | cut -c3-8 rzlipu
My favourite usage of “cut” is to restrict the output of programs which can’t do that themselves to 80 columns (common terminal width):
$ dpkg -l | grep -i macro | cut -c-80 ii docbook-to-man 1:2.0.0-28 ii latex-cjk-common 4.8.2+git20090105-5 ii m4 1.4.14-3 ii mp4h 1.3.1-5 rc swfdec-gnome 2.28.0-1
cut can cut out columns based on characters (-c), bytes (-b), fields (-f) delimited by tab (or the delimiter given by -d).
After many comments: Yes, “dpkg -l” is capable of restricting and even
fitting its output to the number of available columns if $COLUMNS is
passed as environment variable. (And $COLUMNS is set by default in the
shell, but not exported as environment variable as it may
change on terminal resize or WINCH signal.)
Tagged as: #debian.de, cut, GNU Coreutils, UUUT
// show without comments // write a comment