Sunteți pe pagina 1din 74

UNIX

Contents:

 Introduction to UNIX

 UNIX Architecture

 UNIX Command

 The vi editor

 UNIX Shell Scripting


Introduction:

 Unix is a multitasking, multi-user computer operating


system.

 Unix was originally developed in 1969 by a group of


AT&T employees.

 Solaris Unix, AIX, HP Unix and BSD are few flavors of


UNIX.
UNIX Architecture

SREE NIPUNA SOFTWARE SOLUTIONS 4


UNIX Architecture
UNIX Architecture consists of two parts:

• Shell
• Kernal

Shell: A Unix shell is a command-line interpreter.

Kernal: A Unix kernel is a computer program that manages input/output


requests from software and translates them into data processing
instructions for the central processing unit and other electronic components
of a computer.

SREE NIPUNA SOFTWARE SOLUTIONS 5


UNIX Commands
 touch  wc
 ls  sort
 cat  uniq
 cp  cut
 mv  grep
 rm  head
 chmod  tail
 pwd  mkdir

SREE NIPUNA SOFTWARE SOLUTIONS 6


 rmdir  find
 cd  man
 who am i  nohup
 date  ps
 df  kill
 du  sed

SREE NIPUNA SOFTWARE SOLUTIONS 7


ls command
Syntax: ls <option>

 ls command list all the files and directories available in


current directory.

SREE NIPUNA SOFTWARE SOLUTIONS 8


ls -l
 List all files and directories from current directory
in long format.

SREE NIPUNA SOFTWARE SOLUTIONS 9


ls -a
 Display all files including hidden files from
current and parent directory.

SREE NIPUNA SOFTWARE SOLUTIONS 10


ls -A
 Display all files including hidden files from
current directory.

SREE NIPUNA SOFTWARE SOLUTIONS 11


ls [first letter(s) of file(s)]*
 Display all files/directories whose name
starts with any letter in pattern.

SREE NIPUNA SOFTWARE SOLUTIONS 12


ls [!first letter(s) of file(s)]*
 Don’t display all files/directories whose name
starts with any letter in pattern.

SREE NIPUNA SOFTWARE SOLUTIONS 13


ls –l -a
 Using multiple options at a time.

SREE NIPUNA SOFTWARE SOLUTIONS 14


ls -la
 Using multiple options at a time.

SREE NIPUNA SOFTWARE SOLUTIONS 15


touch
Syntax: touch <filename>
 touch command creates zero byte files.

SREE NIPUNA SOFTWARE SOLUTIONS 16


cat
Syntax: cat <filename>

 cat command displays the content of a file.

SREE NIPUNA SOFTWARE SOLUTIONS 17


cat
Syntax: cat <filename1> <filename2>

 cat command can displays the content of multiple files.

SREE NIPUNA SOFTWARE SOLUTIONS 18


cat
Syntax: cat > <filename>

• Creates a file with new file name and open for editing.
• Use ctrl+d keys to exit edit mode
• Opens an existing file in overriding mode.

Syntax: cat >> <filename>

• Creates a file with new file name and open for editing.
• Use ctrl+d keys to exit edit mode
• Opens an existing file in appending mode.

SREE NIPUNA SOFTWARE SOLUTIONS 19


cp
Syntax: cp <filename> <new filename>

 cp command copy data from one file to other.

SREE NIPUNA SOFTWARE SOLUTIONS 20


mv
Syntax: mv <filename><new filename>
 mv command move data from one file to other, old file not
exits.
 Rename a old file to new file.

SREE NIPUNA SOFTWARE SOLUTIONS 21


rm
Syntax: rm <option>
<filename>
 rm command remove files from current directory.
 rm command can’t remove directories.

SREE NIPUNA SOFTWARE SOLUTIONS 22


wc
Syntax: wc <option>
<filename>
• wc command displays number of new lines, words and
Number of bytes from file.

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 23
wc

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 24
wc

SREE NIPUNA SOFTWARE SOLUTIONS 25


wc –l <filename>

SREE NIPUNA SOFTWARE SOLUTIONS 26


sort
Syntax: sort <filename>
 Sort command will sort the data in file based on first
column.

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 27
uniq
Syntax: uniq <filename>
 uniq command remove the duplicates that are sequentially
present in a file.

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 28
uniq

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 29
uniq

Cont..
SREE NIPUNA SOFTWARE SOLUTIONS 30
pwd
Syntax: pwd

 pwd command display current directory.

SREE NIPUNA SOFTWARE SOLUTIONS 31


chmod
• chmod command changes the permissions
of a file.
Order of permissions in Unix:
Owner permissions: Actions the owner of the file can perform on the file.
Group permissions: A member of the group that a file belongs to, can perform
on the file.
Other permissions: What action all other users can perform on the file.

Permission Values:

1 - Execute
2 - Write
4 - Read

SREE NIPUNA SOFTWARE SOLUTIONS 32


chmod
Syntax: chmod <permissions> <filename>

SREE NIPUNA SOFTWARE SOLUTIONS 33


cut Syntax: cut <option> <filename>

 cut command to extract portion of text from


a file by selecting columns.

SREE NIPUNA SOFTWARE SOLUTIONS 34


cut Syntax: cut<option> <filename>
 cut command to extract portion of text from
a file by selecting columns.

SREE NIPUNA SOFTWARE SOLUTIONS 35


grep Syntax: grep <pattern> <file name>

• grep command search for a pattern


in a file and print.

SREE NIPUNA SOFTWARE SOLUTIONS 36


head Syntax: head <option> <file name>
 head command displays top 10 lines of file.

SREE NIPUNA SOFTWARE SOLUTIONS 37


tail Syntax: tail <option> <file name>

 tail command displays bottom 10 lines of file.

SREE NIPUNA SOFTWARE SOLUTIONS 38


head & tail
Syntax: head <option> <file name>|tail <option>

SREE NIPUNA SOFTWARE SOLUTIONS 39


mkdir
Syntax: mkdir <directory name>

 mkdir command is used to create directories.

SREE NIPUNA SOFTWARE SOLUTIONS 40


rmdir
Syntax: rmdir <directory name>

 rmdir command is used to remove directories.

SREE NIPUNA SOFTWARE SOLUTIONS 41


cd
Syntax: cd <directory name>

 cd command is used to move to other directories.

SREE NIPUNA SOFTWARE SOLUTIONS 42


du
Syntax: du

 du command gives disk usage details.

SREE NIPUNA SOFTWARE SOLUTIONS 43


du -h
Syntax: du -h

 du –h command gives disk usage details in


human understandable format.

SREE NIPUNA SOFTWARE SOLUTIONS 44


df
Syntax: df

 df command gives space availability on disk.

SREE NIPUNA SOFTWARE SOLUTIONS 45


df -h
Syntax: df -h

 df -h command gives space availability on disk in


human understandable language.

SREE NIPUNA SOFTWARE SOLUTIONS 46


ps
Syntax: ps

 ps command gives all processes details that are


currently running.

SREE NIPUNA SOFTWARE SOLUTIONS 47


ps -ef
Syntax: ps -ef

 ps –ef command gives all processes details that are


currently running along with user name.

SREE NIPUNA SOFTWARE SOLUTIONS 48


kill
Syntax: kill <option> <process id>

 kill command kills the process running with given id.

SREE NIPUNA SOFTWARE SOLUTIONS 49


date
Syntax: date

 date command displays current date.

SREE NIPUNA SOFTWARE SOLUTIONS 50


sed
Syntax: sed <operation> filename

 sed stands for stream editor. sed command is used


to modify data in files automatically.

SREE NIPUNA SOFTWARE SOLUTIONS 51


sed
Syntax: sed <operation> filename

SREE NIPUNA SOFTWARE SOLUTIONS 52


sed
Syntax: sed <operation> filename

• >sed 's/Informatica/Informatica9/2' file.txt

Replaces the second occurrence of the word.

• >sed 's/Informatica/Informatica9/g' file.txt

Replaces the second occurrence of the word.

SREE NIPUNA SOFTWARE SOLUTIONS 53


awk
awk is a powerful tool available in UNIX to process
rows and columns.

Syntax:
awk 'BEGIN {start_action} {action} END {stop_action}' filename

SREE NIPUNA SOFTWARE SOLUTIONS 54


Example to print first column

SREE NIPUNA SOFTWARE SOLUTIONS 55


nohup
Syntax: nohup <options> &

• nohup stands for no hang up. nohup is used to run


the process even after logout from a shell.

• $ nohup sh custom-script.sh &

• $ nohup sh custom-script.sh > custom-out.log &

SREE NIPUNA SOFTWARE SOLUTIONS 56


who am i
Syntax: who am i

• who am I gives the details of current user who is


logged into the UNIX machine.

SREE NIPUNA SOFTWARE SOLUTIONS 57


man
Syntax: man <command name>
• man command displays the manual for given command.

SREE NIPUNA SOFTWARE SOLUTIONS 58


find
Syntax: find
<location to search> <type to search> <value>
• find command displays the location of given file.

SREE NIPUNA SOFTWARE SOLUTIONS 59


The vi editor
• Stands for Visual Editor.

• Modes of operation
- Command mode
- Insert mode
- The ex command mode

SREE NIPUNA SOFTWARE SOLUTIONS 60


The vi editor

SREE NIPUNA SOFTWARE SOLUTIONS 61


The vi editor

SREE NIPUNA SOFTWARE SOLUTIONS 62


The vi editor

SREE NIPUNA SOFTWARE SOLUTIONS 63


The vi editor - commands
ZZ – write buffer to file and quit

:wq - write buffer to file and quit

:q! – Quit the editor without saving changes to the file.

:q – Quit if the changes written to file.

SREE NIPUNA SOFTWARE SOLUTIONS 64


Sample script

Following commands
Needs to be executed

SREE NIPUNA SOFTWARE SOLUTIONS 65


Output

SREE NIPUNA SOFTWARE SOLUTIONS 66


Name.sh

Output:

SREE NIPUNA SOFTWARE SOLUTIONS 67


Defining variables
Variable name=variable value

SREE NIPUNA SOFTWARE SOLUTIONS 68


Special variables
$0 - filename of the current script.

$nv - Arguments with which a script was invoked.($1,$2 and so on)

$# - Number of arguments supplied to a script

$* - All the arguments are double quoted.

$@ - All the arguments are individually double quoted.

$? - Exit status of the last command

$$ - Process number of the current shell

$! - Process number of the last background command

SREE NIPUNA SOFTWARE SOLUTIONS 69


Relational operators
-eq - Equal to

-ne - Not equal to

-gt - Greater than

-lt - less than

-ge - Greater than or equal to

-le - Less than or equal to

SREE NIPUNA SOFTWARE SOLUTIONS 70


If….else
if<condition>
<statement>
fi
if<condition>
<statement>
Else
<statement>
fi If<condition>
<statement>
elif<condition>
<statement>
Else
<statement>
fi
SREE NIPUNA SOFTWARE SOLUTIONS 71
If….else
#!/bin/sh
a=10
b=20

if [ $a == $b ]
then
echo "a is equal to b"
fi

if [ $a != $b ]
then
echo "a is not equal to b"
fi
SREE NIPUNA SOFTWARE SOLUTIONS 72
Some Syntaxes
• case...esac

• while command1;
do
Statement(s)

while command2;
do
Statement(s)
done

Statement(s)
done
SREE NIPUNA SOFTWARE SOLUTIONS 73
pmcmd Syntax

#!/usr/bin/bash
pmcmd startworkflow
-sv $INT_SVC
-d $INFA_DOMAIN
-u $INFA_USERID
-p $INFA_PWD
-f $INFA_FOLDER
-w $WORKFLOW_NAME

SREE NIPUNA SOFTWARE SOLUTIONS 74

S-ar putea să vă placă și