[HowTo] Use locate command and updatedb to search all partitions

Updatedb command by default does not include /media path for updating its database. You can change the settings in /etc/updatedb.conf so that it starts indexing other partitions too.

sudo gedit /etc/updatedb.conf

In the PRUNEPATHS setting, remove /media. Save the file and run

sudo updatedb

This will index all your files from /media folder. Make sure the partitions are mounted.

Cheers!

[HowTo] Suspend Ubuntu from terminal or keyboard shortcuts

When learning to make bash scripts, at one point or other you’d like to know how to suspend your computer from terminal. Well, there are quite some methods available for Ubuntu. You can choose whatever suits your needs. I prefer method 3 (look below).

Method 1:

sudo sh /etc/acpi/sleep.sh force

Method 2:

sudo pm-suspend

This command might not be available in older versions of Ubuntu. It works perfectly fine on Lucid and Maverick.

Method 3:

This command does not require sudo so it might come in handy. For example, you can map it to a keyboard shortcut for easy access.

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

One thing to notice here is none of the commands I mentioned here will ask your password on resuming. For that you’ll have to lock your computer before suspending. You’ll have to use gnome-screensaver-command –lock before suspending to lock the computer

Create a suspend script:

Open a new file in gedit:

sudo gedit /usr/bin/suspend-comp

Copy and paste the following code and save it:

#!/bin/sh 
sleep $1;
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

If you want the script to ask for a password on resuming, copy-paste this code instead:

#!/bin/sh 
sleep $1;
gnome-screensaver-command --lock
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Add the executable bit:

sudo chmod +x /usr/bin/suspend-comp

Now suspend-comp time-in-seconds can be used in terminal. For example, if I want to have my computer suspended after 20 seconds I can simply type:

suspend-comp 20

Mapping it to keyboard shortcut for easy access:

Go to System->Preferences->Keyboard Shortcuts. Click Add. Type Suspend for Name and suspend-comp 0 in Command field. Click Apply.

Now scroll to the bottom of the list to find Suspend. Click on ‘Disabled’ on the right to ‘Suspend’. Now press any key combination to map the command to it. I used Ctrl+Alt+Shift+s.

Now simply pressing Ctrl+Alt+Shift+s will suspend your computer.

Cheers!

[HowTo] Find number of files inside a folder in Linux

I wanted to find out the number of files inside a folder. I didn’t want the folders to be included in the result.
A blog post on zimbio.com shows us how to do it with ls command which is not only downright inaccurate, it is also slower than what I am going to show you.
I am going to show you how to do it using find command which is extremely powerful once you know how to use it.
Executing the command below will print the number of files (excluding folders) in current directory (including all subdirectories):

find ./ -type f | wc -l

This can be used to find number of directories too:

find ./ -type d | wc -l

You can do more complex counting for example finding out the number of files which are of filesize 1Mb and more.

find ./ -type f -size +1M | wc -l

Finding number of symlinks:

find ./ -type l | wc -l

You can also see number of files accessed within last 1 hour from current directory:

find ./ -type f -amin -60 | wc -l

Here -60 means less than 60 minutes ago.

Only imagination is the limit with what you can achieve using find command.

[HowTo] Open thumbs.db and extract thumbnails from it

Thumbs.db is a file used to store thumbnail data of a folder in Windows. It makes loading of thumbnails significantly faster, however it has some privacy issues. Like if you delete an image, its thumbnail might still be there in thumbs.db file which would allow you to view it.

There’s an open source python script called Vinetto available to extract all the thumbnails in open.db to a folder. It works on Linux, Windows and Mac OS. You can download the script from here.

On Ubuntu, you can use apt-get to install vinetto:

sudo apt-get install vinetto

To extract thumbnails:

vinetto -o ./thumbnails ./thumbs.db

This will extract all the thumbnails inside thumbs.db to thumbnails folder.

Cheers!

[SOLVED] Unable to find the Jasper image conversion program in Kopete

Kopete supports yahoo webcam and it works seamlessly. Although it doesn’t work right away after installing kopete. If you try to access anyone’s webcam you’ll get the following error.

Unable to find the Jasper image conversion program.
Jasper is required to render Yahoo webcam images.
Please see http://wiki.kde.org/tiki-index.php?page=Kopete%20Webcam%20Support
for further information.

You can fix it simply by installing jasper packages available in Ubuntu repositories:

sudo apt-get install jasper libjasper-java libjasper-runtime libjasper-dev libjasper1

You can now send and receive anyone’s webcam.

Cheers!

[HOWTO] Delete all unstarred emails from Inbox or Label in GMail

Its easy to delete all mails from a label/folder or inbox, but sometimes we’d like to save our starred mails and delete all the rest. The search box in gmail comes in handy in such situations. Its really a very powerful tool with various operators to make the search more efficient. The gmail search really gives it an edge over other free email applications.

I have subscribed to one of the yahoo groups and over time it has accumulated over 9000 mails. I quite frequently star the mails which I like. I wanted to delete the rest. To do that I just typed “label:techgroup -is:starred” without quotes in the search bar and clicked on Search. It displayed all the emails from that label which isn’t starred. Notice the hyphen, it means exclude.

Explanation

Its really simple and I doubt anyone would be needing this section.
label:techgroup means we want to display all the mails from label techgroup.
is:starred means we want to display all starred mails form the label.
But the – infront of is:starred negates what it does. It means we want to exclude starred items from the search results. So we get unstarred mails from label techgroup.

After making the search, click on the checkbox beside the ‘Archive’ button to select all the emails on that page. You’ll get another option just above the search result which would say:

All 20 conversations on this page are selected. Select all conversations that match this search

Click on ‘Select all conversations that match this search’. This will select all the matched results. Click on ‘Delete’ and empty the trash if you want.

Read more about the advanced search in gmail.

Cheers!

[HowTo] Enable or disable modules in Apache

You can enable or disable any apache module using a2enmod and a2dismod. You don’t need to edit the conf file for that unless you are having some problem with this method. The syntax of these commands is really simple:
To enable a module:

sudo a2enmod module_name

To disable a module:

sudo a2dismod module_name


For instance, to enable mod_expires, execute sudo a2enmod expires in the terminal. If you see the following output, you can be sure that it has been enabled.

[email protected]:~$ sudo a2enmod expires
Enabling module expires.
Run '/etc/init.d/apache2 restart' to activate new configuration!

To disable mod_expires:

sudo a2dismod expires

Restart the server after enabling the module.

sudo service apache2 restart

Or

sudo /etc/init.d/apache2 restart

PS: On linux systems, you can use auto-complete feature by pressing tab with a2enmod and a2dismod. It will show list of mods installed on your system.

Cheers!

[HowTo] Check your php and server information using phpinfo()

We can check the php configuration, apache’s loaded modules and all other kinds of PHP configuration using a simple function called phpinfo(). Create a file called infophp.php in your web’s root directory and put the following code in it:

<?
phpinfo();
?>

This would output all the php configuration info and apache information. You can pass on an argument to phpinfo() to limit what information is displayed. You can checkout the phpinfo documentation here.

PS: This is a beginner tutorial for absolute beginners.