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

Simple video editing in Ubuntu

I have been using Ubuntu as my main OS for the past year, but have often relied on my old MacBook for doing various things that I haven’t easily figured out how to do in Linux. One of those things is to trim video files non-destructively. This is quite simple to do in QuickTime, although Apple now forces you to save the file with a QuickTime container (.mov) even though there is still only MPEG-4 compression in the file (h.264).

There are numerous linux video editors available, but most of these offer way too many features and hence the need to re-compress the files. But I have found two solutions that work well.

The first one, ffmpeg, should be obvious, although I hadn’t thought that it could also do trimming. However, I often like GUI software, and I have found that Avidemux can do what I need very easily. Just open a file, add start and stop markers for the section to be trimmed, and click save. As opposed to QuickTime, it also allows for saving directly to MPEG-4 files (.mp4) without recoding the file.

There was only one thing that I had to look up, and that was the need for starting the trim section on a keyframe in the video. This is quite obvious when wanting to avoid re-encoding the file, but unfortunately Avidemux doesn’t help in explaining this but only gives an error message. The trick was to use the >> arrows to jump to the next keyframe, and then the file saved nicely.

Boot problems Ubuntu 10.04

Just as I started to believe that Ubuntu had matured to become a super-stable and grandma-friendly OS, I got an unexpected black screen on boot of Ubuntu 10.04 on a Dell Latitude D400. After some googling I have found a solution that works:

On boot, hit the `e’ button when the grub menu shows up. Then add the following after “quiet splash”: i915.modeset=1

If this works and you get into the system, you can do this procedure to change the grub loader permanently:

  • sudo gedit /etc/default/grub
  • Find this line: GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” and replace with: GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash i915.modeset=1”
  • Finally do a sudo update-grub to re-generate the grub menu

I hope this can help save an hour or two for other people encountering the same problem.

Triple boot on MacBook

I am back at work after a long vacation, and one of the first things I started doing this year was to reinstall several of my computers. There is nothing like a fresh start once in a while, with the added benefits of some extra hard disk space (not reinstalling all those programs I never use anyway) and performance benefits (incredible how fast a newly installed computer boots up!).

I have been testing Ubuntu on an Asus eee for a while, and have been impressed by how easy it was to install and use. I have been a Unix/linux users for years at the university, but have given up every time I tried to install it on any of my personal computers. Ubuntu is the first distro that actually managed to install without any problems, and which also managed to detect most of the hardware by itself, at least enough to actually work on the system.

Before I started the process on installing Ubuntu on my MacBook aluminum, I had heard rumors about it being a non-straightforward process, but it turned out to be very simple. I used bootcamp to install Windows XP (remember to format the drive using the windows installer, otherwise it won’t boot up…). To my surprise the new Ubuntu 8.10 installer made it possible to install Ubuntu from within Windows, and without needing to repartition anything. Quite a lot of things are autodetected, and there is a community page that suggests how to fix the rest. The built in audio support is not impressive, but an external sound card will hopefully work fine.

I didn’t find any good recommendations for how much hard drive space I should allocate for XP and Ubuntu, and what type of partitions to use. Previously I have had a 20GB NTSF XP partition, and that seemed sufficient, although I couldn’t read and write to the drive from OSX (apparently there are some software solutions for this). To be more flexible in my tri-OS-life, I decided to go for a 32GB FAT32 partition, of which I set aside 15GB for Ubuntu. After all necessary software is installed, mainly Max/MSP on XP and various Linux audio applications on Ubuntu, there are a 3-4 GB available on each system. This should be sufficient as long as I am mainly going to use the two OSes for occasional software testing.