You are on page 1of 8

LINUX COMMANDS

SHELL SCRIPTING
> (redirect) :- it use to use the output in other command.
eg: echo "hello there" > new.txt
output:
cat new.txt
hello there

>> (append) : work like redirect but add data to existing file without overriding.
echo "hello there sachin" > new.txt
output:
cat new.txt
hello there
hello there sachin

concatinate two files :


eg: cat file1.txt file2.txt
{one file after one file}
**it is important when we want to copy data of two file into one file.
tail : display content from end:-
syntax:
tail -(no. of line want to display) filename
head : display content from start:-
syntax:
head -(no. of line want to display) filename
pipe :- using of one command output in input of second command.
syntax:-
command1 | command2
eg:-
let assume a folder a
:- ls a/ | less
find : use to find file .
syntax:-
find (location were to find) (name of file want to find)
eg:-
find a sac.txt
**in output it return the path of the file.
syntax:- find (location were to find) -name (name of file want to find)
eg:-
find a -name sac.txt
**in output it return the path of the file.

syntax:-
find (location were to find) -type d
eg:-
find a -type d
**in output it return the path of all the directories present inside that location.

grep :- use to grab the word from any file.this return the word if the given word
appear in it.
syntax :-
grap (word) (file name)
**this is a case sensitive.

but if we use:- "grep -i" instead of "grep" it ignore cases.


grep -v (word) filename :- it return the all data which is NOT containing the word
in command.

AWK
awk :-works for the table related data.
syntax:
awk '{print}' filename or awk '{print $0}' filename: to print complete data of the file.
awk '{print $1 $2}' filename : to concatinate data of colume 1 and 2 and print.
awk '{print $1,$2}' filename : to print data of coloumn 1 and 2 without concatination.
awk 'NR==row number {print $0}' filename: to print perticular row.
awk '{print $NR}' filename : to print thr last row.
awk '{print $(NR-i)}' filename: to print perticular row from the last.
awk 'NR==i,NR==j{print $0}' filename :from i to j is the limit of row to print.
awk 'NR==i;NR==j{print $0}' filename : only print i and j row.
case 2 :- let the data is written in continuous format with a PERTICULAR SEPRATOR to print
according to seprator :
syntax:
awk -F "seprator" '{print }' filename:
for all above case operation just add :- -F "seprator"
case 3 :- when we have to find a perticular word in the table.
syntax :
awk '/word which want to find/{print}' filename : all data will display which have that word in
row.
awk '/word which want to find| second word/{print}' filename :- | or operator
awk '$i~/word which want to find/{print}' filename : for perticular row .
**
awk '{print length($i)}' filename :-length of perticular columne of each row.
SUDO
if we want to edit a file which have not the permission to edit. so here we have
two way
i)change the owner
ii)sudo :-command before any command.to over rite the permission.

example:- sudo nano filename.txt


*if we create the file in root folder.

test :- sudo bash :- it changes the root folder name.


owner change :
syntax:
sudo chown new_ownername filename
change group :
syntax:
sudo chgrp new_groupname filename

To change the permission in linux we use :-


chmod
u :-user r :-read
g :-guest w :-write
o :-other x :-exicutable
syntax :-
chmod u=rw filename :- when we want to give user permission of read and write.

shotcut for giving exicutable permission :


syntax
chmod +x filename

UNIX Login:
if we declare a variable in terminal and after re opening of the terminal we are
not able to access the variable value
because it is temprory in the terminal .
to use the value of that variable we have to create that in the ".bashrc" file of the
linux which run very first just
after the opening of the terminal.
** when you want to know the place were command is stored use which command

synatax

which command_name

eg :-

which ls

which pwd

I) .bashrc main change karo:


PATH="bash wala folder ka location:${PATH}"
export PATH
Ii)to check if string is empty or not :
read -p "enter the string" str
if[ -z "$str" ];then
echo "empty"
fi
III) for searching of files.
eg
-e $myfile : file exist or not.
! -e $myfile : file not exist.
-d $myfile : directory exist or not

IV) basename : used to extarct the name of the file.

You might also like