Saturday, July 22, 2006

How to Attain Linux Nirvana..

Tips and Tricks for Linux Nirvana

Moor’s law is giving you better computers every new day. But then, Murphy’s Law is pushing you to stand you on your toes to learn new tricks for using these new, little monsters to their full potential. Linux For You is giving you some prasada of tips & tricks for your Linux Nirvana.

Have some command over Linux Commands:

  • Use BASH terminal

In Linux, there are many shells you can use for interpreting your commands. However, it is recommended to make your default shell BASH, the short form of Bourn Again SHell. It has more built in commands, switches, options and added functionality then other shells that make your command life easy. Anyway, in most recent distributions, it is pre-installed as default shell and you may not bother much.

  • Use Tab for auto complete

Bash supports advanced auto complete feature. While writing your command, simply try to press your keyboard’s Tab key. If it finds something matching in your command history, it will auto complete it for you. If you are giving command for changing directory, and you forgot the names or exact spelling or correct case of directory name, simply press Tab key. It will print the directory of last valid directory entry that you have entered so far. Now you can read the available directories and can complete the command easily.

  • Start multiple programs with single command

Often, we open multiple programs for performing our daily tasks in our desktop. For example, for sending and receiving mail through Internet Dialup modem, you open Kmail, the mail client and Kppp the internet dialer. Either you open these two applications by pressing KDE’s start button and then selecting them from their respective program group’s entries. Next time, when you want to start them, start them differently. Simply open a terminal and give following command:

# kamil ; kppp

This command will start both the application one after another in the sequence given in the command. In a similar way, you can start any number of applications. Simply separate the commands with a semicolon for each. A better way is to make alias that further shortens your commands. The following example will make ‘m’ the command that will open mail client kmail and internet dialer kppp both for you.

#alias m = “kmail ; kppp”

Now, simply give command m and it will open both kmail and kppp for you. It is better to put all the aliases in your home directory’s .bashrc file so that these aliases will load on system startup and will always remain available to you.

  • The ‘see’ prompt

Want to have DOS like C:> prompt in your Linux? Here is how. Simply give following command and you have your way to dos like command prompt:

#PS1= ‘C:>’

Your command prompt will immediately changed to C:> prompt. Now, you have a clue. Yes, you can have any type of cryptic looking command prompt like ‘I love Linux For You’ in your terminal. Not only that, you can have current date, time, host name etc. in your command prompt by using suitable switch. For example, if you want to add current working directory in the above command prompt, the above command will be-

#PS1= ‘\w C:>’

Now your C prompt will have prefix of your current directory. Following is the list of different switches with their brief description:

/w Display current directory

/d Display current Date

/h Display host name

/t Display current time

/u Display user name

/! Display history number of current command

  • Spell check and auto correct your command

There is one great shell option called cdspell that helps people like me who never learn to give correct change directory command. Well, if there is tool like cdspell (change directory command spelling checker and auto corrector) then one should never need to learn either. To enable cdspell in your Bash, give following command:

#shopt –S cdspell

Your command interpreter is ready to check and correct spelling errors in change directory command. Now, give following command:

#cd /sur/nib

Sure, you have /usr/bin directory and not that the one you gave in the above command. But cdspell will check it with available directories and if found misspelled directory name and path, it will print the correct name and path and then proceed the correct command. You will happily see here that instead of error message, you have changed to correct directory /usr/bin. As you have seen here, Cdspell checks for minor spelling errors in directory component, checks for missing character, transposed character or too many characters and automatically corrects them.

  • Spell check from command line

Forget the Word processor to spell check a small text file that you wanted to send as mail attachment. You can check spelling from your command prompt. If you have installed spell checker packages like Aspell in your Linux machine, then you can check spelling errors and interactively, can correct them right from your command prompt. To check spellings of my.txt file in your current directory, give following command:

#spell my.txt

The command will print all the words in the file that it does not find an exact match in its database as misspelled word. The misspelled words appear in the order they appear in the my.txt file. If you want to correct them, you need to check spelling in interactive mode. For that, you will have to give following command:

$ispell my.txt

Now, the command will check your file for spelling error and will display its first instance with list of matching words for possible correction. It you find one, press the number placed against it, or ignore it or add it as new word and it will point to next misspelled word and so on till the file is completed.

  • Change runlevel without reboot

There is no need to reboot to change your run level. If you are in GUI runlevel 5 mode with X Window running and want to switch to commond line mode runlevel 3, simply give following command:

#telinit 3

Conversely, if you are in runlevel 3 and want to switch to runlevel 5, give following command:

#telinit 5

While switching runlevel, the command closes the unwanted process and starts the desired ones for the runlevel it is switching to; and switches you to that runlevel without reboot. Further, if you want to change your computer’s default runlevel permanently, edit the file /etc/inittab (become root first for that). Look for the entry like this in the said file if your default run level is 3:

Id:3:initdefault:

Now, change the figure 3 to 5, (or vice versa) and save the file. Your default runlevel now become 5. The changes will take effect on next reboot.

  • A word with modules

Linux installs device drivers in its Kernel as modules. While modules are necessary for your computer to deliver things, at times you may not need some modules that are pre-installed or when you remove certain hardware. To see what modules are installed in your machine, give following command:

#lsmod

This will show whatever modules installed in your computer. You can have information about modules through modinfo command. Similarly, for removing a module, command is:

#rmmod module-name

Where module-name is the name of module. For your new hardware to work, you need to install module for that. You can add a module through command:

#modprobe module-name

Have some more breeze through your X-Windows

  • Have multiple GUI Window

You already know that you can have multiple command line login windows in your Linux machine. You can login as six different users simultaneously in same machine by switching terminal through Ctrl+Alt + Function Key F1 through F6 key combinations. Similarly, you can have equal number of users running their own GUI desktop simultaneously. You simply have to add some extra configuration strings for that. But ensure that you have better processor, ample RAM and a fast video card for that.

Open file Xservers that is generally available at etc/X11/xdm directory (you must be root user to edit the said file). You will see entry like this:

:0 local /usr/X11R6/bin/X :0

This is the default entry for display 0, which is available at your terminal whenever you start X. Now, if you want to have two more Windows, edit the line and add two more line one each for each extra window. After editing and adding, the line will look like this:

:0 local /usr/X11R6/bin/X :0 vt07

:1 local /usr/X11R6/bin/X :1 vt08

:2 local /usr/X11R6/bin/X :2 vt09

save the file, start Xwindow if it is not started yet, and press Alt+Ctrl+F7 for login to Display 0 (it is default) Alt+Ctrl+F8 for login to display 1 and Alt+Ctrl+F9 for login to display 2. Now you can Login to all three window as same or different user in GUI mode with one running KDE, the other GNOME, the third one XFce etc. You can add three more window in a similar manner for function key F10, F11, F12 respectively. To switch between windows, simply press Alt+Ctrl and Function key number for the particular window.

  • Switch between video mode

While you can change your windows resolution mode through your desktop’s environment settings, there is a quick way to do so. If the monitor has setup to display multiple modes and is capable to do so, you can increase resolution by keep pressing Ctrl+Alt and + (plus) key simultaneously. Similarly the resolution can be brought down by pressing Ctrl+Alt and – (minus) key.

  • Shut the Window down

Linux is pretty hard to crash, but not the Xwindows applications. Some Xwindows application starts behaving erratically and refuses to close its window. There is a small yet powerful utility called xkill that can close anything running as X application. Using it is pretty simple. Simply run command xkill in any terminal and it will display a special mouse cursor. You simply have to click on crashed application window with this cursor and the application will close immediately. Ensure that you do not click on Panel / Desktop etc., else they too will close immediately. You can right click anywhere to cancel an invoked xkill command.

Smart way to test your hard disks

  • Know your disk usage:

There is a nice command called ‘du’ that you can find on most Linux distributions. This command can show you disk usage i.e. space status of your hard disk. You can use it to display usage status of current directory, or directory you specify or drive you point. There are number of options you can use to get information in variety of ways. Following is the command that displays contents of /root directory in directory size sorted in ascending order:

#du –h /root | sort –n

Refer man pages of du command for more options.

  • Smart disk diagnostics

Modern hard disk employ technology called SMART (Self Monitoring Analysis and Reporting Technology). But you need some additional utility to use this advance feature most. You can enable SMART check through your machine’s Mother board’s BIOS, but often they may not be adequate enough for a full, detailed check and analysis reporting. There is a utility called smartmontools that you can use in Linux. You may have pre-installed this tool in your Linux since many Linux distributions include this valuable tool. If it is not installed in your machine, then download and install the latest version from: http://smartmontools.sourceforge.net/ . It can test ATA/ATAPI 3-7 and SCSI hard disks. It is run in command line mode and as usual, has built in numerous options. Following are some basic commands that you can run to test your hard disk /dev/hda:

# smartctl -t short /dev/hda

This command will do a short test on hard disk.

# smartctl -t long /dev/hda

This will do a detailed test on your hard disk.

# smartctl -i /dev/hda

This will show the information about the drive after the test is complete by above two commands.

# smartctl -H /dev/hda

This command gives you quick view of drive health. If your drive is OK, then it shows that the drive has Pass the test.

For more detailed usage, refer manual pages of smartctl.

Fine print: Depending upon your version of Linux, you may or may not get some of the tips working exactly as had been described. Though these tips are simple and harmless, use them on your own risk!

No comments:

More Articles...

Translate in your own language

Want to translate this article in your own language? Just click the Flag below