You are on page 1of 15

Basic shell and Linux




purpose of this document is to provide

the audience with a fast and simple
introduction to using the Linux command
shell and some of its basic utilities.

Special characters
unique symbols { .}{..}[] ..etc




Represents 0 or
more characters
in a filename

Can be used to
represent a
range of values,
e.g. [0-9], [A-Z],

Redirect the
output of a
command onto
the end of an
existing file
echo .airtel 5551234. >>

(? )

separator as
above, but only
runs the second
command if the
first one
finished without
Example: cd
/var/logs && less

Execute a
command in the
background, and
immediately get
your shell back.
Example: find /
-name core >

Represents a
single character
in a filename

(; )
Allows you to
execute multiple
commands on a
single line.
Example: cd
/var/log ; less

Redirect the
output of one
command into
Example: ls |

The Linux Directory Layout


Essential command binaries

(programs) are stored here (bash,
ls, mount,
tar, etc.)


Process information pseudofilesystem. An interface to kernel

data structures.


Static files of the boot loader.


The root (super user) home



Device files. In Linux, hardware

devices are accessed just like
other files, and
they are kept under this directory


Essential system binaries (fdisk,

init, etc).


Host-specific system configuration



Temporary files. All users have

permission to place temporary
files here


Location of users' personal home

directories (e.g. /home/bob).


The base directory for most

shareable, read-only data
(programs, libraries,
documentation, and much more).


Essential shared libraries and

kernel modules.


Most user programs are kept

here (cc, find, du, etc.).


Program source code. E.g. The

Linux Kernel, source RPMs, etc.


Architecture-independent data
(icons, backgrounds,
documentation, term info,
man pages, etc.).

The Command PATH:

Most common commands are located in your shell's PATH,

meaning that you can just type the name of the program to
execute it.

Your shell's PATH variable includes the most common

program locations, such as
/bin, /usr/bin, /usr/X11R6/bin, and others.

NOTE :- EDITOR=/usr/bin/vim; export EDITOR

Export PATH ; refer env variables (unset to
remove env variables)

Commands to navigate :
pwd , cd (dir, ~,-, ..) , ls lrt (-S,-R ,-Sr) ,mkdir,
rmdir, ls ,touch, file

Search commands
Find , locate , which , who

, w

find <dirs> [conditions] [exec cmd {} \;]

-size n[cwbkMG] b 512-byte blocks (default), c in bytes, w
two-byte words, k kilobyte
#find . -name "rc.conf" -exec chmod +r '{}' \;
#find . -exec grep "" '{}' \; -print
This command will search in the current directory and all sub
directories. All files that contain the string will have their path printed
to standard output.


find -perm 755 # matches if mode is exactly 755

find -size 1024k # exactly 1 MB

find -size +1024k # over 1 MB

find -size -1024k # less than 1 MB

find ~ empty # find empty regular files or directories

find -size +102400k -ok gzip {} \; # OK prompted before

[root@localhost ~]# find -size +102400k -ok gzip {} \;
< gzip ... ./current/RHEL6.4-20130116.3-Server-SRPMS-DVD1.iso > ? n
< gzip ... ./current/rpm/cool/images/install.img > ? n
< gzip ... ./current/rpm/RHEL6.4-20130116.3-Server-x86_64-DVD1.iso > ? n
< gzip ... ./current/linux-2.6.32-355.el6.tar > ? n

Compression Utilities
gzip v file(s)
v option displays compression percentage, original file
replaced only regular files are compressed
gzip d filename.gz uncompress the file
bzip2 v file (compression)
bunzip2 v file
gunzip filename.gz (uncompress the file)
gunzip c filename.gz
list contents of the compressed file in STDOUT, the file

to create an archive file

tar cvf archive_name files

c create a new archived

v produces verbose messages

f archive file name

j use bzip2 compression

z use gzip compression

Example :compress :- tar cvf fold-A.tar fold-A/

Untar a package of

pkg.tar.gz format

# tar zxvf < pkg.tar.gz >

Usage of multiple commands

# echo "This system's name is $(hostname)"
# echo current date is `date`
# echo Area: $[ $X * $Y ] # equivalent to $[$X*$Y]
# echo Your cost: \$8.00
# find / -name myfile\*

[root@localhost ramya]# hostname
[root@localhost ramya]# echo "This system's name is $(hostname)"
This system's name is localhost.localdomain
[root@localhost ramya]# echo current date is `date`
current date is Tue Jan 15 17:23:16 EST 2013

Vi editor Default commands

Move by character: Arrow Keys, h, j, k, l (Move by word: w, b)

Move by sentence: ), (

Move by paragraph: }, {

Jump to line x (:x) , Jump to end: G

Insert mode (i) begins insert mode at the cursor

A append to end of line , ^ insert at beginning of line

o insert new a line (below). O insert new line (above

Use [:set nu][:set nonu][:set ic][:set noic]

Ex::1,5s/cat/dog/g # search in lines 1 to 5 and replace all

words in any line
:%s/cat/dog/gi # the whole file

Handy shortcuts
# up(down)_key scrolls through command history
# <something-incomplete> TAB completes path/file_name
# Ctrl+a # cursor to beginning of command line
# Ctrl+e # cursor to end of command line
# Ctrl+d # delete character under cursor
# Ctrl+k # cut line from cursor into kill buffer
# Ctrl+y # paste content from Ctrl k
# Ctrl+J # Join two sentences

Linux basics

Uname (-a , -r )

lsb_release a

Rpm package installation

& /etc/release

ivh,qa,ql,e [nodeps]
Install (-ivh) , list (-qa) , remove (-e) , to list
individual files (-ql rpm name)
Kernel modules
lsmod , modinfo , modprobe
Logs :Dmesg , /var/log ,ethtool& ifconfig
SMBIOS :Dmidecode t <bios> <system><memory><processor>

#[root@localhost linux-]# lspci

00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v3 Processor DRAM

Controller (rev 02)

00:1d.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset

Family USB EHCI #1 (rev 02)

00:1f.0 ISA bridge: Intel Corporation 8 Series/C220 Series Chipset Family

Desktop Super SKU LPC Controller (rev 02)

#[root@localhost linux-]# lspci s 00:1d.0 xv

00:1d.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB EHCI #1
(rev 02) (prog-if 20 [EHCI])

Subsystem: Hewlett-Packard Company Device 330d

Flags: bus master, medium devsel, latency 0, IRQ 20

Memory at facd0000 Capabilities: [50] Power Management version 2

Capabilities: [58] Debug port: BAR=1 offset=00a0

Capabilities: [98] PCI Advanced Features

Kernel driver in use: ehci_hcd

00: 86 80 26 8c 46 00 90 02 02 20 03 0c 00 00 00 00

10: 00 00 cd fa 00 00 00 00 00 00 00 00 00 00 00 00

20: 00 00 00 00 00 00 00 00 00 00 00 00 3c 10 0d 33

30: 00 00 00 00 50 00 00 00 00 00 00 00 07 01 00 00 (32-bit, non-prefetchable) [size=1K]

Thank you
We are Open, Transparent and Honest
We are Collaborative
We Demand Excellence
We Honour our Commitments

2009 MphasiS
The information contained herein is subject to change without notice.