Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
CentOS Quick Start Guide

You're reading from   CentOS Quick Start Guide Get up and running with CentOS server administration

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789344875
Length 320 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Shiwang Kalkhanda Shiwang Kalkhanda
Author Profile Icon Shiwang Kalkhanda
Shiwang Kalkhanda
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with CentOS 7 FREE CHAPTER 2. Command-Line and Filesystem Navigation 3. Managing Text Files 4. User and Group Management 5. Managing File Permissions 6. Process Management 7. Managing Networking in CentOS 8. Software Package Management 9. Overview of Essential Advance Utilities 10. Other Books You May Enjoy

Bash shell and command execution

In this section, we will learn about the different features of the Bash shell with which you can reduce errors and increase the speed at which you work on the Terminal.

Tab completion

Linux shell syntax is case-sensitive as well as space-sensitive, so typing errors are the first major hurdle in learning for any beginner. However, if the tab completion feature is adopted by a beginner, then it makes life very easy and smooth by reducing typing errors to a minimum.

Tab completion enables you to complete command names or file names once you have typed enough characters at the prompt to make it unique. If the characters entered at prompt are not unique, pressing the Tab key twice displays all commands that can begin with the character already entered into the command line. An example of command completion using the Tab key is shown in the following screenshot:

The Tab completion feature can be used to complete file names or path names when typing them as argument to commands. Pressing the Tab key once completes the filename or path if it is unique; otherwise, pressing the Tab key a second time lists all the possible combinations of filenames or path names based on the current pattern. Thereafter, you can type additional characters to make the name or path unique, and press the Tab key again for completion of the command line. An example of path and filename completion using the Tab key is shown in the following screenshot:

Command-line editing shortcuts

Bash has a very useful command-line editing feature that can increase your productivity while working on the Terminal. It enables the user to use some shortcut commands to move around or delete characters on the command prompt.

The following table lists the most useful command line shortcuts available in Bash:

Shortcut

Description

To move the cursor

Ctrl + A

Moves the cursor to the beginning of the command line

Ctrl + E

Moves the cursor to the end of the command line

Ctrl + Left arrow

Moves the cursor to the beginning of the previous word on the command line

Ctrl + Right arrow

Moves the cursor to the beginning of the next word on the command line

To delete characters

Ctrl + U

Deletes the characters from the current cursor position to the beginning of the command line

Ctrl + K

Deletes the characters from the current cursor position to the end of the command line

Ctrl + W

Deletes the last word from the current cursor positing on the command line

Ctrl + L

Clears the screen (you can also type the clear command)

To modify the size of the Terminal window

Ctrl + +

Increases the size of the Terminal window

Ctrl - -

Decreases the size of the Terminal window

The history command

The history command is used to display a list of previously executed commands prefixed with a command number showing the order of their execution, as shown in the following screenshot:

The exclamation point character (!) is a metacharacter in Bash, used for previously executed command expansion from history list on prompt.

The following table lists various history commands that are quite useful for beginners:

Command

Description

!<number>

Expands to the command matching the specified number from history

!<string>

Expands to the most recently used command that begin with the string specified at the prompt

history -d <number>

Used to delete the numbered command from history

history -c

Empties the history list

Ctrl + R

Searches the history list of commands for a pattern, and executes the most recent match when found

The following screenshot displays the usage of the history command:

Besides the already listed options, we can use the arrow keys for navigation between the previous and next command line in the shell's history. The Up arrow key brings up the previous command executed from the history list. The Down arrow key brings up the next command from the history list.

Command aliases

The alias command is used to create an alias name or nickname for frequently used commands. It simplifies the administration process by providing alias names for long commands or even combinations of commands.

Listing current aliases

To list the currently configured aliases for your shell, just type alias without any argument at the prompt, as shown in the following command line:

$ alias

Setting an alias

The following syntax is used to set an alias x for the exit command. Thus, after setting this alias, whenever you want to exit from Terminal, you just have to enter x at the prompt:

$ alias x="exit"
$ alias c="clear"

Removing an alias

To remove an alias, the unalias command is used. For example, to remove the previously set alias, we use the unalias command as follows:

$ unalias x
The alias command will set its alias for the current session only. If you want to set an alias for any command persistently, you have to make an entry for it in /etc/bashrc for system-wide changes, and if you want to make user-specific changes, than put its entry in the .bashrc file stored in the user's home directory.
You have been reading a chapter from
CentOS Quick Start Guide
Published in: Dec 2018
Publisher:
ISBN-13: 9781789344875
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image