Advanced Shell Commands

 < Day Day Up > 

We have looked at a lot of shell commands in this book. Most were pretty easy to work with. You could devote an entire book just to Linux shell commands, so obviously we will not be examining all of them. However, there are a few more interesting ones that we will take a look at in this section. You may be wondering why these commands were held off until now. Some did not fit neatly into any previous category. Others are a bit more complex and probably are best shown to you after you have had a little experience with shell commands.


This is an interesting command and quite useful. From a purely aesthetic view point, it probably is the most appealing of the shell applications. The cal command displays a calendar in your shell. This can be very useful. If you enter cal at the shell, you should see a calendar much like the one shown in Figure 21.1.

click to expand
Figure 21.1: The cal command.

This command is very easy to use. However, like most shell commands, it has several flags you can pass to it if you want. Table 21.1 lists several of the more common flags used with cal.

Table 21.1: cal Flags




This causes the calendar to show the previous, current, and next month. The number three causes three months to be displayed.


This causes the calendar to use Sunday as the first day of the week.


This causes the calendar to use Monday as the first day of the week.


This will cause the calendar to display using Julian dates.

There are more flags than this, of course, and you can see them all by entering man cal at the shell. However, these flags are enough to demonstrate how the calendar works differently with different flags. For example, the cal –m command is shown in Figure 21.2.

click to expand
Figure 21.2: The cal –m command.

In Figure 21.3 you can see the past, current, and next month displayed using the cal –3 command.

The cal command may be one of the easiest to use shell commands we have discussed. However, it is quite useful and does not fit into any previous category.

click to expand
Figure 21.3: The cal –3 command.


The grep command is one of the most widely used commands in the Unix/Linux world. It is a search command. It is used to search a file for a particular occurrence. You can search for a single character, entire word, sentence, or more. The format is quite simple:

   grep [item to search for] filename

If you want to search one of your previously written script files from the preceding chapter for the occurrence of the word else, you could simply type in

   grep else

You should see something much like what is shown in Figure 21.4.

click to expand
Figure 21.4: The grep command.

The grep command is popular with Linux and Unix users because it is so flexible. If you enter man grep at the shell, you will see a rather extensive entry, listing a number of flags you can pass to grep. However, some of the most common flags are listed and described in Table 21.2.

Table 21.2: The grep Flags




This instructs grep to ignore case.


This tells grep to look for whole word matches only.


This instructs grep to look for entire line matches only.


This suppresses error messages.

As with all shell commands, you can pass more than one flag to grep. This makes it a very flexible and popular search tool. It is probable that there has never been any book written about Linux that did not give grep at least a passing introduction.


If you will recall, when we explored the KDE interface we discussed the Calculator and compared it to the Calculator found in Windows. You may be pleased to find that the Linux shell also has a calculator, although not nearly so graphically appealing. The dc command puts your shell into Calculator mode. You can then enter the arithmetic operations you want to perform. Much like certain calculators, dc uses a sort of reverse notation. For example, if you enter the following, you should see something much like what is displayed in Figure 21.5.

click to expand
Figure 21.5: The dc command.

   dc    10    5    +    p    15

After each character, you will of course press the Enter key. They are not displayed here on separate rows by accident. Each command, number, and arithmetic operator is entered separately, followed by pressing the Enter key.

Notice that the arithmetic operator appears after the second operand, rather than between the two operands. Also notice the letter p. This concludes the arithmetic operations and causes the answer to be printed to the screen.

 < 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 © 2008-2017.
If you may any questions please contact us: