0% found this document useful (0 votes)
14 views24 pages

Essential Unix/Linux Commands Guide

OS Lab EXP1

Uploaded by

examsaimlds
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)
14 views24 pages

Essential Unix/Linux Commands Guide

OS Lab EXP1

Uploaded by

examsaimlds
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

EXERCISE-1

1. a) Study of Unix/Linux general purpose utility command list -


man,who,cat, cd, cp, ps, ls, mv, rm, mkdir, rmdir, echo, more, date, time,
kill, history, chmod, chown, finger, pwd, cal, logout, shutdown.
Command Man
Syntax $ man [command] [specific file]
Description “man” stands for manual which is a reference book of Linux Operating System.
It is similar to HELP in popular software.
Examples $ man ls

This command displays the all the information about “ls” command including
its syntax, description and usage.

Command Who
Syntax $ who - [option]
Option Description
-a Same as -b -d –login -p -r -t -T -u
-b Time of last system boot
-d Print dead processes
-H Print line of column headings
-l Print system login processes
-m Only hostname and user associated with stdin
-p Print active processes spawned by init
-q All login names and number of users logged on
-r Print current runlevel
-t Print last system clock change
-T Add user’s message status as +, – or ?
-u List users logged in
Description “who” command displays who all are logged onto the network.

“who am i” command displays information about the current user.


Examples 1) $ who

root console july 2 10:30

aaa tty01 july 2 10:40

bbb tty02 july 2 10:55

2) $ who - H
3) $ who - u
4) $ who – b

Command Cat
Syntax $ cat [argument] [specific file]
Description “cat" is short for concatenate. This command is used to create, view and
concatenate files.
Examples 1) $ cat /etc/passwd

This command displays the "/etc/passwd" file on your screen.

2) $ cat /etc/profile

This command displays the "/etc/profile" file on your screen. Notice that some of the
contents of this file may scroll off of your screen.

3) $ cat file1 file2 file3 > file4

This command combines the contents of the first three files into the fourth file.

Command cd, chdir


Syntax $ cd [name of directory you want to move to]

Description "cd" stands for change directory. It is the primary command for moving around
the filesystem from current directory to the specified directory.
Examples 1) $ cd /usr

This command moves you to the "/usr" directory. "/usr" becomes your
current working directory.

2) $ cd /usr/fred

Moves you to the "/usr/fred" directory.

3) $ cd /u*/f*

Moves you to the "/usr/fred" directory - if this is the only directory matching
this wildcard pattern.

4) $ cd

Issuing the "cd" command without any arguments moves you to your home directory.

5) $ cd -

Using the Korn shell, this command moves you back to your previous working
directory. This is very useful when you're in the middle of a project, and keep
moving back-and-forth between two directories.

Command Cp
Syntax $ cp [options] file1 file2

$ cp [options] files directory


Options -b backup files that are about to be overwritten or removed
-i interactive mode; if destination exists, you'll be asked whether to overwrite the file
-p preserves the original file's ownership, group, permissions, and timestamp
Description The "cp" command is used to copy files and directories. Note that when using the cp
command, you must always specify both the source and destination of the file(s) to
be
copied. The cp command copies both text and binary files.
Examples 1) $ cp .profile .[Link]

This command copies your ".profile" to a file named ".[Link]".

2) $ cp /usr/fred/Chapter1 .

This command copies the file named "Chapter1" in the "/usr/fred" directory to the
current directory. This example assumes that you have write permission in the
current directory.

3) $ cp /usr/fred/Chapter1 /usr/mary

This command copies the "Chapter1" file in "/usr/fred" to the directory named
"/usr/mary". This example assumes that you have write permission in the
"/usr/mary" directory.

4) $ cp file1 file2

This command simply copies file1 to file2.

Command Ps
Syntax $ ps [options]
Description The "ps" command (process statistics) lets you check the status of processes
that are running on your Unix system. It gives a snapshot of the current
process’s
attribute.
Examples 1) $ ps

PID TTY TIME CMD

476 tty03 00:00:01 login


659 tty03 00:00:01 sh

684 tty03 00:00:00 ps

The ps command by itself shows minimal information about the processes you are
running. Without any arguments, this command will not show information about other
processes running on the system.

2) $ ps -f

The -f argument tells ps to supply full information about the processes it displays. In
this example, ps displays full information about the processes you are running.

3) $ ps -e

The -e argument tells the ps command to show every process running on the system.

4) $ ps -ef

The -e and -f arguments are normally combined like this to show full information
about every process running on the system. This is probably the most often-used form
of the ps command.

5) $ ps -ef | more

Because the output normally scrolls off the screen, the output of the ps -ef command
is often piped into the more command. The more command lets you view one
screenful of information at a time.

6) $ ps -fu fred

This command shows full information about the processes currently being run by
the user named fred (the -u option lets you specify a username).

Command Ls
Syntax $ ls [options] [names]
Description "ls" stands for list. It is used to list information about files and directories.
Examples 1) $ ls

This is the basic "ls" command, with no options. It provides a very basic listing of the
files in your current working directory. Filenames beginning with a decimal are
considered hidden files, and they are not shown.

2) $ ls -a

The -a option tells the ls command to report information about all files,
including hidden files.

3) $ ls -l

The -l option tells the "ls" command to provide a long listing of information about the
files and directories it reports. The long listing will provide important information
about file permissions, user and group ownership, file size, and creation date.

4) $ ls -al

This command provides a long listing of information about all files in the current
directory. It combines the functionality of the -a and -l options. This is probably the
most used version of the ls command.

5) $ ls -al /usr

This command lists long information about all files in the "/usr" directory.

6) $ ls -alr /usr | more

This command lists long information about all files in the "/usr" directory, and all sub-
directories of /usr. The -r option tells the ls command to provide a recursive listing of
all files and sub-directories.

7) $ ls -ld /usr

Rather than list the files contained in the /usr directory, this command lists information
about the /usr directory itself (without generating a listing of the contents of /usr). This
is very useful when you want to check the permissions of the directory, and not the
files the directory contains.

Command Mv
Syntax $ mv [options] sources target
Options -b backup files that are about to be overwritten or removed.
-i interactive mode; if destination file exists, you'll be asked whether to overwrite the
file or not.
Description The "mv" command is used to move and rename files.
Examples 1) $ mv Chapter1 [Link]

This command renames the file "Chapter1" to the new name "[Link]".

2) $ mv Chapter1 garbage

This command renames the file "Chapter1" to the new name "garbage". (Notice that
if "garbage" is a directory, "Chapter1" would be moved into that directory).

3) $ mv Chapter1 /tmp

This command moves the file "Chapter1" into the directory named "/tmp".

4) $ mv tmp [Link]

Assuming in this case that tmp is a directory, this example renames the directory
tmp to the new name [Link].

Command Rm
Syntax $ rm [options] files
Options -d, --directory
unlink FILE, even if it is a non-empty directory (super-user only)

-f, --force
ignore nonexistent files, never prompt

-i, --interactive
prompt before any removal

-r, -r, --recursive


remove the contents of directories recursively

-v, --verbose
explain what is being done
Description The "rm" command is used to remove files and directories. (Warning - be very
careful when removing files and directories!)
Examples 1) $ rm [Link]

This command deletes the file named "[Link]" (assuming you have
permission to delete this file).
2) $ rm Chapter1 Chapter2 Chapter3

This command deletes the files named "Chapter1", "Chapter2", and "Chapter3".

3) $ rm -i Chapter1 Chapter2 Chapter3

This command prompts you before deleting any of the three files specified. The -i
option stands for inquire. You must answer y (for yes) for each file you really want
to delete. This can be a safer way to delete files.

4) $ rm *.html

This command deletes all files in the current directory whose filename ends with
the characters ".html".

5) $ rm index*

This command deletes all files in the current directory whose filename begins with
the characters "index".

6) $ rm -r new-novel

This command deletes the directory named "new-novel". This directory, and all of
its' contents, are erased from the disk, including any sub-directories and files.

Command Grep
Syntax $ grep [options] regular expression [files]
Options -i case-insensitive search
-n show the line# along with the matched line
-v invert match, e.g. find all lines that do NOT match
-w match entire words, rather than substrings
Description Think of the "grep" command as a "search" command (most people wish it was
named "search"). It is used to search for text strings within one or more files.
Examples 1) $ grep 'fred' /etc/passwd

This command searches for all occurrences of the text string 'fred' within the
"/etc/passwd" file. It will find and print (on the screen) all of the lines in this file
that contain the text string 'fred', including lines that contain usernames like "fred" -
and also "alfred".

2) $ grep '^fred' /etc/passwd

This command searches for all occurrences of the text string 'fred' within the
"/etc/passwd" file, but also requires that the "f" in the name "fred" be in the first
column of each record (that's what the caret character tells grep). Using this more-
advanced search, a user named "alfred" would not be matched, because the letter
"a" will be in the first column.

3) $ grep 'joe' *

This command searches for all occurrences of the text string 'joe' within all files of
the current directory.

Command Mkdir
Syntax $ mkdir [options] directory name
Description The "mkdir" command is used to create new directories (sub-directories).
Examples 1) $ mkdir tmp

This command creates a new directory named "tmp" in your current directory. (This
example assumes that you have the proper permissions to create a new sub-directory in
your current working directory.)

2) $ mkdir memos letters e-mail

This command creates three new sub-directories (memos, letters, and e-mail) in the
current directory.

3) $ mkdir /usr/fred/tmp

This command creates a new directory named "tmp" in the directory "/usr/fred". "tmp"
is now a sub-directory of "/usr/fred". (This example assumes that you have the proper
permissions to create a new directory in /usr/fred.)

4) $ mkdir -p /home/joe/customer/acme

This command creates a new directory named /home/joe/customer/acme, and creates


any intermediate directories that are needed. If only /home/joe existed to begin with,
then the directory "customer" is created, and the directory "acme" is created inside of
customer.

Command Rmdir
Syntax $ rmdir [options] directories
Description The "rmdir" command is used to remove directories. (Warning - be very careful
when removing files and directories!)
Examples $rmdir customer

This command deletes the directory named "customer" (assuming you have
permission to delete this directory).

Command Echo
Syntax $ echo [options] IDs
Description The “echo” command is used to display a line of text, or messages. It takes zero, one r
more arguments.
Examples 1) $ echo hi

This displays a “hi” msg on the terminal

2) $ echo “Hello World”

Two words can be displayed using echo by placing them in [Link] output of the
above command will be – Hello World

Command More
Syntax $ more [filename]
Description This command is used to display the contents of a file. It allows us to set the output
page size and pauses at the end of each page to allow us to read the file.
Examples $ more chapter1

Command Date
Syntax $ date [- options]
Description The “date” command prints the date and time. Using this command, the user ca
display the current date along with the time nearest to the second.
Examples $ date

This displays the system’s current date and time in IST.

Command Time
Syntax $ time [options]
Description This command is used to know the resource usage. It runs a program or command
with given arguments, generates a timing statistics about the program run and directs
this statistics report to the standard output.
Examples $ time

Real 0m0.000s

User 0m0.000s

Sys 0m0.000s

Command Kill
Syntax $ kill [options] IDs
Description The command “kill” ends one or more process IDs. In order to do this you must own
the process or be designated a privileged user. To find the process ID of a certain job
use “ps” command.
Examples $ kill 456

Here 456 is the PID of the process.

Command History
Syntax $ history
Description The command “history” is used to display the history of previous executed
commands. When used without options, it displays the command history list with line
numbers.
Examples $ history

1 pwd

2 date

3 cal

Command Chmod
Syntax $ chmod<permissions><filename>
Description The “chmod” command is used to change permissions of a file after its creation. Only
the Owner or Super User can change file permissions.
Examples $ chmod u+x sample

$ls - l sample

-r w x r --r –sample

Command Chown
Syntax $ chown <new_owner><filename>
Description The command “chown” is used to change the file’s owner and group. Only the
owner can change the major attributes of a file. Sometimes it is necessary to
change the ownership of a file.
Examples $ls -l sample

-rwxr--r-x 1 dhoni July 19 11:55 sample

$chown virat sample

$ls -l sample

-rwxr--r-x 1 virat July 19 11:55 sample.


Command Finger
Syntax $ finger
Description It is a user information lookup command. The “finger” command displays
information about the system users.
Examples $finger

Login Name TTY Idle When

Where root superuser tty01 1:24

Mon 14:00

501 ABD tty02 0:20 Mon 15:40 [Link]

502 Federer tty03 2:12 Mon 15:40 [Link]

Command Pwd
Syntax $ pwd
Description "pwd" stands for print working directory. It displays your current position in the
UNIX filesystem. i.e., the location of the current directory in the directory
sttucture. There are no options (or arguments) with the "pwd" command
Examples $ pwd

It is simply used to report your current working directory.

Command Cal
Syntax $ cal <month><year>
Description This command is used to print the calendar of a specific month or a specific
year.
Examples $ cal 05 2021

Command Logout
Syntax $ logout
Description This command is used to logout from the shell.
Examples $ logout

Command Shutdown
Syntax $shutdown
Description This command is used to shutting down the system in a safe way.
Examples $ shutdown
EDIT Mode

- Generally for moving the cursor and deleting stuff.


In the Edit Mode, the keys do not type letters, but do other actions such as cursor
movement, deletions, copying lines, etc.

Letter Simple Cursor Movement


h Moves cursor left one space
j Moves cursor down one line
Note: the Arrow keys
k Moves cursor up one line do work locally, but
sometimes mess up
l Moves cursor right one space
over a network.
Fast Cursor Movement
w Moves the cursor a full word at a time to the right
b Moves the cursor back to the left a word at a time
^ Moves the cursor to the front of a line
$ Moves the cursor to the end of a line
<ctrl>f Moves the cursor forward a full page of text at a time
<ctrl>b Moves the cursor backward a full page of text at a time
Modifying Text
x Deletes the character under the cursor
dd Deletes the line where the cursor is located (typed twice!)
n dd Delete n consecutive lines ( n is an integer)
r Replaces the character under the cursor with the next thing typed
J Joins current line with the one below (Capital J!)
u Undoes the last edit operation
<ctrl> r Redo (Undoes the last undo operation)
Cut and Paste Operations
yy Copies or yanks a line ( 5yy yanks 5 lines)
p Puts the yanked text on the line below the cursor (lower case p)
P Puts the yanked text above the current line (capital P)
Note: If vi is already in the input mode, text from that or another window may
be highlighted using the left mouse button, and copied into place by pressing
the middle mouse button.

COMMAND Mode - For interacting with the operating system.


To enter the Command Mode, a colon " : " must precede the actual command.

Letter Action
: r <file> reads a file from disk into the vi editor
: w <file> writes current file to disk
: wq writes the file and quits vi
: q! quits without writing (useful if you've messed up!)

Starting with vi editor:

Syntax: $vi filename

Editing the file:

- Open the file using $ vi filename

- To add text at the end of the file, position the cursor at the last character of the file.

- Switch from command mode to text input mode by pressing ‘a’.

- Here ‘a’ stands for append.

- Inserting text in the middle of the file is possible by pressing ‘i’.

- The editor accepts and inserts the typed character until Esc key is pressed.

Saving text:

:w – save the file and remains in edit mode

:wq – save the file and quits from edit mode

:q – quit without changes from edit mode

Quitting vi:

Press zz or ‘:wq’ in command mode.

b) Study of Bash shell, Bourne shell and C shell in Unix/Linux operating


system.
Types of Shells:The Shells are 4 types
a) The Bourne Shell (sh)

b) The C Shell (csh)

c) The Korn Shell (ksh)

d) The Bourne-Again Shell (bash)

Study of Bash shell

Bourne again shell (Bash) is a free Unix shell that can be used in place of the Bourne shell. It
is a complete implementation of the IEEE Portable Operating System Interface for Unix (POSIX)
and Open Group shell specification.

Bash is basically a command processor that typically runs in a text window, allowing the user to
type commands that cause actions. It can read commands from a file, called a script. Like all
Unix shells it supports the following:

 File name wildcarding


 Piping
 Hear documents
 Command execution
 Variables and control structures for condition testing and iteration

Bash was written for the GNU Project by Brian Fox. It is called Bourne again shell for many
reasons, the first being that it is the open-source version of the Bourne shell and the second as a
pun on the concept of being born again. Its acronym is also a description of what the project did,
which was to bash together sh, csh, and ksh features.

A Unix shell is a command-line interpreter that provides users with a basic user interface. It
allows users to communicate with the system through a series of commands that are typed in the
command-line window. There are no buttons or pop-up windows in a shell, simply lots and lots of
text.

Essentially, Bash allows users of Unix-like systems to control the innermost components of
the operating system using text-based commands.

Bash has a number of extensions and runs on Unix-like operating systems like Linux and
Mac OS X. It was ported to Windows through the Subsystem for UNIX-based Applications (SUA)
and by POSIX emulation using Cygwin or MSYS. It can even be used in MS-DOS.

Study of Bourne shell


A Bourne shell (sh) is a UNIX shell or command processor that is used for scripting. It was
developed in 1977 by Stephen Bourne of AT&T and introduced in UNIX Version 7, replacing the
Mashey shell (sh).

The Bourne shell is also known by its executable program name, "sh" and the dollar
symbol, "$," which is used with command prompts. A Bourne shell interprets and executes user
defined commands and provides command based programming abilities. A Bourne shell enables
the writing and executing of shell scripts, which provide basic program control flow, control over
input/output (I/O) file descriptors and all key features required to create scripts or structured
programs for shell.

A Bourne shell also executes commands and functions that are predefined or integrated;
files that search or follow a command path, as well as text file commands.

The Bourne shell's architectural code was implemented in subsequent versions of UNIX
shell, including Bourne Again shell (Bash), Korn shell and Zsh shell.

Study of C shell
The C shell was created by Bill Joy while he was a graduate student at UC Berkeley in the
late 1970s. It was first released as part of the 2BSD Berkeley Software Distribution of Unix in
1978.

The C shell gets its name from its syntax, which is intended to resemble the C
programming language.

The C shell (csh) is a command shell for Unix-like systems that was originally created as
part of the Berkeley Software Distribution (BSD) in 1978. Csh can be used for entering commands
interactively or in shell scripts. The shell introduced a number of improvements over the earlier
Bourne shell designed for interactive use. These include history, editing operations, a directory
stack, job control and tilde completion. Many of these features were adopted in the Bourne Again
shell (bash), Korn shell (ksh) and in the Z shell (zsh). A modern variant, tcsh, is also very popular.

The C shell introduced features that were intended to make it easier to use interactively at
the command line, though like other shells it is capable of being scripted. One of the most notable
features was command history. Users can recall previous commands they have entered and either
repeat them or edit these commands. Aliases allow users to define short names to be expanded into
longer commands. A directory stack lets users push and pop directories on the stack to jump back
and forth quickly. The C shell also introduced the standard tilde notation where "~" represents a
user's home directory.

Most of these features have been incorporated into later shells, include the Bourne Again
shell, the Korn shell and the Z shell. A popular variant is tsch, which is the current default shell on
BSD systems, as well as on early versions of Mac OS X.
d) Study of Unix/Linux file system (tree structure).

Unix File System


Unix file system is a logical method of organizing and storing large amounts of information in a
way that makes it easy to manage. A file is a smallest unit in which the information is stored. Unix
file system has several important features. All data in Unix is organized into files. All files are
organized into directories. These directories are organized into a tree-like structure called the file
system.

Files in Unix System are organized into multi-level hierarchy structure known as a directory tree.
At the very top of the file system is a directory called “root” which is represented by a “/”. All
other files are “descendants” of root.

Directories or Files and their description –

 / :The slash / character alone denotes the root of the filesystem tree.
 /bin :Stands for “binaries” and contains certain fundamental utilities, such as ls or cp,
which are generally needed by all users.
 /boot :Contains all the files that are required for successful booting process.
 /dev :Stands for “devices”. Contains file representations of peripheral devices and pseudo-
devices.
 /etc :Contains system-wide configuration files and system databases. Originally also
contained “dangerous maintenance utilities” such as init,but these have typically been
moved to /sbin or elsewhere.
 /home :Contains the home directories for the users.
 /lib :Contains system libraries, and some critical files such as kernel modules or device
drivers.
 /media :Default mount point for removable devices, such as USB sticks, media players, etc.
 /mnt :Stands for “mount”. Contains filesystem mount points. These are used, for example,
if the system uses multiple hard disks or hard disk partitions. It is also often used for
remote (network) filesystems, CD-ROM/DVD drives, and so on.
 /proc :procfs virtual filesystem showing information about processes as files.
 /root :The home directory for the superuser “root” – that is, the system administrator. This
account’s home directory is usually on the initial filesystem, and hence not in /home
(which may be a mount point for another filesystem) in case specific maintenance needs to
be performed, during which other filesystems are not available. Such a case could occur,
for example, if a hard disk drive suffers physical failures and cannot be properly mounted.
 /tmp :A place for temporary files. Many systems clear this directory upon startup; it might
have tmpfs mounted atop it, in which case its contents do not survive a reboot, or it might
be explicitly cleared by a startup script at boot time.
 /usr :Originally the directory holding user home directories,its use has changed. It now
holds executables, libraries, and shared resources that are not system critical, like the X
Window System, KDE, Perl, etc. However, on some Unix systems, some user accounts
may still have a home directory that is a direct subdirectory of /usr, such as the default as
inMinix. (on modern systems, these user accounts are often related to server or system use,
and not directly used by a person).
 /usr/bin : This directory stores all binary programs distributed with the operating system
not residing in /bin, /sbin or (rarely) /etc.
 /usr/include :Stores the development headers used throughout the system. Header files are
mostly used by the #include directive in C/C++ programming language.
 /usr/lib :Stores the required libraries and data files for programs stored within /usr or
elsewhere.
 /var :A short for “variable.” A place for files that may change often – especially in size, for
example e-mail sent to users on the system, or process-ID lock files.
 /var/log :Contains system log files.
 /var/mail :The place where all the incoming mails are stored. Users (other than root) can
access their own mail only. Often, this directory is a symbolic link to /var/spool/mail.
 /var/spool :Spool directory. Contains print jobs, mail spools and other queued tasks.
 /var/tmp :A place for temporary files which should be preserved between system reboots.
e) Study of .bashrc, /etc/bashrc and Environment variables.

An important Unix concept is the environment, which is defined by environment


variables. Some are set by the system, others by you, yet others by the shell, or any program
that loads another program.

A variable is a character string to which we assign a value. The value assigned could be a number,
text, filename, device, or any other type of data.

For example, first we set a variable TEST and then we access its value using the echo command −

$TEST="Unix Programming"
$echo $TEST

It produces the following

result. Unix Programming

Note that the environment variables are set without using the $ sign but while accessing them
we use the $ sign as prefix. These variables retain their values until we come out of the shell.

When you log in to the system, the shell undergoes a phase called initialization to set up the
environment. This is usually a two-step process that involves the shell reading the following files

 /etc/profile
 profile

The process is as follows −

 The shell checks to see whether the file /etc/profile exists.


 If it exists, the shell reads it. Otherwise, this file is skipped. No error message is displayed.
 The shell checks to see whether the file .profile exists in your home directory. Your
home directory is the directory that you start out in after you log in.
 If it exists, the shell reads it; otherwise, the shell skips it. No error message is displayed.

As soon as both of these files have been read, the shell displays a prompt −

This is the prompt where you can enter commands in order to have them executed.

Note − The shell initialization process detailed here applies to all Bourne type shells, but some
additional files are used by bash and ksh.
The .profile File

The file /etc/profile is maintained by the system administrator of your Unix machine and
contains shell initialization information required by all users on a system.

The file .profile is under your control. You can add as much shell customization information
as you want to this file. The minimum set of information that you need to configure includes −

 The type of terminal you are using.


 A list of directories in which to locate the commands.
 A list of variables affecting the look and feel of your terminal.

You can check your .profile available in your home directory. Open it using the vi editor
and check all the variables set for your environment.

Environment Variables
Following is the partial list of important environment variables. These variables are set
and accessed as mentioned below −

[Link]. Variable & Description


DISPLAY
1
Contains the identifier for the display that X11 programs should use by default.
HOME
2
Indicates the home directory of the current user: the default argument for the cd built-in
command.
IFS
3
Indicates the Internal Field Separator that is used by the parser for word splitting after
expansion.
LANG

4 LANG expands to the default system locale; LC_ALL can be used to override this. For
example, if its value is pt_BR, then the language is set to (Brazilian) Portuguese and the
locale to Brazil.
LD_LIBRARY_PATH

5 A Unix system with a dynamic linker, contains a colonseparated list of directories that the
dynamic linker should search for shared objects when building a process image after exec,
before searching in any other directories.
PATH
6
Indicates the search path for commands. It is a colon-separated list of directories in
which the shell looks for commands.
PWD
7
Indicates the current working directory as set by the cd command.
RANDOM
8
Generates a random integer between 0 and 32,767 each time it is referenced.
SHLVL
9
Increments by one each time an instance of bash is started. This variable is useful
for determining whether the built-in exit command ends the current session.
TERM
10
Refers to the display type.
TZ
11
Refers to Time zone. It can take values like GMT, AST, etc.
UID
12
Expands to the numeric user ID of the current user, initialized at the shell startup.
MAIL
13
This variable holds the absolute pathname of the file where user’s mail is
kept. Usually the name of this file is the user’s login name
SHELL
14
This variable contains the name of the users shell program in the form of
absolute pathname. System administrator sets the default shell If
required, user can change it
TERM
15
This variable holds the information regarding the type of the terminal being
used. If TERM is not set properly, utilities like vi editor will not work

Following is the sample example showing few environment variables −

$ echo $HOME
/root

$ echo $DISPLAY

$ echo $TERM
xterm
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/home/amrood/bin:/usr/local/bin
$

.bashrc
.bashrc file is automatically executed when new terminal(shell) is opened.
Purpose of bashrc file:
 You can export environment variables(So there is no need to export environment variable
every time)
 You can define aliases
 You can provide the path for cross compiler
 You can add your own script which can start automatically whenever new shell is opened.
 You can change the history length

/etc/bashrc
 Like .bash_profile you will also commonly see a .bashrc file in your home directory. This file
is meant for settingcommand aliases and functions used by bash shell users.
 Just like the /etc/profile is the system wide version of .bash_profile. The /etc/bashrc for Red
Hat and /etc/[Link] in Ubuntu is the system wide version of .bashrc.

Interestingly enough in the Red Hat implementation the /etc/bashrc also executes the shell scripts
within /etc/profile.d but only if the users shell is a Interactive Shell (aka Login Shell)

You might also like