You are on page 1of 10

Terminal :

Terminal is the IO media of linux , We can also say it is a IO device of LINUX.


Shell is a command interpreter/translator when click on terminal it gives shell prompt.
Dos --- command.com
Windows --- win.com
Linux --- bash shell
which shell u are working :echo $SHELL
chsh To change the shell in super user
chsh -> then password of su -> /bin/bash or /bin/csh
clear
pwd
touch
mkdir
rm
rm -f
rmdir
rm -rf
cd
cd ..
cd ../..
cd /
touch .raja hidden files
l.
ls -a
ls -al
tree
cat
ls
ls -l
ls .
ls ..
l.
cal -1
cal -3
cal -s
cal -m
cal -y
1
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

date +%a -- day


date +%A day full
date +%h/b month (oct)
date +%m month no
date +%d dd
date +%D mm/dd/yy
date +%y yy
date +%Y YYYY
date +%T time
date +%H Hour
date +%M Minute
date +%S second
date +%H:%M:%S time
date +%x mm dd yyyy
date +%X hh:mm:ss AM
date +%w day of the week
date +%W weak of the year
date +%u 1..7 (Monday as the first day)
date +%U week no of the year
init 0
reboot
shutdown -h now
shutdown -h 16:30 &
shutdown -c
cp <file1> <file2>
mv <file1><file2>
alias <name>=command
alias <name> command

Vi editor
vi editor is used to edit all kinds of plain text , But it especially useful for editing
VIM is the upgrade version of vi.

the programs.

Modes of VI editor :
VI editor has 3 modes :
1. Command mode
2. Input mode
3. Ex mode or Last line mode
Command mode :- The default mode of the editor is command mode . Where every key pressed is interpreter as
2
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

command to run the command.


Input Mode :- Every key pressed after switching actually shows up as a text. Pressing ESC in this mode takes vi
to command mode.
Ex mode :- The mode used to handle files and perform substitutions.
:w Saving your work
:q won;t work if buffer is not saved
:wq or :x or ZZ save and quit
:w <new file> or :w </home/lakshya/raja.c>-- just like save as in windows.
:w! -- Just above but overwrite existing file
vi provides the key h,j,k,l to move the cursor in the 4 directions .
J Moves up
k Moves Down
h Moves right
l Moves left
b Moves back to beginning of the word
w Moves forward to the beginning of the word.
e Moves forward to the end of the word
:n go to nth line
:10 go to 10th line
:5 -- go to 5th line
x Delete a single character
4x Delete 4 character
dw Delete one word
<n> dw Delete n word
dd Delete a single line
<n>dd Delete n no of line
p for paste
yy copy a sing line
<n>yy copy n lines
yw copy a single word
<n>yw copy n words
u Undo a single step
<n>u Undo before 10 step
.(dot) -- The command is used for redo
Substitutions :
search and replace (:s)
syntax :
address/source pattern/target pattern
The source pattern will is replaced with target pattern in all lines specified by
address. The address
3
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

can be 1 or pair of nos, separated by comma.


:1s/old/new :It will replace only the first line.
:2s/old/new :It will replace in the second line
:1,4,7s/old/new It will replace new word in the 1,4 and 7 line but not more then
one word in a single line.
:%s/old/new :It will replace new word in every line, But not more then one in
a single line.
:%s/old/new/g :- It will replace every where with the new word in the whole file.
:set number :- Go to specifed line
:set nonumber :- To remove the line no
:e <filename> -- Switch from one open file to another .
:/text :- To search a particular text
Wild card character :
* -- Any no of character including name
? -- A single character
echo *.c Display all files and folder
rm *.o Delete all files whose ending with *.o
ls 1* -- Shows all files whose starting is 1

vi raja
vi raja1
vi raja2
vi raja3
vi raja123
vi raja124
$ ls raja? -- Display the raja1,raja2,raja3 .... But whose starting with raja but
after raja only one character will be replaced
$ ls raja* -- Display the files raja1,raja2,raja3,raja123,raja124.....
Every file will be display whose starting with raja.
Note that * and ? Cannot identify those file whose are starting with .(dot) i,e hidden files .
want to access all the hidden files then
$ ls .???*

If u

If u want to select to some specific files i,e


$ ls raja[12]
then raja1 ,raja2 will come
U can also give range i,e
$ ls raja[1-5]
Here only raja1,raja2,raja3....raja5 will come.
4
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

$ more <filename> : Displaying the files with scrolling capabilities.


$ head :- Display lines from the beginning of the file.
By default it will prints 10 lines from beginning .
$ head -n : Display N no of lines from beginning.
$ tail :- Display the no of lines from end of file
By default it will prints 10 lines from beginning .
$ tail n :- Display the n no of lines from the end.
$ cmp <file1><file2>:- If differs then it shows the line no and byte no where it differs.
$ diff -a <file1> <file2> :- Find the difference between two files.
$ diff i <file1><file2> :- Ignore Change case
$ sort <file_name> :-To sort a file
$ sort r <fiel_name> :- To sort a file in reverse order..
Link file
There are 2 kinds of link file :
1. Hard link
2. Soft Link / Symbolic link

Hard Links
when a file is copied, then original and copy occupy separate space on disks.
Unix allows a file to have more then one name and yet maintain a single copy on
disks.
Unix allows a file to have more then one name and yet maintain a single copy on
disk . The file
said then said to have more then one name .& they all have the same INODE number.
Create a hard link :$ ln raja raja1 (Here raja1 should not exists)
$ls -li
To show the INODE number. U will find same INODE number of
raja and raja1.

Soft / symbolic Link :


create a soft link:$ ln -s rani rani1 (rani1 should not present)
$ ls -li
To show the INODE number and U will find different INODE
Number of rani rani1.
If something will change in the rani then it automatically change in the
rani1. Also above case it also happens .
5
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

But here if u delete the original file then the link file will be orphan .
It cannot open also . If u want to open then u have to create another file in
the same name of original then it opens.
$ echo $PATH :It will shows u whole path that command searched for execution.
$ whereis cat :Display the cat path where cat is present .
if u want to change the PATH , or want to not work this commands i,e cat
then :
u have to present in Super user
copy the contents of PATH
$ export PATH=<paste here>
now $ cat :- it will shows command not found
grep :grep searches the named input FILEs (or standard input if no files are named, or if a single hyphenminus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep
prints the matching lines.
file1
grep <text> <filename>
$ grep lakshya file1 :it will give the output , thsoe lines whose have lakshya word from file1
$ grep lakshya file1 file2 :it will give the output , those lines whose have lakshya word from
file1 file2
Note :if u want to give multiple word then give with (double quote).
$ grep -i lakshya file1
Ignores the case for matching .
$ grep -v lakshya file1
Does not display lines from matching pattern . That lines will
print will print which line have no word like lakshya .
$ grep -i -v lakshya file1
This will not also display also upper case lakshya.
$ grep -c lakshya file1
Count the no of times the word lakshya is present.
$ grep -L lakshya file1 file2 file3 .....
Displaying only the filename whose have the word lakshya
Basic regular expressions :
vi file1
6
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

sudhir Agarawal
manish aggarawal
v.k agrawal
$ grep [aA]g[ar][ar]wal file1
sudhir agarwal
v.k agrawal
why ?
The character class [aA] matches the letter a in both cases upper and
Lower case. And [ar][ar] matches in the 4 patterns i,e aa, ar, ra, rr.
So only 1st and 3rd case will be displayed.
$ who :shows who logged on
$ who am i :it will shows who is logging on
$ echo $ LOGNAME :only name will displayed who has logged on
$ du :It will shows the disk usages / estimate the file size
By default directory contains 4 bytes and file 0 bytes
$ du -a :Count for all files and direcories
$ du -b :It will shows in bytes format
$ du -total :It will displays the total no.
$df :Report file system disk space usages .
It shows all the drives
$ df -a :shows all file system
$df total :
shows the total of the disk usages in % format.
Compress and Decompress a file :
$ bzip2 <file_name> :- Compress bunzip file and extension should be .bz2
$ bunzip2 <filename.bz2> :- Decompress a file
$ gzip <file_name> :- Compress a file
$ gunzip <filename.gz> :- Decompress a file.
$ file * :- To show all the files
$ file a.c :- To show the specific file
7
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

Change permission :
We can give some permission (read,write ,execute) to a file or directory
In linux we can give the permission to any file or directory through chmod command
There are 2 ways to Assign/Remove the permission
1. Relative Mode
2. Absolute mode
Relative Mode to give permission:
U user
+ -- Assign permission
G group
- -- Removing Permission
O Others
a -- All (User , group and Others)
r Read
w Write
x Execute
$ chmod ugo+x <file_name>
$ chmod ugo+rwx <file_name>
$ chmod go-rwx <file_name>
$ chmod u-rwx <file_name>
$ chmod a-r <file_name>
$ chmod ugo+rwx <file1><file2><file3>
$ chmod ugo+rwx *
Absolute mode to give Permission :
Here each type of permission has assign a number as follows :Read r
Write w -Execute x --

4
2
1

$ chmod 000 <file_name>


$ chmod 111 <file_name>
$ chmod 222 <file_name>
$ chmod 444 <file_name>
$ chmod 777 <file1><file2><file3>..
$chmod 777 *
Recursively giving permission:It is possible to make chmod recursively to a particular directory .
Once we will give the permission to one directory it applies for every files and directories
$ chmod R 777 *

8
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

Remembers a file permissions only can be changed by the owner of the file , But
Administrator can changed any permission of any file.
$ mkfifo :- Make fifo files also known as pipe files.
Here one terminal input will be shown in the other file.
One Terminal :
Second Terminal :
$ mkfifo raja
$ echo lakshya> raja
Cat raja
Lakshya (prited here)

Some super user activity :


#vi //proc/cpuinfo :
To see the whole cpu information .
# file <executable file name>
To see the Microprocessor
# vim /etc/grub.conf or vim /boot/grub/grub.conf
It is used to show the grub information i,e
default time , Time out , Title
# /sbin/ifconfig eth0 192168.10.10
To set the IP address of a computer .
# /sbin/ifconfig eth0 192.168.10.15 netmask 255.255.255.0
To set the IP address and subnet mask.
# ping 192.168.10.15
send request to the remote computer which is inside a network
# ssh 192.168.10.15
If U want to access the remote user desktop in your computer
Note :- first physical connection should be established .
Passwd To change the password of own or other or root , U have to present in
in super user.
# passwd To change the passwd of own i,e who current login
# passwd <user_name> -- To change the password of any user.
# passwd <user_name> -i 15 For 15 days valid this password
#
#
#
#

useradd <user_name> -- To add a user


groupadd <group_name> -- To add or create a group.
userdel <user_name> -- To delete the user
groupdel <group_name> -- To delete the group

# init 0 To shut down the computer


# /sbin/fdisk -l To show the drive structure
9
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

10
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik

You might also like