Community Enterprise Operating System,Â commonly referred to as CentOS,Â is a fast, stable, and open source enterprise-grade Linux distribution used on laptops, desktops, and servers. It is derived from the source code of Red Hat Enterprise Linux (RHEL), which is developed and maintained by the CentOS community. All proprietary content related to Red Hat Inc. is removed from the CentOSÂ packages, which are then recompiled with CentOS community assets, such as logos and so on. CentOS 7 is an exact replica of RHEL 7, but is available for free with community support and updates. The CentOS project is now officially sponsored by Red Hat Inc. and is most suitable for environments where commercial support for operating systems is not mandatory.
In this chapter, we will give you a walk-through on how to install CentOS 7 on your computers. After installation, we will introduce you to the command-line console of Linux in order to useÂ Bash (short for Bourne Again Shell). This chapter teaches you how to set up your environment to perform all the exercises in the following chapters of this book.
In this chapter, we will cover the following:
- Preparing to install CentOS 7
- Performing manual installation
- Accessing the command line using the console
- Introducing the Bash shell
- Bash shell and command execution
The CentOS community released its latest operating system version with the name CentOS 7.6-1810, where 7.6 comes from RHEL 7.6 and 1810 shows its release date (October 2018). CentOS 7.6 can be installed on physical or virtual hardware. You can use any of the main desktop virtualization software utilities, such as Oracle VirtualBox (https://www.virtualbox.org/wiki/Downloads) or VMWare Workstation (https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html), as per your environment. My choice for desktop virtualization software is VirtualBox as it is free, open-source, and easy to use. You will also need a working internet connection to download the CentOS image from the community download page.
- 512 MB RAM
- 4 GB HDD space
- A network card
However, to practice all the exercises described in this book, we recommend that the following hardware requirements are met:
- 64-bit architecture support
- 1 GB RAM
- 10 GB HDD space
- DVD drive or USB memory stick
- A network card
There are different ways to get the software required to perform all the exercises in this book. However, the easiest and most flexible way is to download the
iso file from the CentOS website and burn it to a DVD, or create a bootable USB drive with CentOS. Then, boot your PC using the ISOÂ DVD image if you are using a virtual machine. If you are installing onto a physical system, then use a bootable USB drive or burned CentOS DVD for installation.
Use the following link to download the CentOS 7.6 (64 bits) ISO image file:Â
Once you have the right hardware and software for the CentOS installation, you should decide on the basic setup parameters to be specified while performing the installation. The following table lists the details we will use during the installation of our CentOS 7.6 server described in this chapter:
Nowadays, the fastest and easiest way to install CentOS is to use a bootable USB drive; however, in our case, I have chosen to use the DVD ISO image with a virtual machine. First, we need to boot the computer system/virtual machine using the DVD. On booting from the DVD, you will get a cool CentOS screen displaying the basic installation options, and testing the media and troubleshooting options.Once your system/virtual machine is up and running with a bootable DVD of CentOS 7, follow these steps to install CentOS on your system:
- We have to choose the
Install CentOS 7Â option and pressÂ Enter,Â as shown in the following screenshot.This will start the graphical installer and ask about the language to be used during the installation process:
- After this,youwill seeÂ anÂ
INSTALLATION SUMMARYÂ screen.From this screen, you can specify the settings you want to use for the threedifferent sections and their sub-sections, as shown in the following screenshot:
On this screen, the
Begin Installation button will remain disabled as long as any setting from a section or subsection displayed on the
INSTALLATION SUMMARY screen is still incomplete. If all the sections and subsections displayed on this screen are complete with minimum installation instructions, only then will the
Begin Installation button be enabled.
By default, the installer does automatic partitioning for our hard disk. If we want to use the default layout, then we must click on
INSTALLATION DESTINATION,Â and then approve the disk device we want to use for automatic partitioning by clicking on theÂ
Done button on the next screen. Thereafter, the
Begin Installation button will be enabled and we can install CentOS with a minimal configuration, as shown in the following screenshot:
The minimal installation of CentOS 7 doesnât have a graphical interfaceâit has a bare minimum set of packages installed, with limited features available in the command-line interface.
- If you are a beginner and wantÂ to useCentOS 7 with a graphical user interface (GUI), then follow these installation instructions. In this step, we'll learn about the usage of CentOS and then modify certain options that need to be configured during installation. TheÂ
INSTALLATION SUMMARYscreen has three sections, as follows:
These three sections are explained as follows:
LOCALIZATION:Â This section further contains the following three sub-sections for configuration:
DATE & TIME
DATE & TIMEoption, select the time zone that you are in by clicking on your location on the world map. You can also configure your current specific
DATE & TIMEÂ from this window, as shown in the following screenshot:
We leave the
LANGUAGE SUPPORTÂ settings at their defaults, and move to the next section to be configuredâin this case,
SOFTWARE: This section further contains two sub-sections for configuration:
SOFTWAREÂ section, we keep
INSTALLATION SOURCE set toÂ its default local mediaÂ (DVD-ROM), as shown in the following screenshot:
The next sub-section for configuration is
SOFTWARE SELECTION. This forms an important part of the installation procedure. Click on this option and you will get the screen shown in the following screenshot. From here, you can choose the default base environment and add-ons that are available for the selected environment. For our practice demonstration, we will install the
GNOME DesktopÂ base environment with four add-ons:Â
Office Suite and Productivity,
Development Tools and
System Administration ToolsÂ as shown in the following screenshot:
SYSTEM: This section further contains four sub-sections for configuration:
NETWORK & HOST NAME
In this section, we keep the
SECURITY POLICYÂ sub-sections set to their default parameters, and configure the two remainingÂ sub-sections as follows:
INSTALLATION DESTINATIONÂ sub-section, we specify where we want to install CentOS. Automatic partitioning is selected by default, but wecan create a manual partitioning scheme of our own as per our requirements. As a bare minimum standard, we will create the following three partitions:
- Boot partition:Â This partition stores bootable filessuch as the kernel image, and so on.
- Swap partition:Â This is for swapping files and programs in and out of the RAM. It is generally twice the size of the RAM.
- Â Root (/)partition:Â This contains theÂ Linux filesystem.
The following screenshot shows where to click to create manual partitions:
- Choose the device onto which to install the OS, and select
I will configure partitioning. Finally, click on the
Âbutton to proceed with the creation of multiple partitions as shown in the following screenshot:
- Now, we create a minimum of three partitions in the partition table (
/). In my case, I have keptÂ
File SystemÂ as
xfs,Â with the
Partitiontype for the
partitions. For the
File Systemtype is kept as
swap, as shown in the following screenshot:
- Next, on pressingÂ
Done, you will getÂ the
SUMMARY OF CHANGESÂ dialog box. Click on theÂ
Accept ChangesÂ button to begin creating on the disk the partitions that we specified in the partition table, as shown in the following screenshot:
NETWORK & HOST NAME: In this finalÂ part ofthe installation summary, which we'll configure networking. You can leave the default settings as they are to get the IP address from the DHCP server, or click onÂ
NETWORK & HOST NAMEÂ to set up networking manually. From the dialog box, click on the
IPv4 Settings Tab, then choose the method asÂ
ManualÂfrom drop-down menu and specify the private IP address, as shown in the following screenshot:
Further in the
NETWORK & HOST NAME settings,Â change the network connection state from Off to On, as shown in the following screenshot:
- Next, the screen prompts for user settings. Here, we click
Root PasswordÂ first and set the password to
- Next, we click on
CREATE USERÂ to create a user. For both the
Full nameÂ and
User nameÂ fields, enterÂ
student, and set
[email protected]. Here also we have to click on theÂ
DoneÂ button twice to confirm the password, as shown in the following screenshot:
- Have a cup of coffee while the installation process is in progress. Once the installation is complete, remove any installation media (the instructions only apply to the DVD method)Â and click on theÂ
RebootÂbutton, as shown in the following screenshot:
- Once the system has rebooted, we will get the INITIAL SETUP screen, where we have to acceptÂ an EULA agreement before logging in to the system. Here, we click on
LICENSE INFORMATIONÂ to accept the license agreement, as shown in the following screenshot:
- Once the license agreement has been accepted, the
Â FINISH CONFIGURATIONÂ button will become enabled. Click on itÂ to reach the login screen.
- On the login screen, click on the
studentÂ usernameÂ and enter the password as
[email protected], as shown in the following screenshot:
- After a successful login, you will see the welcome screen that is displayed only when the user LOGS IN for the first time. Click on theÂ
NextÂ button to reach the desktop.
- Congratulations! You have successfully installed the latest version of CentOS 7 on your computer system or virtual machine.You can explore your new CentOS 7 environment and perform other tasks, such as updating the system or installing other useful software for daily operational requirements. To power down the system, click on the right corner of desktop. You will get a drop-down menu; from there you can clickÂ on
Shut down, as shown in the following screenshot:
With this, your installation process is complete. In the upcoming section, we will learn how to access the command-line console.
When using CentOS, systemadministration or applications development tasksareperformed using either thecommand-line interface (CLI), such asthe Bash shell, or with the help of a GUI, such asÂ GNOME, KDE, and so on.Â In this section, we will learn how to enter commands in the Bash shell at the Linux console.
To access a shell prompt in the GUI environment, you have to start a Terminal application, such as GNOME Terminal. There are multiple ways to launch a Terminal. The most frequently used ways to access a Terminal are as follows:
- Right-click anywhere on your Terminal and select
Open in TerminalÂ from the context menu that pops up
- From the activities overview, select
If you have started the Terminal application as a normal user, then the default prompt ends with a
$ character, as shown in the following screenshot:
A normal shell prompt lists the following three details:
- The login name of the current user
- A short hostname of the machine, also known as the machine name
- The name of the current working directory
The tilde (
~) sign in the shell prompt represents the user's home directory. We will learn more about this in the following chapter.
The default shell of CentOS 7 is Bash, which provides a scripting facility for the automation of repeated tasks. The main functionality of any shell is to interpret the commands entered by the user at the prompt, and to provide a platform to launch any other program.
The default shell of Unix distributions is generally set as the Bourne shell.Â It is similar to the Microsoft Windows's Command Prompt application,Â
cmd.exe. Windows 7 and Windows Server 2008 R2 onwards include Microsoft PowerShell, which is very similar in functionality to Bash.
There are two ways to access the shell. The first method is via the Terminal. When you install Linux without a GUI (as in a text-based installation), this can be the Linux machine's physical console, consisting of a keyboard for user input and a display to show output.
The second method is by using the shell from a virtual console. The Linux machine's physical console supports multiple virtual consoles, which act as separate Terminals with independent login sessions. If the GUI is installed, then the first virtual console is the GUI in CentOS/RHEL. In addition to the first graphical environment, five pure text-based environments are also available on a virtual console with which you can access a login shell. Ctrl + Alt + (F2 through F6) are text-based and Ctrl + Alt + F1 is the graphical desktop.
The name of the application to be executed
This modifies the behavior of the command; options are generally prefixed with one or two hyphens
TheseÂ generallyÂ indicate the target on which the command is be applied
A command can consist of one or more options and can take one or more arguments, depending upon its syntax. Understanding the syntax of commands will tell you all about the options and arguments it can take, and in what order. To view the syntax of a command, we can use theÂ
--help option or view the manual page. The usage of theÂ
mkdir command with its options is shown in the following screenshot:
Initially, you may find the output of theÂ
--help option a bit confusing. However, it becomes much simpler once you understand the basic conventions used in the syntax, discussed as follows:
- Square brackets,Â
[ ], enclose optional items. For example, it is not mandatory to execute theÂ
mkdircommand with any option, as shown in the following command line:
$ mkdir mydirectory
â¦, represent a list of more than one item of a given type. For example, we can use multiple options, such asÂ
-v, together with theÂ
mkdircommand as shown in the following command line:
$ mkdir -p -v demo/linux/centos
- Text given in angled brackets,
<>, represents variable data. Sometimes, variable data is also written in capital letters. For example,
mkdirÂ means we have to insert the directory name we want to use with theÂ
- Multiple items separated by pipes (
|), mean that only one of those items can be specified.
- Typing the
exitcommand anytime on the console terminates the current session.
- Pressing the
CtrlÂ + DÂ keys together is also a shortcut quite often used to terminate the current session.
The GNU BashÂ is primarily aprogram that interprets commands entered by the user at the prompt. As we learned in the previous Command line syntax and structure section, each command entered by the user can have three parts:
- The command
- The options (beginning with
- The arguments
Each word entered in the shell is separated from the others with a space. Commands are the names of various applications installed on our system, where each command has its own options and arguments.
When you want to execute a command entered at the prompt, the EnterÂ key is pressed. After the EnterÂ key is pressed, output from that command is displayed on the shell, which is followed again by the prompt as shown in the following screenshot:
Each command is entered on a single line; however, if you wish you can enter multiple commands on a single line using the semicolon (
;), which acts as a command separator.
The various functions performed by the shell include the following:
- It provides an interface between the user and operating system
- It is a way for the user to execute commands and other programs
- It acts as an command-line interpreter for commands entered at the command prompt
- Shell also enables the automation of tasks by reading commands from a special text file, known as a shell script
- Shell provides an environment for users and programs running on the operating system
There are multiple types of shell installed on each Linux distribution, with slight differences in features among them. The Bourne shell (sh) is the most primitive, and the Bash shell is the most advanced. The differences between these shells are listed in the following table:
File name completion
Command line editing
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 commandnamesor 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:
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 themost usefulcommand line shortcuts available in Bash:
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Â
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 exclamation point character (
!) is a metacharacter in Bash,used forpreviously executedcommandexpansionfrom history liston prompt.
The following table lists various
history commands that are quite useful for beginners:
Expands to the command matching the specified number from history
Expands to the most recently used command that begin with the string specified at the prompt
Used to delete the numbered command from history
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
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.
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.
$ alias x="exit" $ alias c="clear"
$ unalias x
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.
In this chapter, we started our journey learning CentOS 7. First, we began with the installation process, which was followed by an introduction to the Bash shell and command line syntax and structure. We then mastered the basic features of running commands from the shell with fewer strokes with the help of theÂ Tab key, command-line shortcuts,
In our next chapter, we will continue our journey through CentOS 7, looking at the Linux file system hierarchy and other essentials.