Terminal or shell command to shutdown or reboot Ubuntu Linux

So how do you shutdown or reboot Ubuntu Linux from a terminal or a shell prompt? If GUI is working you can always click on a Quit button. If GUI is not working or if you are working remotely over ssh type the following command:

To shutdown / poweroff Ubuntu Linux
Type the command:
sudo halt
OR
sudo shutdown -h now

To reboot Ubuntu Linux
Type the command:
sudo reboot

More information can be found about these two commands by typing following commands (man page):
man reboot
man shutdown

how to get the size of a folder in Linux CLI

It seems like a simple request…and it mostly is. But if you want to get the size of a folder – including sub-folders – in Linux from the command line, you need to use the du command. The simplest trick (thanks linuxforums.org) to get the total size without listing all the sub-folders is to use the following:

du -h | grep -v ‘/’ | awk ‘{print $1}’

Mounting a Drive On Linux System

This post is meant to be a simple walk-through on how to mount a new drive on your Linux System.

Here we will take a scenario of mounting a new drive ?backup to store backup of your system..

***WARNING*** ***WARNING*** ***WARNING***

” What ever you do make sure to NOT use the command “fdisk /dev/sda” or “fdisk /dev/hda” as that means you are editing your main and boot partition ”

So let us begin..

Quote:

First run fdisk to look at your available disks.

# fdisk -l

Disk /dev/hda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 268 2048287+ 82 Linux swap
/dev/hda3 269 9726 75971385 83 Linux

Disk /dev/hdc: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

What we see above is two separate disks, one being hda and the other is hdc. The hda is the main boot drive which should not be played with !

Quote:

The second step is to format the drive. ( If the drive is hdb, hdd, sdb, sdc, sdd simply replace it with “hdc” )

#fdisk /dev/hdc

-press “n” for new partion
-press “p” for primary partition
-press “1″ for the first partition
-press enter for the first AND last cylinders. This will make it automatically use the entire disk
-press “w” for write out to save what you have done

The next step is to make the file-system readable by Linux. You need to format it using ext3 which is widely used file-system .

#mkfs.ext3 /dev/hdc1

Note that I have used “hdc1″ because it is the first partition. Now we are going to set the disk to automatically be mounted on boot as /backup.

Quote:

#mkdir /backup

#vi /etc/fstab

Add the following line:
/dev/hdc1 /backup ext3 defaults 1 1

Verify if this new drive is mounted.

#mount /backup