Sie sind auf Seite 1von 67

UNIX

SREE NIPUNA SOFTWARE


SOLUTIONS

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

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

UNIX Commands
touch

wc

ls

sort

cat

uniq

cp

cut

mv

grep

rm

head

chmod

tail

pwd

mkdir

SREE NIPUNA SOFTWARE


SOLUTIONS

rmdir
cd
who
date
df
du

am i
find
man
nohup
ps
kill
sed
SREE NIPUNA SOFTWARE
SOLUTIONS

ls command
Syntax:

ls <option>

ls command list all the files and directories available in


current directory.

SREE NIPUNA SOFTWARE


SOLUTIONS

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

SREE NIPUNA SOFTWARE


SOLUTIONS

ls -a
Display all files including hidden files.

SREE NIPUNA SOFTWARE


SOLUTIONS

10

ls -la
Using multiple options at a time.

SREE NIPUNA SOFTWARE


SOLUTIONS

11

touch
Syntax:

touch <filename>

touch command creates zero byte files.

SREE NIPUNA SOFTWARE


SOLUTIONS

12

cat
Syntax:

cat <filename>

cat command displays the content of a file.

SREE NIPUNA SOFTWARE


SOLUTIONS

13

cat
Syntax:

cat <filename1> <filename2>

cat command displays the content of a file.

SREE NIPUNA SOFTWARE


SOLUTIONS

14

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

15

cp
Syntax:

cp <filename> <new filename>

cp command copy data from one file to other.

SREE NIPUNA SOFTWARE


SOLUTIONS

16

mv
Syntax:

mv <filename> <new filename>

mv command move data from one file to other, old file


exits.
Rename a old file to new file.

SREE NIPUNA SOFTWARE


SOLUTIONS

17

rm

rm <option> <filename>
rm command remove files from current directory.
Rm command cant remove directories.
Syntax:

SREE NIPUNA SOFTWARE


SOLUTIONS

18

wc

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

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

19

wc

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

20

wc

SREE NIPUNA SOFTWARE


SOLUTIONS

21

wc l <filename>

SREE NIPUNA SOFTWARE


SOLUTIONS

22

sort

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

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

23

uniq

uniq <filename>
uniq command remove the duplicates that are sequenti
present in a file.
Syntax:

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

24

uniq

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

25

uniq

SREE NIPUNA SOFTWARE


SOLUTIONS

Cont..

26

pwd
Syntax:

pwd

pwd command display current directory.

SREE NIPUNA SOFTWARE


SOLUTIONS

27

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 perf
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

28

chmod
Syntax:

chmod <permissions> <filename>

SREE NIPUNA SOFTWARE


SOLUTIONS

29

cutSyntax: cut <option> <filename>


cut command to extract portion of text from
a file by selecting columns.

SREE NIPUNA SOFTWARE


SOLUTIONS

30

grep
Syntax: grep <pattern> <file name>
grep command search for a pattern
in a file and print.

SREE NIPUNA SOFTWARE


SOLUTIONS

31

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

SREE NIPUNA SOFTWARE


SOLUTIONS

32

tailSyntax: tail <option> <file name>


tail command displays bottom 10 lines of file.

SREE NIPUNA SOFTWARE


SOLUTIONS

33

head & tail


Syntax:

head <option> <file name>|tail <option>

SREE NIPUNA SOFTWARE


SOLUTIONS

34

mkdir
Syntax:

mkdir <directory name>

mkdir command is used to create directories.

SREE NIPUNA SOFTWARE


SOLUTIONS

35

rmdir
Syntax:

rmdir <directory name>

rmdir command is used to remove directories.

SREE NIPUNA SOFTWARE


SOLUTIONS

36

cd
Syntax:

cd <directory name>

cd command is used to move to other directories.

SREE NIPUNA SOFTWARE


SOLUTIONS

37

du
Syntax:

du

du command gives disk usage details.

SREE NIPUNA SOFTWARE


SOLUTIONS

38

du -h
Syntax:

du -h

du h command gives disk usage details in


human understandable format.

SREE NIPUNA SOFTWARE


SOLUTIONS

39

df
Syntax:

df

df command gives space availability on disk.

SREE NIPUNA SOFTWARE


SOLUTIONS

40

df -h
Syntax:

df -h

df -h command gives space availability on disk in


human understandable language.

SREE NIPUNA SOFTWARE


SOLUTIONS

41

ps
Syntax:

ps

ps command gives all processes details that are


currently running.

SREE NIPUNA SOFTWARE


SOLUTIONS

42

ps -ef
Syntax:

ps -ef

ps ef command gives all processes details that are


currently running along with user name.

SREE NIPUNA SOFTWARE


SOLUTIONS

43

kill
Syntax:

kill <option> <process id>

kill command kills the process running with given id

SREE NIPUNA SOFTWARE


SOLUTIONS

44

date
Syntax:

date

date command displays current date.

SREE NIPUNA SOFTWARE


SOLUTIONS

45

sed
Syntax:

sed <operation> filename

sed stands for stream editor. sed command is used


to modify data in files automatically.

SREE NIPUNA SOFTWARE


SOLUTIONS

46

sed
Syntax:

sed <operation> filename

SREE NIPUNA SOFTWARE


SOLUTIONS

47

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

Replace all the occurrence of the pattern in a li

SREE NIPUNA SOFTWARE


SOLUTIONS

48

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

49

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

50

man

man <command name>


man command displays the manual for given comman
Syntax:

SREE NIPUNA SOFTWARE


SOLUTIONS

51

find

find <location to search> <type to search> <va


find command displays the location of given file.

Syntax:

SREE NIPUNA SOFTWARE


SOLUTIONS

52

The vi editor
Stands for Visual Editor.
Modes of operation
- Command mode
- Insert mode
- The ex command mode

SREE NIPUNA SOFTWARE SOLUTIONS

53

The vi editor

SREE NIPUNA SOFTWARE


SOLUTIONS

54

The vi editor

SREE NIPUNA SOFTWARE


SOLUTIONS

55

The vi editor

SREE NIPUNA SOFTWARE


SOLUTIONS

56

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

57

Sample script
c

om

en

Following commands
Needs to be executed

SREE NIPUNA SOFTWARE


SOLUTIONS

58

Output

SREE NIPUNA SOFTWARE


SOLUTIONS

59

Name.sh

Output:

SREE NIPUNA SOFTWARE


SOLUTIONS

60

Defining variables
Variable name=variable value

SREE NIPUNA SOFTWARE


SOLUTIONS

61

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

62

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

63

If.else
if<condition>
<statement>
fi
if<condition
>
<statement
>
Else
<statement
>
fi

If<condition>
<statement>
elif<condition
>
<statement>
Else
<statement>
SREE NIPUNA SOFTWARE
SOLUTIONS
fi

64

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"
SREE NIPUNA SOFTWARE
SOLUTIONS
fi

65

Some Syntaxes
case...esac
while command1;
do
Statement(s)
while command2;
do
Statement(s)
done
Statement(s)
done
SREE NIPUNA SOFTWARE
SOLUTIONS

66

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

67

Das könnte Ihnen auch gefallen