jump to navigation

Clean Up Old Thumbnails February 15, 2006

Posted by Carthik in administration, commands, maintenance, snippets, ubuntu.

The nautilus file manager shows you thumbnails of images, pdf files etc when you are browsing your directories. But you already know that. Nautilus also saves a copy of the thumbnails for later, to speed things up. The thumbnails are stored in your ~/.thumbnails directory. Over time, thumbnails keep accumulating, since, even if you delete a file (an image, say), the thumbnail remains. Cleaning this up might save you some space. It saved me about 650MB!

I found this neat command that you can execute to find and delete thumbnails that have not been accessed in the last 7 days. Deleting a thumbnail should not affect anything much, since if Nautilus cannot find a thumbnail, it will just create one anew.

$find ~/.thumbnails -type f -atime +7 -exec rm {} \;

You can put that code in your cron if you like, to have it run every month or so.

Turn on Bash Smart Completion January 28, 2006

Posted by Carthik in administration, commands, snippets, ubuntu.

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents

If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now 🙂

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.

Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!

To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:

#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion

Now you can use tab completion to power your way through commands.

You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

How to use your Linux Machine as an Alarm January 22, 2006

Posted by Carthik in commands, guides, snippets, ubuntu.

You probably leave your computer on all the time. (Linux users keep it up longer, right?)
So instead of wasting more electricity by using an alarm clock to wake you up, why not put your desktop to work as a personal alarm? Like the Task Scheduler in Windows computers, it is really, really simple to have your Linux system do things at specified times in the future. This article will guide you through the process of using your desktop as a musical alarm.

Note: If you prefer player X and I use player Y in the examples below, you can easily substitute X for Y.

Use Kalarm:

Kalarm is the KDE alarm tool, which can, besides paying sounds, display a text file, or execute commands at specific times in the future. Even if you are an Ubuntu user (Gnome) you still can install and use kalarm. The name of the package to install is, unsurprisingly, “kalarm”!

Use the Xmms-Alarm plugin:

Xmms is the famous winamp-lookalike minimal music player for Linux. Install the package “xmms-alarm” and then you can use Xmms as an alarm. Downside: you will have to keep xmms running all night. No biggie? Alright then, you are all set. Click on the image above to see how to get to the point where you can set the preferences. (Right click on the Xmms window and Choose Options->Preferences->General Plugins)

Using Xmms and “at”:

Start XMMS and start playing songs. Adjust the volume to what you want to wake up to.

Push the stop button, then type:
$echo xmms -p | at 7:00

The “at” command line utility will make sure xmms starts playing at 7 AM the next day to wake you up.

Read $man at to find out more about “at”, which can do just about anything “at” a particular time.

Use “sleep” and “at” :

$sleep 8h && xmms /path/to/mp3file.mp3

This will open the mp3file.mp3 file with xmms after exactly 8 hours.

Use cron, mplayer, and a few other usual suspects:

More details at The Cron-Mp3 alarm clock writeup.

So , pick your poison potion!!!

Finally, if music doesn’t wake you up, the following sure will:
$sleep 8h && cat /dev/urandom > /dev/dsp

Thanks to all the ubuntu-users subscribers for writing in great suggestion, a few months ago.

Booting in to the command prompt January 22, 2006

Posted by Carthik in commands, snippets, ubuntu.

Recently, I switched to using multiple monitors at work. At home, however, I have only the laptop screen. I did not want the GUI login (GDM/KDM) to come up on boot. I wanted to be able to change the xorg.conf file before starting X, depending on whether I was at home or at work.

I found a reversible way to disable booting into the graphical display.

To disable graphical login (to log into the command prompt) do:

$echo "false" | sudo tee /etc/X11/default-display-manager

The next time you reboot, you will find yourself staring at the command prompt.

To enable it again, do:

$echo "/usr/bin/gdm" | sudo tee /etc/X11/default-display-manager
Note: replace gdm in the above with kdm if you use kde’s display manager, or xdm, if, for some reason you use that.

Hat tip to Peter Garrett on the ubuntu-users list.

Rescue Data from Failing Partition January 21, 2006

Posted by Carthik in administration, applications, commands, guides, ubuntu.

If you have a hard disk drive, or a drive partition that is failing, or if you want to copy data from one partition to another (don’t we all, at some time or the other?), then ddrescue comes to the rescue!
In case parts of the partition you are trying to rescue data from are corrupt, then ddrescue (unlike dd) skips over it and gets out all the data that is uncorrupted!

Install ddrescue using
$sudo apt-get install ddrescue

Make sure you have a partition with more disk space that the entire partition you are trying to retrieve data from. Yes, that includes occupied AND free space on the partition you are trying to retrieve data from.

Rescue data using:
$dd_rescue /dev/hda1 /some/dir/drive-backup.img
Where you might have to replace /dev/hda1 with the partition you are trying to rescue data from, and /some/dir/ should have more free space than the entire /dev/hda1 partition.

This creates a drive image. You can mount it as a loop device. Do the following to do just that:

sudo touch /dev/loop1
sudo losetup /dev/loop1 /some/dir/drive-backup.img
–If you get an ioctl error, run “$sudo modprobe loop”, and run the prior command again
sudo mount -t ext3 /dev/loop1 /media/drive-backup
(replace ext3 with the filesystem type of your old partition)

Now you can browse /dev/loop1 and copy out all your data. If you use an external USB drive to backup the image to, you can take the image with you 🙂

Thanks are due to Dan Martin who posted this at the ubuntu-users mailing list a few weeks ago.

List only the directories October 19, 2005

Posted by Carthik in commands, snippets, ubuntu.

I had a trivial problem today where I had a huge list of files in a directory, and other directories within the directory. I was looking for a specific directory and wanted to get the files out of the way. I wanted a listing of the directories within the current directory and nothing more. Luckily, with a little experimentation I was able to figure out how to do this :

$ ls -l | grep “^d”


Watch outputs as they change October 10, 2005

Posted by Carthik in commands, snippets, ubuntu.

This is another “trick” that might seem trivial to the gurus out there, but is something I discovered recently.

Use the command watch to regularly update and refresh the output of some command. If you want to see the “running output” then watch is the program for you.

Using it is simple, by default it updates the output once every two seconds. So
$watch “your-command”

will update the output of “your-command” every two seconds.

To make it refresh more frequently, try
$watch -n1 “your-command”

and to make it highlight differences as and when they occur, try the -d option.

As an example, the command
$watch -d -n1 “netstat -t tcp”
will show you a list of the IP connections heading out from your computer, and update the output every second. It will also highlight new items/changes as they happen.

Another little gem from teh ubuntu-users mailing list archives!

Memory, Swap Management October 7, 2005

Posted by Carthik in commands, ubuntu.

A lot of Linux newbies, myself included are often astonished at the amount (%) of memory used by Linux as opposed to, say, Windows on comparable systems. If you look at the System Monitor (Applications -> System Tools -> System Monitor), you can find the amount of memory used by your system. If you leave your computer on for a long period (say more than a day) then the memory usage seems to keep going up. This is a “good thing”. Let me explain why.

Linux actively uses free available memory to improve your system’s performance. Let’s say you have 1 GB of main memory (don’t we all wish!). Now, suppose all the programs you are running together require only 200 MB of memory. What happens to the other 800 MB of the available memory?

On a linux system, the memory is used to “cache” data that is used by the CPU. The idea behind caching is that it takes longer for your CPU to access data on the hard drive than it does to access data that is present in the main memory. So caching using the main memory effectively speeds up the system. On a windows system, there is no such optimization, so free memory is wasted as it does not get used.

Now when an application really needs all the memory that is used for caching, Linux pops out the cached data and makes the required memory available. As a last option, if all of the main memory is used up, then the memory you set aside in your swap partition is used too.

Try the command:
$free -m

to see what your memory usage is. The first line of results is fairly obvious. The second line tells you what the applications “see”, and should tell you how much memory is actually being used by the applications themselves.

Another used command is “top” which gives you a look at the memory/cpu usage and other details about the processes that are running on your computer – all at the terminal. I much prefer it to the GUI-based System Monitor myself.

Knowing that all the memory I paid for is being used to the max makes me feel all warm and fuzzy. For a moment earlier today, I thought there was something wrong, since almost all of my memory was being used, and I was hardly running anything intensive – now I am at ease – there was something wrong earlier, when the memory was not being used by Windows – now I know!!

Better Management of Packages while Uninstalling September 30, 2005

Posted by Carthik in administration, applications, commands, ubuntu.

Have you ever noticed how, when you install a required package using apt-get or synaptic, and lot of associated “required” packages such as library packages and documentation packages are also installed due to the dependencies between packages? There are some “meta-packages” like kubuntu-desktop, for example, which in and of themselves do not install any files on your system, but have a long list of dependencies, which, together assume a cetain function. I installed kubuntu-desktop to try KDE, and later removed it, and was surprised to see that all the dependencies that were installed we not removed! That is where this story began.

What I don’t like is that when I later remove the package I installed earlier, the packages that were installed because they were dpendencies don’t get removed. So, when I installed the package, 30 MB was used, say. Now after unistalling the package, only 5 MB is freed, since the other 25 MB was used up by the dependencies. Over a period of time, this leads to a number of “orphaned” packages remaining on your system. The package or application that used this package has long-since been removed, but apt “ignored” removing these dependency packages.

Now I like my system lean, and more importantly, clean. I use debfoster to keep my system clean over a longish period of time.

Debian uses the main programs apt and dpkg to manage packages. These programs do not make a distinction between packages that got installed because some other program happened to need it and packages you really asked for. Debfoster will help you get rid of packages (libraries for example) get left behind on your system when the program that required it was removed or upgraded to a version that doesn’t have the dependency.

In the above, what is said of Debian is also true of Ubuntu.

Install debfoster, read it’s man page, and take it out on a ride by running it. The first time, it will ask you a few questions. Later, periodically running it will keep your system clean of aliened packages that are no longer needed. If you make a mistake with the answers, you can always edit the file /var/lib/debfosterkeepers which defines the packages you want to remain on your system.

An alternative to debfoster is aptitude (instead of apt-get) but the catch is that one has to always use aptitude instead of apt-get from the very beginning, and if you like me, realized the orphaned packages problem late, then aptitude won’t work.

Of course, I should add that besides occupying some space on your hard drive, and a few extra installed applications, the extra orphaned packages cause no harm.

List of last few edited files September 21, 2005

Posted by Carthik in commands, ubuntu.

Ever edited quite a few files, and started wondering what files you edited recently? Happened to me quite a few times. I search on google to find the file to edit to accomplish some purpose, edit it, save it, and get on with my work. Later, I find I want to edit it again, and can’t remember the files I edited last. To not repeat this in the future, let me make a note for myself:
$find -mtime 0

will list the last ‘n’ files edited.

$find -mtime 0 | more
will page the results.