Miscellaneous Shell Commands

 < Day Day Up > 



There are a number of shell commands that do not neatly fit into any category but may prove useful for any Linux system administrator. The commands can provide you with useful information about your system or assist you in performing certain tasks. In the next few paragraphs we will take look at some of these commands.

du and free

It can be quite important for you to find out information about your machine’s current state. In KDE or GNOME you would use the System Information utility to view the use of memory and free diskspace. From the shell we have a few commands we can use. The du command, short for disk usage, will tell you how many bytes of disk space the current directory is occupying. You can see this command in Figure 19.12.

click to expand
Figure 19.12: The du command.

You can also use shell commands to determine how much free memory your system has available. The free command, shown in Figure 19.13, will display the total memory, memory in use, and free memory in bytes. This is quite useful in diagnosing slow or inadequate performance on your machine, which is often caused by too little memory.

click to expand
Figure 19.13: The free command.

pwd

When you are looking at your prompt, it usually lists the name of the current directory and the current user. It does not list the complete path to your directory. If you are in a directory that is a subdirectory of yet another subdirectory, it can get quite easy to forget where you actually are. The pwd command, shown in Figure 19.14, will display the complete path to your current location. It is the shell equivalent of leaving a trail of bread crumbs so you can find your way back home.

click to expand
Figure 19.14: The pwd command.

dmesg

This is a very interesting command and may prove quite useful if you need to diagnose system problems. When your system boots up, you see a lot of information telling you what processes are starting, what processes failed, what hardware is being initialized, and more. Unfortunately, you may not have watched the bootup process carefully, or you may not remember what you saw. If, for example, your sound card is not working, it would be a good idea to know if it was properly initialized during bootup. You can use the dmesg command, shown in Figures 19.15a and 19.15b, to view all the messages that were displayed during bootup.

click to expand
Figure 19.15A: The dmesg command.

click to expand
Figure 19.15B: The dmesg command, continued.

As you can see, this command produces a tremendous amount of output. It can be quite daunting to read through this entire series of screens searching for a single item. This is where the redirect command can be quite helpful. If you type in dmesg > boot.txt, the dmesg output will be redirected to a file. You can then use any text editor you like to open that file and search for the items you need to check. This is just one example of how, using various shell commands together, you can make the system easy to manage.

fsck

Hard drives eventually age and begin to encounter problems. It is important to be able to diagnose and correct problems before they become too severe. Every computer needs a process to check the system. With Windows, you can run a Scan Disk on any drive from the Windows Explorer. You right-click on the drive, and under Properties choose Tools. This is shown in Figure 19.16.

click to expand
Figure 19.16: The Windows Scan Disk.

In Linux you can run fsck on any drive from the shell. This is short for filesystem check. It will check the integrity of the filesystem. This command can be quite useful in ensuring that your computer is optimized to perform its best. You can see this command in Figure 19.17. However, with later versions of Linux using ext3 as the filesystem, optimization is rarely if ever required, so you may not use this command very often.

click to expand
Figure 19.17: The fsck command.

logout and shutdown

When we discussed run levels and init, you saw that you could use the command init 0 to shut down the system. However, many users cannot use the init command. It is meant to be the tool of the root user, not all users. How do you reboot or shut down the system from the shell if you are not logged on as the root user? The answer is to go to KDE and choose the Logout option from the Start menu. However, if you are logged on as root or use the su command for superuser mode, there are other commands that also will work for shutting down the system. The shutdown command does exactly what init 6 does. Just type in shutdown at the shell, and the system will shut down. You can also log out using the command logout typed in at the shell. logout works for any user, but remember that shutdown will work only for root.

passwd and su

You also may need to change the password of the user currently logged on. This can be done with the passwd command. If you type in the command passwd, as shown in Figure 19.18, you will be prompted to enter a new password. If the system feels that this password is too easy to crack, because either it is a standard dictionary word or too short, the system will tell you that it is a bad password. You then retype the password to confirm it.

click to expand
Figure 19.18: The passwd command.

There will be times when you may go to a Linux machine where someone has logged on, and you want to do some task that requires the privileges of the root user. Logging out, then logging back in as the root, can be tedious. Fortunately, you don’t have to do that. You can invoke the superuser mode. If you type in su at the shell, you will be asked for the root password. If you supply it, you will have root privileges.



 < Day Day Up > 



Moving From Windows to Linux
Moving From Windows To Linux (Charles River Media Networking/Security)
ISBN: 1584502800
EAN: 2147483647
Year: 2004
Pages: 247
Authors: Chuck Easttom

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net