Professional Documents
Culture Documents
SHELL SCRIPTING
COMMANDS
> (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
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.
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"
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
.bashrc main change karo:
PATH="bash wala folder ka location:${PATH}"
export PATH
to check if string is empty or not :
read -p "enter the string" str
if[ -z "$str" ];then
echo "empty"
fi
for searching of files.
Eg -e $myfile : file exist or not.
! -e $myfile : file not exist.
-d $myfile :
basename : used to extarct the name of the file.
VARIABLE
syntax:
variable_name="value want to assign"
eg:-
a=5
a="sachin"
when want to access the value of variable place $ sign before the name;
eg
a=5
echo $a or
or
echo ${a} :-here benfit is you can conacatinate the value to the variable.