Directory Navigation Tips in Linux

Linux, bash October 7th, 2008

Many of us just use cd, cd .., cd <dir> to navigate through the file system in Linux. Directory or file-system navigation can be simplified by using following commands -

1) Many times we are in some directory say /home/user/foo and we need to go to the directory /usr/share/bar . After completing tasks in this directory, if one needs to get back to the previous directory, he would type in ‘cd /home/user/foo’ . Won’t it be far easy if we had some kind of back button as in Nautilus or Windows Explorer ? Its already there in Linux. Just type in
$ cd -
and you will reach back to the previous directory.

2) Another important tool to make navigation easier is ‘pushd’ and ‘popd’. Say you are in some directory /home/user/foo1 and then you wish to navigate to /home/user/foo2 and then to /home/user/foo3
After all these you need to back to previous directories. You can use pushd and popd like this :

$ pwd
/home/user/foo1
$ pushd .
$ cd /home/user/foo2
$ pushd .
$ cd /home/user/foo3

Now to get back to previous directories -
$ popd
$ pwd
/home/user/foo2

pushd actually push its argument directory to a stack and popd changes the current directory to the one on top of the stack.

Hope you enjoyed these tips.

How to force fsck (File System Check)

Linux, Ubuntu July 13th, 2008

Ubuntu linux, by default performs an ‘fsck’ one every 30 times the file-system is mounted to make sure the hard disk has no errors.

Sometimes you may need to perform an ‘fsck’ during next boot. Here’s the solution -

Create a file /forcefsck without any contents. This can be simply accomplished by

$ sudo touch /forcefsck

The next time you bootup fsck will be performed on all the partitions of your hard drive.  Since the file /forcefsck is deleted during the bootup process, this will force ‘fsck’ just ones.

On the contrary, if you frequently turn off your machine, you may be annoyed by regular fsck done every 30 times filesystem is mounted.  So, you may sometime wish to disable fsck and boot up fast. This can be done by creating a file /fastboot

$ sudo touch /fastboot

This file is also deleted during the boot up. So this method disables fsck only once. To change the frequency of ‘fsck’ according to your need you may use a very good utility ‘tune2fs’.

Check out its man pages for more details.

P.S.: These methods are generic to all Linux distros, but I am not sure about the frequency.