Monday, March 28, 2011

Using 'du' command to leave out other filesystems

Jaya Srila Prabhupada.

du -hsx /home

this command leaves out other filesystems that may have been mounted in the filesystem heirarchy starting at /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.

Backing up home folder

Jaya Srila Prabhupada

cp -vrx /home /home/ghd/mnt-backup

Because we use the -x option, this command doesn't copy contents from other filesystems that may have been mounted in the filesystem heirarchy starting from /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.

Thursday, March 17, 2011

Conditional Expression in C

Jaya Srila Prabhupada



A conditional expression is of the form:
expression ? expression_true : expression_false

Yes, the conditional expression involves the ternary operator!

Jaya Sri Sathguru Sridhara Swamy Maharaj.

Wednesday, March 16, 2011

Sorting the output from 'ls' command when filenames have numbers

Jai Srila Prabhupada.

Many times filenames contain numbers of arbitrary length - file1, file2, ..., file9, file10, file11, ..., file19, file20, file21, ... so on. When we run the 'ls' command, the output is sorted based on dictionary order and not in the way shown above.

Use the following command:
ls | sort -V

Note that we are calling 'ls' without any arguments, otherwise it won't work.

Jaya Sathguru Bhagawan Sri Sridhara Swamy Maharaja.

Friday, March 4, 2011

Why some Linux distros install to extended partitions



Jaya Srila Prabhupada

Some Linux distros including openSUSE create an extended partition on the hard disk before installing the OS on to it. Also the partition numbering starts from 5 and not from the next available number. For example, if I have one partition on the hard disk namely sda1 and I am installing openSUSE on it, the latter creates an extended partition sda2 and logical partitions starting from sda5 (sda5, sda6, and so on). One may wonder why the logical partitions didn't start from sda3.

The reason is extra convenience that one gets when one needs to add a partition. For example, if another (primary) partition is added to the disk described above, the new partition will be numbered as sda2 and the extended partition that was previously numbered as sda2 becomes sda3. However, and this is the important point, none of the logical partitions need to be renumbered; they still start from sda5. Thus no changes need to be made to the boot loader (e.g. GRUB) and fstab entries in the installation.

Jaya Sathguru Bhagawan Sridhara swami maharaj.