matt-helps

insight on all things techie

Ubuntu: Ctrl-C no longer works in terminal

The programmers behind gnome-terminal seem to have changed something to do with the way ctrl-c works. Now if you want to cancel a program that has the focus of the terminal and you hit ctrl-c then nothing will happen. That’s because the gnome terminal is trying to copy text to the clipboard - perhaps your gnome-terminal’s “copy to clipboard” command is set to ctrl-shift-c in which case you won’t notice this problem!

The gnome-terminal used to “copy to clipboard” only if you had text selected and would issue a ctrl-c (and abort/cancel) if you had none selected. Now it always attempts to “copy to clipboard” regardless of whether you have text selected or not. The only way around this right now is to go into your keyboard shortcuts (in the Edit menu) and set Edit | Copy to something other than ctrl-c, I suggest the original gnome-terminal default of shift-ctrl-c.

Shame, since ctrl-c is used everywhere else for copy!

Alternatively, some programs will also abort if you use ctrl-\ (that’s a backslash) and some with ctrl-d, other than that you’ll have to learn each program’s individual quit command (if they have one). For “top” it is q.

Hope that helps!

Facebook Easter Egg

Well I’m not sure what facebook are doing with this but if you follow the following commands you get a lens flare (a visual effect) on the screen:

1. Log into facebook
2. Click on the background (the white bit)
3. Press: up, up, down, down, left, right, left, right
4. Press: b, a, enter
5. Click on the screen

Thanks facebook - I guess their code monkeys have got time to kill !?

How to spend $4000 from the commandline!

I have used Amazon Elastic Cloud (EC2) for my dedicated hosting needs for nearly 6 months now. They’ve just released a new “bulk-buy” service that enables you to buy 1 or 3 years’ of as many instances as you want in advance. I’ve just bought 3 years of the smallest instance at $500 plus $0.03 per hour - saving just over half of my server costs over the course of the 3 years: $500 + (24*365.25*3*0.03) = $1288.94 for 3 years, verses the current cost of $0.1 per hour which is 24*365.25*3*0.1 = $2629.80 for 3 years. Both prices are ex-vat and don’t include bandwidth costs or storage costs, obviously, though those costs are themselves VERY competitive ($0.17/GB outgoing and $0.10/GB incoming). But as you can see it is a good deal for me to bulk buy in advance.

So how do you bulk buy? Amazon’s new service is called reserved instance and you bulk buy simply by typing in a command in your terminal or dos cmd prompt (ec2-purchase-reserved-instance-offering) and hey presto you’ve just bulk bought in advance. For me that was $500, but it is possible to buy the biggest instance they have for $4000! All just by issuing a single call from the commandline. That is such a scary prospect I went into my history and deleted it so that I wouldn’t accidentally call the command again by accident. Actually there was no need to delete it from my history as in order to buy a reservation you need to ask Amazon to “offer” you one (ec2-describe-reserved-instance-offering) and then use the offering id that they specify for the instance type & region you need. Once that offering id has been used it can’t be used again - but I wasn’t about to test that their code worked…

The way it works in terms of billing is that the running instance that fits the profile you’ve bought are discounted to the new rate (or as many instances that fit the reservation profile that you’ve bought anyway). You don’t need to restart any running instances and you don’t need to relaunch them in any particular way - it is really just something that is applied at billing time. Make sure you reserve the right type of instance in the right availability zone though - get that wrong and you’ve wasted a serious amount of money!

Anyway, yes, top range instance is $4000 for 3 years per instance plus $0.24 per hour per instance - so it is possible to spend $4000, plus VAT (or your country’s tax) from the commandline in one easy line! Ouch!

How to stop Spotify on Linux audio skipping

Spotify is a great application that lets you listen to any music they have (there’s an incredible amount on there) with the odd, almost unnoticable, advert thrown in to pay for the service. It works on windows or mac, but there is no native binaries for linux. Thankfully spotify for windows works under wine just fine - hooray.

However I found that the audio wasn’t great - for me it would skip like a CD skips every few seconds - if it was a CD I would just clean it and throw it in the bin. The reason for this behaviour is found in wine’s audio config - I won’t go into the real reason why, but it is to do with the driver and daemon, etc. Other people have had problems with distortion or just no audio at all.

The solution if you have this problem is to start all your wine commands with padsp and make sure the OSS audio driver is selected. First start winecfg like this:

padsp winecfg

Then go to Audio, find the OSS driver and select that (and unselect anything else selected), hit OK, etc.. Now start your wine apps (inc spotify) like this:

padsp wine "C:\Program Files\Spotify\spotify.exe"

And now my spotify is working just fine!

Recursive Find and Replace in Multiple Files

Just had to make a few changes to a website I own that means changing the same text in lots of files. Linux has lots of powerful tools to enable you to make this kind of change over lots of files over many directories very easily. The command is:

find . -type f | xargs sed -i 's/string1/string2/g'

This is basically two commands. Find will find a list of actual files (-type f, rather than symlinks or directories, etc) in this directory (.) - you could specify particular filenames by adding -iname “filename.ext” before the pipe (|).

Find outputs a list of relative filenames on each line. These are then piped (|) into xargs. xargs is a progam that runs the command that follows it (sed) once for each line of text that it receives, in this case from the pipe, it will run sed once for every filename it receives and place the filename at the end of the sed command.

The sed command is incredibly powerful and well worth learning how to use. sed stands for “Stream Editor” and edits a stream of text as instructed. xargs passes a filename for sed to operate on, then it makes a change inplace (-i), which means it changes the file rather than just outputting the change wherever you ask it to, and then carries out the actual command (’s/string1/string2/g’).

’s/string1/string2/g’ is in quotes to keep the scope clear, s is a command meaning substitute and the s command takes the form s/oldstring/newstring/ which means it finds the text oldstring (can be a regular expression) and replaces it with the newstring text. For each line it finds it carries it out as many times as it finds the oldstring because we’ve set the global option (g), without which it would just change the first instance of oldstring.

Hope someone finds that helpful!

How to temporarily disable the touchpad while typing

In linux if you have a laptop with a trackpad just below the keyboard sometimes you can be typing away and then suddenly you touch the trackpad/touchpad and find your cursor appears elsewhere so you have to stop typing and put the cursor back in the right place. Its a bit of a pain if you’re doing a fair bit of typing especially considering how sensitive these pads can be.

The easiest solution is to temporarily disable the touchpad automatically whenever you type for 1 second. This is easily achievable with the following command in terminal:

syndaemon -d -t -i 1

The number 1 means 1 second and can be adjusted to any integer.

Of course the best thing to do is to make it a task executed at start up so go into preferences | sessions and then add an entry there. The name and description can be anything you want and the command is the command above.

Faster internet connection with a local DNS cache

One of the things you can do to speed up browsing and general internet activity is to create a local DNS cache. A DNS is a Domain Name Server and its purpose is to convert domain names to IP addresses. Every time you type in a domain name your computer has to ask a DNS to convert it to an IP address. Occasionally a website’s IP address will change so you can’t store an IP address forever, but it is worth cacheing it locally, even just for 24 hours or so considering the number of times we hit some sites during the day.

In Ubuntu (and debian, and other flavours of linux, though this tutorial is written for ubuntu) we can install a little helper application to cache the DNS results for a time and thus speed up our internet experience in general! It is called dnsmasq and the first step is to install it:

sudo apt-get install dnsmasq

Then at the terminal we need to edit the config file:

gksudo gedit /etc/dnsmasq.conf

Then find the line that says “#listen-address” and remove the leading # (if there is one) and make it say:

listen-address=127.0.0.1

Save and exit. Now edit /etc/dhcp3/dhclient.conf:

gksudo gedit /etc/dhcp3/dhclient.conf

Edit the line that says “prepend domain-name-servers” to say:

prepend domain-name-servers 127.0.0.1;

or if you want to use OpenDNS.org’s DNS servers (which I recommend) then change that line to:

prepend domain-name-servers 127.0.0.1, 208.67.222.222, 208.67.220.220;

Now at this point if you were to get a new IP lease it would all work, but that’s a bit of hassle so lets make it work now without rebooting the hardware. Edit /etc/resolv.conf:

gksudo gedit /etc/resolv.conf

Insert the following line at the top of the nameserver list:

nameserver 127.0.0.1

Finally we need to restart our little utility to take into account the new settings:

sudo /etc/init.d/dnsmasq restart

Now it is time to test it! At the terminal type:

dig news.bbc.co.uk

…and take note of the query time. Then run the same command again and note the improvement. You should be looking at around 2ms for the 2nd time whereas the first one will be dependant upon your internet connection - for me it was about 50ms - so for me this makes the DNS query portion of browsing about 25 times quicker. Enjoy.

Using Alien to convert .rpm packages to lpia .deb

Alien is a nice little linux utility that converts .rpm software packages to .deb packages so that you can install software packaged for Red Hat on Debian and Ubuntu, etc.  Clever.  But for those of us on the lpia architecture (like the dell mini 9) we require those .deb files that Alien spits out to have their “architecture” setting to be lpia, not the i386. There is no way to change it from the command line so you’re left with a .deb package that either won’t install or can be forced to install but then won’t uninstall.  You could of course unpack, edit the control file and then repack the .deb file, but there is an easier way.

Install alien if you haven’t already:

sudo apt-get install alien

Then ask alien to generate the build tree without actually building the package itself:

alien -g filename.rpm

This creates a build tree that is turned into an lpia .deb package once we’ve made a change to the control file as before.   Edit debian/control using your favourite text editor and modify the line that specifies the architecture so that it now says:

Architecture: lpia

And then in the directory that contains the folder “debian” run:

debian/rules binary

That will create a .deb file which you can then install either through the usual GUI methods or by calling:

dpkg -i filename.deb

And of course because you’ve installed it using the right architecture you’re also able to uninstall it should you need to.  Hooray.

Three million hit by Windows worm

A worm that spreads through low security networks, memory sticks, and PCs without the latest security updates is posing a growing threat to users.

The malicious program, known as Conficker, Downadup, or Kido was first discovered in October 2008.

Although Microsoft released a patch, it has gone on to infect 3.5m machines.

via BBC NEWS | Technology | Three million hit by Windows worm.

Yet again we see windows requires updates to patch up their software with a million holes in it.  These are the ones we know about too.  According to the article this seems to be a clever bit of code.  First it hijacks services.exe then creates & allows a randomly named .dll to become a service and then sets up a webserver & downloads files to execute from any one of hundreds of sites whose name changes continually according to a preset algorithm.

Quite clever actually.  I guess I find the whole thing quite bemusing.  You buy a nice fast machine and then have to buy a slow operating system with holes in it to run it which you then have to go out and buy antivirus software to do something that the operating system should be doing anyway which makes your computer run like a 3-legged dog.  The only reason to have a windows partition is games & specialist software - most software has linux equivalents and even some games run under wine.

Still, if you’re going to pay a huge multi-national corporation lots of money to still produce trash after all these years and you still pay and install it then I guess you get what you deserve.

Trash rather than rm

One of the most powerful/dangerous commands in linux is the “rm” command.  It removes the file from the filesystem and whilst with some media formats it is possible to recover an rm’d file in ext3 it is almost impossible to get that file back (without a hexdumper and lots of time on your hands to manually re-link the file).

After doing a bit of work the other day but before my nightly backup had run I went into the directory I had been coding in and decided to get rid of the backup files that had been created.  The backup files were like the normal files except they had a tilda attached, ie, filename.txt~, so to delete all the backup files in one go I quickly typed in:

rm *~

Except that’s not what I typed.  I missed the tilde off the end and wiped all the files from that directory.  Oops.  Nightly backup not yet run.  Major Oops.  After chuckling that I do make backups a priority and I tell people to make backups a priority I hadn’t done it myself.  Too late.

I did get the files back because, thankfully,  my data store is an SDHC card formatted to vfat (windows) so only the FAT entry had been deleted - more on that in my next post.

But that left me wondering.  I rarely need all the power of rm - whenever I’m using it from the commandline I could think of virtually no circumstances where I would prefer to unlink the file altogether rather than just move it to the trash.  As I looked around the net I noticed lots of suggestions from people to replace rm altogether or to create an alias for rm that does something else, but the problem with that is that lots of programs rely on rm being the way it is and taking specific arguments, etc.  To change it just for me would probably break the system or applications that I have installed or could install at any time.

The solution I settled on was to stop using rm from the commandline altogether and learn to use an alias I created called “trash” whenever I wanted to delete a file from the commandline.  All you need to do to use it is to open your ~/.bashrc file and put the following line in it somewhere (at the end works just fine):

alias trash="mv -t ~/.local/share/Trash/files --backup=t --verbose"

Obviously if your trash is in a different location you need to change the location above - what I’ve written above is correct for Ubuntu.  Now when you “trash” a file it will go into your trash bin and is therefore retreivable rather than being deleted forever.

Such a simple script doesn’t work perfectly of course and if you delete a huge file on a removable local device you’ll notice that it will move the file to the trash bin on another device and that will take some time.  What I could do with now is to know the name of the trash folder on the device on which the file is located and send it there.

Hard drive destruction ‘crucial’

The only way to stop fraudsters stealing information from old computer hard drives is by destroying them completely, a study has found.

Computing magazine Which? recovered 22,000 “deleted” files from eight computers purchased on eBay.

Criminals source old computers from internet auction sites or in rubbish tips, to find users’ valuable details.

via BBC NEWS | Technology | Hard drive destruction ‘crucial’.

Actually you don’t quite need to go to that extreme, and I’m sure a  very determined tech thief could piece together the digital media from the smashed hard-drive.  No, more secure (and easier!) is to just run one of the many shredding utilities you can download out there - preferably one where you can specify to overwrite the original data with a given number of garbage writes (I remember 23 being the number of times you should go over the original data - though that was some time ago), and then you can go ahead and sell your computer/hard-drive on ebay.

Perhaps the best solution though is just to have your home folder encrypted (or profile directory in windows) .   Or even setup an entire volume to be encrypted.  You never know when you’re going to leave your laptop on the train or when someone is going to steal it from under your nose at Starbucks.  You also never know when someone is going to break into your house and walk away with your desktop tower.  Sure your home insurance will cover the equipment, but it won’t cover the cost of re-securing your identity.

Convert .deb package from i386 to lpia

These new fangled netbooks that run ubuntu such as the Dell Mini 9 are great. One problem, as mentioned in an earlier post on this blog (see Related Posts) is that when you download an application like skype or adobe flash player that isn’t in the repositories you get a .deb file for linux and when you try to install it the debian package manager will complain that there is an architecture mismatch because are attempting to install an i386 package on an lpia processor. You can use a commandline switch to force the install but you won’t be able to automatically uninstall it later.

As I mentioned in that previous post, you can just repackage the *_i386.deb file into a *_lpia.deb file manually, but now it is even easier than that as there is now a helper script to do it automatically thanks to the helpful guys on the ubuntu forums. Just unzip this i386 deb to lpia helper script file into the directory where you want to run it (or into your scripts directory), set it to executable and then run it from the directory with the *_i386.deb file. You don’t need to specify any parameters, but the deb package must end _i386.deb (rename it if you have to):

cd /path/to/my/i386/deb/file
wget http://www.matt-helps.com/pub/deb2lpia.sh.tar.gz
tar -xvzf deb2lpia.sh.tar.gz
rm deb2lpia.sh.tar.gz
chmod +x deb2lpia.sh
deb2lpia.sh

Hope that helps.

(updated for v1.1 of the script)

Website age ratings ‘an option’

Film-style age ratings could be applied to websites to protect children from harmful and offensive material, Culture Secretary Andy Burnham has said.

via BBC NEWS | UK | Website age ratings ‘an option’.

An interesting idea came out of the UK government this week, the idea of applying film-style age ratings to websites (here in the UK that is U=Universal, PG=Parental Guidence, 12=12 years old and older, 15=15 years old and higher and 18=18 years old and higher) as a means of protecting kids.  As a father of 2 small kids I can understand the desire to create a safer internet but I think they may be entirely misunderstanding how the net works as such a system for the whole net would be completely unworkable.

The internet is almost un-policable without cross-border cooperation between governments.  It is not known whether the internet was designed to be unpolicable or whether it just evolved as it has but data is stored and services are run on servers all over the world including in many countries that would not offer cooperation with the UK government.  Not only that but websites appear and disappear with almost disturbing speed - how do you regulate that?  What about websites that are full of safe stuff in one area, but have inappropriate content elsewhere on the same site.  What about user-posted content?  Not just pictures, but graphic text also?

No, the only way to get even close to what the government would like to do is to create a whitelist of websites that are safe for kids that have no user-posted content and are regularly policed.  A whitelist operates like a walled garden - you can roam around inside the garden but you can’t get out - you can visit any site on the whitelist, but no others.  Perhaps sites would apply to be part of this whitelist and volunteer themselves on there, but I can’t imagine that the take up would be at all high considering the punishment the government would dole out if something nasty slipped through their own censoring.

No, the only way for young kids to use the internet is to do so closely supervised.  And if my kids think they can have a computer in their own room before they’re 32 they’ve got another thing coming…

Site relaunch

You may have noticed but I’ve converted this site to a wordpress site, added a few features and removed a few too.  This is mainly because I’ve decided to focus matt-helps.com entirely on techie things (computers, programming, linux, internet, and techie stuff in the news) - mainly because these are the things I have the experience in but also because I think most of my subscribers probably aren’t interested in football or cars!  (Not that I’m that interested in the latter one either).

What you will find is that the RSS feed http://feedproxy.google.com/matt-helps now publishes the full text so that you don’t have to come to the website to read the whole article - we can do this now because we can put google ads into RSS feeds - hooray!

UK Police DNA Database is a “Breach of Human Rights”

Last week we had profoundly good news on the abuse of human rights in the UK that we call the police’s DNA database. The European Court of Human Rights has ruled unanimously that holding the DNA & fingerprint details of people that have no criminal record is a breach of their rights. The biometric data of about 4.5m people are held by the police in a national database and one in five of them does not have a current criminal record.

Personally I find this an affront to personal freedom - sure, if you’ve been convicted of a crime then you give up that freedom, but until that point our DNA & fingerprints must remain off the record.

The government maintains that DNA & fingerprint records are vital for catching criminals and state that 3500 matches are made each month. I do not dispute the value of such a database but I do dispute their statistics as they are not relevant - what proportion of those 3500 monthly matches are:

a) perpetrators of the crime, as opposed to innocent people using the same environment.

b) from the 1/5 of the database who have no criminal record - I bet it is not even 1/50th.

c) solving crimes that couldn’t be otherwise solved.

They also leave out the number of failed checks/tests they actually do each month to get 3500 matches. The statistics are worthless - they’re just a device designed to enable this government’s ideal of a police state. Yes, there will be some people that get away with crime because of this, but the end does not justify the means. Freedom and maintaining human rights does come at a very real cost, but it is one that we must pay: simply because a few people offend because they can get away with it does not mean that we should infringe everyone’s rights to privacy. If someone does get away with it they will most likely be caught the next time or the time after that - because typically people don’t just offend just once, and any DNA found in previous crime-scenes (of unknown origin) is stored for future cross-reference anyway - making this entire debate pointless.

The problem is that the police, like all public departments, are target driven and statistical goals always distort the vision & values of an organisation.

So I am thankful that the government’s infringement upon our freedom (in the name of our protection) has been halted on this front for now. Haven’t we seen this all before anyway? In the name of protection the Republic allows Senator Palpatine to create an army which then goes on to subjugate the galaxy into the new Emperor Palpatine’s empire…