Add date to files in Ubuntu

Even though I have been running Ubuntu as my main OS for more than a year now, I am still trying to figure out a good workflow. One thing I have been missing from my former OSX setup was the ability to quickly and easily prepend the date to a number of files. Having moved my files between many different OSes, hard drives, network drives, etc. over many years, I know that the files’ creation dates will break at some point. For that reason, I prefer to prepend the date to filenames of photos, random text files, etc. That way I am able to quickly search through the files easily.

On OSX I have made a small Automator script called add-date that does exactly this: prepends a file’s creation date to the filename. It has worked like a charm for many years, and still works, so feel free to try it out if you are on OSX.

In Ubuntu there are, of course, numerous terminal based methods to do something like this. But I haven’t really been that eager to mess around with mv, rename and regexp just to rename a bunch of files once in a while. In the quietness of the Norwegian summer I finally got around to look a little more into how to do this in Ubuntu, and it turned out to be very easy. Nautilus, the file manager on Ubuntu, actually sports the ability to run scripts from the GUI. The scripts, of any programming flavor (python, perl, etc.) just need to be put in the folder:

 ~/.local/share/nautilus/scripts

There are many examples of adding today’s date to the files, such as this python example, but it took a little while to figure out how to do it using the modification date of the file. I finally got this to work as a little bash script:

#!/bin/sh
for f in "$@"; do mv "$f" "$(date -d@$(stat --printf='%Y' "$f") +%Y-%m-%d)-$f"; done

Save this as a file in the scripts folder, make it executable (chmod a+x), and restart nautilus. Then I can easily add the date to all files I want directly from the GUI.

Screenshot from 2015-08-03 21:53:02

Why open file formats matter

Cleaning up on my hard drive, I came across a couple of .wks (MS Works spreadsheet) documents from 1994-95. I don’t really need to get at the contents of these files right now, but I think it could be useful to be able to open them at some point. So I tried to see if I could open them with any of the office programs I have on my computer (MS Office, Numbers, OpenOffice, NeoOffice).

MS Works used to be a quite widespread office suite that came with a lot of machines back in those days, and it is actually still in sale. Therefore you would imagine that MS programs should be able to open files from previous versions. Strangely enough, I discovered that MS spreadsheet flagship Excel can’t open the old MS Works files.

I haven’t tried the Windows version of Excel yet, but if that doesn’t work I guess I have to start up an old computer that may have MS Works installed (or pay for some conversion program). Yet another reason for working with open file formats.