Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Understanding The

Linux Command Line


&
Using Basic Linux Commands
What is Command Line?
A command line is a text-based interface which can be used to input instructions to a
computer system.

The Linux command line is provided by a program called the shell. Over the long history
of UNIX-like systems, many shells have been developed.
A few are :
• sh
• csh
• Ksh
• zsh
• bash
What is the login shell in Linux?
Login shell. A login shell is a shell given to a user upon login into their user
account.
The Shell basics
Commands entered at the shell prompt have three basic parts:
• Command to run
• Options to adjust the behaviour of the command
• Arguments, which are typically targets of the command
A few things to know about commands (Help)
conventions:
• Square brackets, [], surround optional items.
• Anything followed by ... represents an arbitrary-length list of items of that type.
• Multiple items separated by pipes, I. means only one of them can be specified.
Chapter1. Access ing the Command Line
• Text in angle brackets, <>, represents variable data. For example, <filename>
means " insert the filename you wish to use here". Sometimes these variables are
simply written in capital letters (e.g., FILENAME).
A Simple Command example

Command:
$ date
Output:
Tue Oct 10 22:55:01 PDT 2017

Command:
$ date -u
Output :
Wed Oct 11 06:11:31 UTC 2017

:-u Option: Displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time )time
zone.
What we cover in this Session

● Standard Input/Output/Error
● What are they?

● How and why handle them

● Environment Variables
● What & Why

● Important Commands Associated With

● How and where to set and manipulate them

● The all Powerful pipe and other redirection operators


● What & Why

● How to use

● When to use

● Multiple Examples with other commands

● Shell Scripts (An Introduction)


● How to create and execute
Input/Output/Error Re-direction

In Bash and other Linux shells, when a program/command is executed, it


uses three standard I/O streams.

Each stream is represented by a numeric file descriptor:

0 - stdin, the standard input stream.

1 - stdout, the standard output stream.

2 - stderr, the standard error stream.

A file descriptor is just a number representing an open file.


Environment Variables
In Linux and Unix based systems environment variables are a set of
dynamic named values, stored within the system that are used by
applications launched in shells or sub-shells.

Environment variables allow you to customize how the system works


and the behaviour of the applications on the system.
Environment Variables

The names of the variables are case-sensitive. By convention,


environment variables should have UPPER CASE names.

When assigning multiple values to the variable they must be separated


by the colon : character.

There is no space around the equals = symbol.

Variables can be classified into two main categories, environment


variables, and shell variables.
Environment Variables vs Shell Variables

Environment variables are variables that are available system-wide


and are inherited by all spawned child processes and shells.

Shell variables are variables that apply only to the current shell
instance. Each shell such as zsh and bash, has its own set of internal
shell variables.
Commands available that allow you to list and set environment
variables in Linux:

env – The command allows you to run another program in a custom


environment without modifying the current one.

printenv – The command prints all or the specified environment variables.

set – The command sets or unset shell variables. When used without an
argument it will print a list of all variables including environment and
shell variables, and shell functions.

unset – The command deletes shell and environment variables.

export – The command sets environment variables.


Using the all powerful PIPE | in unix/linux
The pipe takes output from one command and uses it as input for another.

One of the main purposes of piping is filtering. You use piping to filter the contents
of a large file—to find a particular string or word, for example.

This purpose is why the most popular use for pipes involves the commands grep
and sort

A very simple example :

Let’s PIPE it

ls | wc -l

ls | tr “a-z” “A-Z”

You might also like