More Bash Features

The bash shell includes a great many more features that make it easy—or possible—for you to perform your tasks.

Location, location, location

For starters, if you don't know where you are already because you added information to your prompt, you can find out!

To find out where you are:

1.
At the command prompt, type pwd.

2.
Press Enter.

Your current location is displayed (Figure 10.22).

Figure 10.22. You can enter pwd to find out where you are.


To list the files in the current directory:

1.
At the command prompt, type ls.

2.
Press Enter.

The files in your current directory that are not hidden are listed (Figure 10.23).

Figure 10.23. To list the files in the current directory, enter L s.


To list the files—including hidden files—in the current directory:

1.
At the command prompt, type ls –a.

2.
Press Enter.

All the files are listed, including hidden ones (Figure 10.24).

Figure 10.24. To list files-including those that are hidden-in the current directory, enter Ls-a


Using command completion

Command completion in the bash shell means that after you enter just part of a command, the rest will be filled in automatically when you press the Tab key.

Of course, command completion works only if there is a valid way to complete the command you started.

Command completion can be used to complete shell commands, file and directory names, and more.

To use command and completion:

1.
At the command prompt, enter a partial command. For example, as a start on the command more test, to view the contents of the file test, enter more te.

2.
Press the Tab Key. Bash will complete your command, so that it now reads more test.

3.
Press Enter to see the contents of the more command displayed (Figure 10.25).

Figure 10.25. If you use the Tab key with an incomplete command, bash will do its best to read your mind.


Using session history

In the bash shell, the Up arrow key lets you scroll through the list of previous commands entered during your session. The Down arrow will bring you back to the current command.

To access a command you previously used:

  • Press the up arrow key until you reach the command.

To see a numbered list of your session commands:

1.
At the command prompt, type history.

2.
Press Enter.

A numbered list of your session command will be displayed Figure 10.26.

Figure 10.26. Use the history command to display a numbered list of your session commands.


Tip

If you follow history with a number, n the command will display the commands. For example, history 12 will display the last 12 commands you entered.


To reuse a numbered session command:

1.
At the command prompt, type ! followed by the command number. For example, type !144.

2.
Press Enter.

The referenced command will be exectcuted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169