GNU and Unix Commands
GNU and Unix Commands
Table of Contents
Introduction.................................................................................................................................................3
Work on the Command Line........................................................................................................................7
Using Single Shell One Line Command Sequences...................................................................................8
Using and Modifying the Shell Environment.........................................................................................11
Exporting Shell Environment Variables..................................................................................................11
Using and Editing the Shell Command History.......................................................................................11
Invoking Commands Inside and Outside the Defined Path....................................................................11
Introduction
A Linux distribution is made up of a number of utilities and programs. One key utility is the
command line shell. Let’s dive into the Bourne-again Shell (bash) and the VI text editor. here
are different shells available on Unix systems e.g. AIX or Linux Systems e.g. Red-Hat.
The Original shell was called the Bourne shell and was very light on features.
First a shell is a computer program. Many shell programs are installed when you install the
Linux OS.
A shell is actually 3 things:
1. Its your interface to the OS
2. Its a command line interpreter
3. Its also a programming language with regard to scripting.
See what shells or shell programs are installed on your system:
cat /etc/shells
Examples of shells: Bourne shell, C shell, Korn shell, Bourne Again shell etc.
There are many other shells available and you can also write your own shell using the C
programming language.
Changing a shell can be like relearning Unix as they all have their own features and unique
syntax sometimes.
Interfaces in Linux:
-Command line
-GUI
You will type your shell commands on the command line.
The GUI has some overhead.
Taking a closer look at the bash shell shows that it is a program/an executable/a binary
[root@centos01 ~]# file /bin/bash
A query list of the bash program shows that it comes with many other binaries besides itself.
Get more information about and read about the shell with [root@centos01 ~]# info bash
Navigate with down arrow keys and hit enter on topics such as:
Further use down arrow keys and hit enter on each to learn more:
The up-arrow key will take you back to the previous page.
We can also get some information about the bash shell or program with yum
[root@centos01 ~]# yum info bash-4.2.46-33.el7.x86_64
/usr/bin/bash
/usr/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs),
for GNU/Linux 2.6.32, BuildID[sha1]=7e644dee920bc3ba797c38e05383286563712b49, stripped
A Linux distribution is made up of a number of utilities and programs. One key utility is the
command line shell. Learn how to perform single line shell commands and command
sequences.
Open Linux at the command line and learn to type in numerous Linux commands. You can type
them in on separate lines and pressing enter after each one or you can put them all on the
same line separated with the semicolon.
The date command returns the date and time and the who command lists who is logged in
and from which terminal.
Type date;who to put two Linux commands on the same line. They are executed one after the
other, although the output is all together. If the date command were to take a long time to run, I
would normally have to wait before issuing the next command. In Linux, we can use a
semicolon to link together many different commands on a single command line. Additionally, we
can pipe the result of one command on the Linux command line to another command.
I can pipe the result of this command such that it filters out and only shows me this line with my
IPv4 addresses. I don't want to see anything else.
I will use the | here to pipe that to the Linux grep command; grep is a filtering command and
what I am going to filter for here is the text "inet" because that's part of the output.
So, I am going to continue piping further on a single Linux command line by adding yet
another | and adding grep yet again. But this time with grep, I'll use -v, which means I want
to exclude what I am about to specify which is going to be simply lines that have 127 on them.
Note: The virbr0, or "Virtual Bridge 0" interface is used for NAT (Network Address Translation).
It is provided by the libvirt library, and virtual environments sometimes use it to connect to the
outside network.
Another way that we can work on a single command line is to use special operators that
determine what should be returned if something is true versus false.
[root@centos01 ~]# ping -c 4 8.8.8.8 && echo "The google default gateway is reachable" || echo
"Cannot reach the google default gw"
The && means that if the command on the left fails, I can tell it what I want to occur on the right,
as a result of that. So, I am going to add after the && an echo statement. Basically, if the
command on the left succeeds, I want to display a message to that nature
But I have to decide what I want to do otherwise if the ping is not successful. Use the || or
double vertical bar || symbol after which use the echo command.
Ping an address that is not on the network or that you can’t reach.
So, we can use special operators on a single command line to mimic an if statement.