[go: up one dir, main page]

0% found this document useful (0 votes)
10 views11 pages

GNU and Unix Commands

The document provides an overview of GNU and Unix command line usage, focusing on the Bourne-again Shell (bash) and various shell commands. It explains the shell's role as an interface, command line interpreter, and programming language, while detailing how to execute single line commands, use pipes, and manage shell environment variables. Additionally, it covers the importance of command history and the ability to invoke commands within different paths.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

GNU and Unix Commands

The document provides an overview of GNU and Unix command line usage, focusing on the Bourne-again Shell (bash) and various shell commands. It explains the shell's role as an interface, command line interpreter, and programming language, while detailing how to execute single line commands, use pipes, and manage shell environment variables. Additionally, it covers the importance of command history and the ability to invoke commands within different paths.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

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

[root@centos01 ~]# rpm -qa | grep -i bash

A query list of the bash program shows that it comes with many other binaries besides itself.

[root@centos01 ~]# rpm -ql bash-4.2.46-33.el7.x86_64

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:

* Introduction:: An introduction to the shell.

When you get to and hit enter on

Introduction:: An introduction to the shell.

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

[root@centos01 ~]# bash –version

[root@centos01 ~]# which bash

/usr/bin/bash

[root@centos01 ~]# file /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

Work on the Command Line


Recap: Interfaces in Linux:
-Command line
-GUI
You will type your shell commands on the command line.

Using Single Shell One Line Command Sequences

 perform single line shell commands and command sequences

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.

Consider the ifconfig command shows me my network interface configuration.

[root@centos01 ~]# ifconfig


Here I see I've got two network interfaces called " enp0s3 and enp0s8", that's my ethernet
interface and I can see it's got IPv4 addresses listed here as " 10.0.2.15 and 192.168.56.101."

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.

[root@centos01 ~]# ifconfig | grep -i "inet "


I'm also getting output I don't want. I am getting a local loopback address of "127.0.0.1."

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.

[root@centos01 ~]# ifconfig | grep -i "inet " | grep -v 127

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.

Using and Modifying the Shell Environment


Exporting Shell Environment Variables
Using and Editing the Shell Command History
Invoking Commands Inside and Outside the Defined Path

You might also like