Test if a file exists

Another really useful linux command is test, which can be used to test if a file exists and then rename it.

Here’s an example:

$ test -f test.txt && mv test.txt test.txt.`date +%Y%m%d-%H%M%S`

This first tests if the file test.txt exists. If it does, it renames the file test.txt.YYYMMDD-HHMMSS (appropriate date/time stamp). Great for scripts that are working with a log file and need to rename it before starting a new log.

Linux Date/Timestamp

I often find myself needing to append a date (and sometimes a time stamp) to files. 

The following will generate the current date in the format YYYYMMDD which is the most suitable for sorting files.

$ date +%Y%m%d

Example output is “20120528” or Year = 2012, Month=05 (May) and day = 28.

Similarly the following will output the current time in the format HH24MMSS (24 hour time)

$date +%H%M%S

Example output is “193347” or Hour = 19, Minute = 33 and second = 47 (19:33.47). 

The two can be combined:

$date +%Y%m%d-%H%M%S

Example output is 20120528-193347. Note the separation of the date and time with a dash.

You can use these commands in your shell scripts. For example, this will create an empty test file called “Test.txt.20120528-193347”:

$ touch Test.txt.`date +%Y%m%d-%H%M%S`

As you can see, quite handy for organising files.

iPhone Launch Bar Apps

An interesting commentary on how I use my iPhone. I’ve actually removed the “Phone” and “Message” apps form the 4 app iPhone launch bar at the bottom of the screen, and replaced them with the Gmail and Wunderlist. Turns out, I actually don’t use the “Phone” or “Message” apps as much as these so, why have them there? Obviously Safari remains, so you can see how my iPhone is less of a “phone” and more of a personal information device.

Note for the observant, I’ll let you guess what the 4th app might be (it is a system app – i.e. not downloaded and it’s not Music or App Store).

Alternative To?

If you are looking for software, a great site to start is at Alternative To. There are a few ways to go about searching on the site. One way, if you already know of a similar product is to search for it, then look at the alternative matches (which you can then filter by license and platform).

The other option if you don’t have anything in mind is to simply browse by platform and license across all software. You can use the most likes/views to see what’s being used.

A very handy site and a comprehensive database.

Excess Data Usage Charges

As you may know, most Telco’s have additional charges for mobile data usage. Some of these Telcos (yes I’m looking at you Telstra), have decided that the web page to tell you how much data you’ve used doesn’t have to be all that accurate. Sure it’s a couple days behind but that never hurt anyone …

I’m sorry, but if you filled up at a fuel station where the bowser kinda “guessed” how much fuel you put in your car, and you only found out you were $10 over when you went to pay, you’d be royally pissed right?

Sure, the Telcos will argue about the difficultly of keeping data usage information up to the minute. That’s fine, but if they truly can’t measure data usage that accurately (funny the accounting department doesn’t have any trouble), then how about giving us all some grace –

Dear Sir/Madam, we aren’t really sure how much data you’ve used, and you only went over in the last few days of the quota period so we won’t charge you for it.

Of course, its clear why they do this. It is very difficult to use 100% of your quota without going over. That way they save on bandwidth for every single customer, while still getting full payment based on 100% usage. Very sneaky.


The Other Steve

You know, Steve Wozniak, aka the guy that invented the Apple Computer and helped start the personal computer revolution? 

He has a very interesting autobiography entitled iWoz. Well worth a read (or listen). There are two sides to every story 🙂

Apache Virtualhost Entries Work After a Graceful Restart

Turns out that you can apply virtual host changes in Apache config (httpd.conf) with a graceful apache restart, rather than a full restart which forcibly kicks (which means kicking users off your web server).

Here’s how to do a graceful change:

  • Change the httpd.conf file accordingly
  • Check your config with sudo service httpd configtest (make sure you get syntax OK)
  • Issue sudo service httpd graceful (most Linux variants)

Note quite a few other Apache changes take effect with a graceful restart. Well worth trying this first, before resorting to a full restart.