Sunday, 16 September 2012

How to mount a Pen Drive manually in Linux?

Most of you must be thinking that why do we need to mount a pen drive or any other external Hard Drive manually. Why cant' we just plug in the drive and let Linux do things for us, i.e. formatting (creating a file system on drive) and then mounting it inside the root file system.
The answer is, we can always let Linux automatically mount the drive for us. Infact, in my version of Linux, as soon as I plug in the drive, it is mounted at /media/Pendrive, supposing that my pendrive name is Pendrive.
But sometimes, we do not want automatic mounting. Infact, we want to mount our external hard drive or pendrive at a specified location for things to work. This is the scenario where we need manual mounting of a drive.
Let's see how to mount a drive manually.
If your drive is mounted automatically on plugging in then dismount the drive from the location on which it is mounted by using the command.
umount /media/Pendrive # supposing pendrive is mounted on /media/Pendrive
umount /dev/sdb1 # supposing the name Linux gave to my device is sdb1
You can also give the device name for dismounting if you know, or you can check it by using the command dmesg
Look for an SCSI device with storage capacity as that of your drive ( name would be like sda1,sda2...., sdb1,sdb2...)
Make the directory where you want to mount the drive. Let's say I want to mount the drive at /Folder
Mount the drive using the following command
mount -t ext2 /dev/sdb1 /Folder
Now the drive is mounted at /Folder. Here, ext2 denotes the file system for the drive.
Again, if you want that that your drive should be automatically mounted at the specified location when the system boots up and should be dismounted when the system shuts down, add the following line in /etc/fstab.
/dev/sdb1 /Folder ext2 defaults 0 0
The file systems in /etc/fstab are automatically mounted during system start up and dismounted during system shutdown.
You can always mount all the file systems in fstab using mount -a

For more info visit

Sunday, 9 September 2012

{ } and ( ), two different ways of grouping commands in shell script.

There are two different ways of grouping commands in unix shell script.
i) ( ) : When we group commands inside ( ), the commands are executed in the subshell, instead of current shell.
ii) { } : When we group commands inside { }, the commands are executed in the current shell.
Let's understand it with the help of an example. In this example, we will try to change the working directory of a shell and verify whether it has been changed or not.
Open shell and type the following command. Assuming that shell's pwd before executing the below command is /
$ { cd /etc/mail ; pwd ; }
The output will be
/etc/mail
This cd command was run on the current shell. If you want to verify, execute pwd again and you will see the same output
$ pwd
/etc/mail
Now, we will execute the same set of commands using ( ). Again assuming that pwd is /etc/mail
$ ( cd .. ; pwd )
The output will be
/etc
This cd command was run on the subshell. If you want to verify, execute pwd and you will see the output
$ pwd
/etc/mail
We can see that pwd of the current shell has not changed.
Note: Always use ; before } if { and } appears on the same line. This is not needed in case of ( ).
For more info visit