Deleting folders beginning with a dash “-” on Linux

If you have a folder or file which starts with a dash (e.g. “-someFolder”) then simply running rmdir (or rm for a file) will produce the following error:

> rmdir -someFolder
rmdir: illegal option -- s
usage: rmdir [-p] directory ...

A neat way to delete such a folder is by referencing the directory first:

> rmdir ./-someFolder

The folder should now be deleted. Files are the exact same, just replace rmdir with rm.

Advertisements

Apt-get not finding packages

On a freshly installed Ubuntu system, apt-get may not have bothered to download its list of packages. This can lead to the confusing position of ‘E: Unable to locate package X‘ on almost everything. Fix this by entering:

sudo apt-get clean
sudo apt-get update

Packages should then be visible and installable via the usual command:

sudo apt-get install X

If you’re not sure on the package name, search for it using:

apt-cache search X

If you still cannot find the software you’re after you may of course need to add additional repositories.

Stopping favicon 404 spam in Apache error logs

Favicons display many elements of the dark, early days of the Internet. Typically a 16×16 pixel image in ICO format (wtf is that?), they were introduced back in 1999 with Internet Explorer 5. More recently mobile browsers have followed in this unholy tradition by introducing more favicon files, bringing the list of files needing to be created / handled to:

  • favicon.ico
  • apple-touch-icon-precomposed.png
  • apple-touch-icon.png

Whilst they do provide a nice little visual logo space for your website or company, you may sometimes think they aren’t worth the bother. One unexpected problem: An Apache error log full of 404 errors from web browsers trying to locate /favicon.ico, /apple-touch-icon-precomposed.png and /apple-touch-icon.png files in your website’s root directory.

A simple way to prevent this is to add the following code to your apache virtualhost configuration:

Redirect 404 /favicon.ico

<Location /favicon.ico>
    ErrorDocument 404 "favicon does not exist"
</Location>

Redirect 404 /apple-touch-icon-precomposed.png

<Location /apple-touch-icon-precomposed.png>
    ErrorDocument 404 "apple-touch-icon-precomposed does not exist"
</Location>

Redirect 404 /apple-touch-icon.png

<Location /apple-touch-icon.png>
    ErrorDocument 404 "apple-touch-icon does not exist"
</Location>

Whilst this solution seems the most technically correct, it still means your server is going to be hit with constant 404 requests for the non-existant files on every page and frame load, although thankfully they should no longer be clogging up error logs. A more pragmatic approach is to create 3 blank files, 1 in ICO format and 2 in PNG format, placing them in your website’s root public directory as favicon.ico, apple-touch-icon-precomposed.png and apple-touch-icon.png. A good tip is to set the Expires header to sometime in the distant future to avoid any further favicon requests.

You will also need to add the following code to your page:

<link rel="shortcut icon" href="#" />

Now finally you can live in peace from bombardment of favicon requests …until browser makers start adding new favicon types.