Essential Linux Cleanup

In today’s abundance of storage space, you usually needn’t worry about such things no longer, but it still might be worth having in mind (for image dumps, etc):

(1) APT Cache

Depending on how often you use it, you may find more than 5GB of cache stored in your file system.
$ sudo apt-get clean

(2) Unused Linux Kernel headers

From this post:
$ dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
$ sudo update-grub # if you need to update it

(3) Orphan packages

For this, you need a package called deborphan.
$ sudo apt-get remove --purge `deborphan`

(4) Browser Cache

Well, this will depend on your browser. For Firefox or Chrome, see this.

As an alternative to manual stuff like the above, you can also check the BleachBit.

Encrypting and Decrypting with gEdit

This is more a note-to-self on something that I caught myself doing over and over and over (decrypting a file into a temporary file, editing it, encrypting it back and removing the temporare file).

After some checking and this article (my post is also there for the sake of helping out)

I found that it is fairly easy to do so from gEdit…


You will only need:

  • gedit
  • gedit plugin – External tools (enabled)
  • a valid gpg key

(I am using no passphrase here but if you need one, you can hard coded it there or use other scripts to prompt the passphrase input for you).


Just go to Tools > Manage External Tools, and add the scritps:


Paste the following code on a new command, called “Encrypt”:

if [ ! "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then 
    echo "$stdin" | gpg -a -e -r --no-tty -
    echo "$stdin"

with the options:

  • ShortCut – Control + Shift + E
  • Save – Nothing
  • Input – Current document
  • Output – Replace current document
  • Applicability – All documents / All languages

Should be something like this:



Paste the following code on a new command, called “Decrypt”:

if [ "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then 
    echo "$stdin" | gpg -d --no-tty - 2> /dev/null
    echo "$stdin"

with the options:

  • ShortCut – Control + Shift + D
  • Save – Nothing
  • Input – Current document
  • Output – Replace current document
  • Applicability – All documents / All languages

Should be something like this:


In action

Once that is done, then you can open encrypted files (asc – ascii files, not binary), or create new ones on spot…





Ubuntu: Google Chrome or Chromium Browser

After spending time on this, I am moving back to Google Chrome. I was hoping that apt-get updates would be a nice one to keep (since Google’s official repository is crappy right now).

I reckon Google has its own update tool, and additional features such as embedded PDF reader (ok, you can hack the chromium-browser (with plugins) it to make it work as well)… but the official Google version comes with all Google stuff ready, and some additions I find handy. So, I am handling this with:

# download the package (unstable, replace this if you want the stable version)
# Install the package
sudo dpkg -i google-chrome-unstable_current_amd64.deb
# fix missing desktop icon
sudo ln -s /opt/google/chrome/google-chrome.desktop /usr/share/applications/google-chrome.desktop


PHP Documentation

Simple installation and usage of phpdoc:

Install dependencies and phpdoc

# install dependencies
$ sudo apt-get -y install php-pear php5-xsl graphviz
# install phpdoc
$ sudo pear channel-discover
$ sudo pear install phpdoc/phpDocumentor-alpha
# run phpdoc
$ phpdoc --target ./docs --directory ./ --title 'PHP Documentation'

And that’s it!


[Linux] Running Multiple Skype instances

Recently I have been using Skype for corporate communication, and one thing that happens quite often is the fact you do not want to mess your personal and work stuff.

Luckily, on Linux (and Windows, I presume), you can easily  run multiple instances (accounts) of Skype.

Here is how I do it:

1) Create a script to run the second (or N instances) of Skype:

create a file on an executable $PATH (such as /usr/local/bin/skype-username)

echo username password | skype --pipelogin -- secondary

Usually it is a good approach to set this file to permissions 0700, if you want to leave the password hard-coded like the above. Handy, but you have the security trade-offs to think about. And replace the username/password with your own credentials (note the file has also executable permissions, and if you don’t need the credentials, just use 0755).

sudo chmod 700 /usr/local/bin/skype-username

2) Create the desktop Icon

Save a file named: /usr/share/applications/skype-username.desktop

[Desktop Entry]
Name=Skype Username
Comment=Skype Internet Telephony (for Username)
Exec=skype-username %U

I basically use the desktop icon for Synapse, but you could just create on your desktop as well (or on Unity, if using Ubuntu).


For more advanced usage of Skype, I recommend looking at system commands you can type in:

MySQL WorkBench on Ubuntu 12.10

Is this never gonna end? :S

I wrote some time ago about dependency issues with MySQL Workbench here, and here I am again. This time, I was just upgrading the latest version in my Ubuntu 12.10, and got another dependency issue, with version 5.2.47.

# get and install missing/unmet dependency
sudo dpkg -i libctemplate0_1.0-1_amd64.deb
# get and install MySQL WorkBench
sudo dpkg -i mysql-workbench-gpl-5.2.47-1ubu1204-amd64.deb

That’s it!

Logcat in colors from command-line

After days and days looking at these logs, I finally came to reason, and decided to put some colors on it. I found some people already doing this:

But neither of them support new logcat formats (specially the time output, which I use a lot). So I built my own (quick work, really). Here it is:

Rework from 37Signals

Just read the book Rework (… can’t say I agree with everything, but definitely it defies the status-quo, and puts things to perspective. Sometimes we just get used to do things, oblivious of their reason, and such reading pushes you to question them all over again. Maybe worth reading (the interesting lines) every now and then to keep mind fresh!


Some of the quotes I liked from the book:

[…] Unless you’re a fortune-teller, long-term business planning is a fantasy.

[…] Plans let past drive the future.

[…] Workaholics aren’t heroes. They don’t save the day, they just use it up. The real hero is already home because she figured out a faster way to get things done.

[…] If you constantly fret about timing things perfectly, they’ll never happen.

[…] Details make the difference. But getting infatuated with details too early leads to disagreement, meetings, and delays.

[…] If you start pushing back deadlines and increasing your budget, you’ll never stop.

[…] Let’s say your challenge is to get a bird’s-eye view. One way to do it is to climb the Mount Everest. That’s the ambitious solution. But then again, you could take an elevator to the top of a tall building. That’s a judo solution.

[…] The right time to hire is when there’s more work than you can handle for a sustained period of time.

[…] Hire managers of one.

[…] Hire great writers. […] Clear writing is a sign of clear thinking.

[…] When everything constantly needs approval, you create a culture of nonthinkers,

[…] You don’t need more hours; you need better hours.

[…] Write to be read, don’t write just to write.

The Augustine Test

While studying Corporate Governance, I heard about the Augustine Test, a simple question based framework to help evaluating the ethics of decision making. The questions here are somewhat “adjusted” to present times (considering Augustine lived in 350s), but I found them quite interesting:

  • Is it legal?
  • If someone else did it to me, would I think it was fair?
  • Would I be OK if it appeared on the front page of the local paper?
  • Would I like my mother to know I did it?


[Bash] timing scripts

If you are in the need to check how long a script takes, most people will just suggest time command, and that’s good enough in many cases.

But if you need to print out different elapsed times within a script, or even a simple overall elapsed time in a more human readable way (I often do this for email reports, etc), I reckon this is a very good approach:

# In your script, define when the timer starts
start_timer=$(date +%s.%N)
# do whatever
# print in seconds
echo "This script took [`echo "$(date +%s.%N) - $start_timer" | bc \
     | awk '{printf "%.2f\n", $0}'`] seconds to complete."
# print in milliseconds
echo "This script took [`echo "($(date +%s.%N) - $start_timer)*1000" | bc \
     | awk '{printf "%.2f\n", $0}'`] milliseconds to complete."

Note that the awk command is there just to cut off the decimal digits (by default, is 9 digits for nanosecond precision). Tweak that as needed.

This will produce an output like:

This script took [12.01] seconds to complete.