Useful commands #3: Deleting files with special characters in their filenames

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Ever been stuck with a weird file you wanted to delete? You know, those lock files with special characters in their filenames left all over your Samba shares by some Windows applications (for instance)? Today’s post will help you get rid of them in a snap.

First of all, make sure your current directory is the one where your annoying file is located:

cd directory_containing_weird_file

 
Next, list directory’s content using the –inode option:

ls -i

 
You should now see a listing with a number at the beginning of each line. This number corresponds to the unique inode ID of each file and we’ll use it as identifier for the deletion, instead of our bizarre filename. Just do:

find . -inum inode_ID_of_your_file -exec rm -i {} \;

 
The recalcitrant IS wiped out for good this time!

That’s all Folks!


For further reading, you can take a look at ls and rm man pages which detail some other interesting options.

Advertisements

Useful commands #2: Removing old kernels

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

In a recent post, I explained how important it is to keep your operating system up to date. If you followed my advices, you may have noticed that Ubuntu’s package manager does not delete any old kernel when upgrading to a new one. It’s on purpose, just to have a known good kernel around in case the upgrade fails. While this is a rather reassuring behavior, you could also want to get rid of these old kernels (to free up some space on your hard disk for example). Let’s see how.

Before doing any cleaning, first write down your current kernel release. You’ll find it by running:

uname -r

 
Next, simulate the old kernels removal:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get --dry-run remove

 
Here, the –dry-run parameter allows to see the events that would occur during real removal but no change is actually done to the system. Check all the informations displayed on screen to make sure there was no error and verify that your current kernel release was not listed anywhere.

If everything looks fine, you can run the command for real:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

 
Old kernels are history now.

That’s all Folks!


For further reading, see the Ubuntu wiki to understand why this removal is not so easy to automate.

Useful commands #1: Preventing the update of a package

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Doing frequent updates of your favorite OS and programs is always recommended. Not only does it allow you to take advantage of new features but it also minimizes the security risks by correcting the possible flaws spotted since the installation or the previous update.

In Ubuntu, software updates can be either automatic (see Automatic Updates in the official documentation for details) or… manual. If you choose to go the manual way, you’ll have to make sure to do the updates by yourself on a regular basis (Ubuntu’s welcome screen advises you of updates availability) using two commands:

sudo apt-get update

 
first, to re-synchronize the package index files from their sources (the repositories are listed in /etc/apt/sources.list), followed by:

sudo apt-get upgrade

 
to finally install the newest versions of all packages currently installed on the system.

This full update in one shot is very handy of course, but what to do if you don’t want to update a specific package? For instance, let say you patched and rebuilt a program for whatever reason and you don’t want it to be replaced by the new latest official version. What to do? This is where today’s useful command comes in:

sudo apt-mark hold package_name

 
Now, this package will never be updated automatically as well as manually as long as it is on “hold” status. To display this status, you can use:

dpkg --get-selections | grep "package_name"

 
Finally, the day you decide to allow the upgrade to the latest version available in the official repository, just type:

sudo apt-mark unhold package_name

 
to put the package back on “install” status.

That’s all Folks!


For further reading, take a look at Package Management in Ubuntu’s official documentation.

Ubuntu Server system administration made easier: Webmin

Leave a comment

Successfully tested on Ubuntu Server 10.04 LTS 64-bit

Tired of being a command-line master? You would like to do Ubuntu Server administration tasks using some kind of GUI? DO NOT install Ubuntu’s desktop environment. Install Webmin instead.

The easiest way to install Webmin on Ubuntu is by using the official Webmin APT repository. First, create a new /etc/apt/sources.list.d/webmin.list file containing the following lines:

## Webmin repository
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

 
Next, get the repository GPG key

wget http://www.webmin.com/jcameron-key.asc

 
and add it to your trusted keys list:

apt-key add jcameron-key.asc

 
Finally, resynchronize the list of available packages

apt-get update

 
and install Webmin:

apt-get install webmin

 
Now, you should be able to login to Webmin at https://webmin_server_hostname:10000 using any existing sudoer account and discover the many possibilities of this wonderful tool.

That’s all Folks!


For further reading, see Webmin website.