You are on page 1of 33

sort

]sort [options] [files


] ,[files ".
:

-b
-d ( )
-f uppercase/lowercase
-m (
).
-n .
-ofile .file
-r .
-u .
+n n .

- sort
> cat data
World
whould
for
Fater
> sort data
Fater
World
for
whould
> sort data -f
Fater
for
whould
World
> sort data -r
whould
for
World
Fater

> ls -l
total 6
-rw------- 1 romano root
-rw------- 1 romano 368
-rw------- 1 romano 368
-rw------- 1 romano 368
> ls -l | sort +4 > lsdata
> more lsdata
total 6
-rw------- 1 romano 368
-rw------- 1 romano root
-rw------- 1 romano root
-rw------- 1 romano 368
-rw------- 1 romano 368
>

23 Nov 8 23:09 data


243 Nov 8 23:12 ex1
428 Nov 8 23:22 ex2
0 Nov 10 13:30 ex3

0 Nov 10 13:30 ex3


0 Nov 10 13:31 lsdata
23 Nov 8 23:09 data
243 Nov 8 23:12 ex1
428 Nov 8 23:22 ex2

grep
]grep [options] [^]word [files
] [files word
.
"
,
>grep "It is" file
:
-c
-h ,
-i uppercase/lowercase
-l
-n
-v , word
-w word ( )
- ^word word

- grep
more file1
>> ls
Arik ! ex2
ex/
file1
file2 ex4 typescript
file2~
Have
you
news ?
ex1
>
cat file1
ex3heard
file2file1~
not|! grep
, listen
>If ls
Arik
ex!
> cat you
file2heard news ?
ex/
Have
Tomorrow
we! have a new exam !
ex1
If
not , listen
So we cannot
go toaRan's
birthday
ex2
Tomorrow
we have
new exam
! .
By we
. cannot go to Ran's birthday .
ex3
So
> grep
-v -n new * | sort | head -3
ex4
By
.
! ex| grep new | sort -d onews
>file1:1:Arik
ls
cat| grep
file2 file1
-c
not , listen !
5file1:3:If
>
more news
file2:2:So
we cannot
Have
you heard
newsgo
? to Ran's birthday .
Tomorrow we have a new exam !

uniq
]]uniq [options] [file1 [file2
file1 ,
( file2 ,file2
).

:
-c .
-d ,
.
-u .
-n n- ( )
:

- uniq
> more file3
one
two
two
three
three
three
> uniq file3 list
> more list
one
two
three
>

> more names


Uri
Dan
Uri
Elena
Alex
Ofra
Uri
Ofra
> sort names | uniq -d
Ofra
Uri
>

cut
]cut options [files
cut
.files

:
-c list
, list -
-f list
, list -
-dc . -f
. .c
><tab

- cut
,
>
cat
file1
, .
a11 a12 a13 a14 a15
b21 b22 b23 b24 b25
c31 c32 c33 c34 c35
-c1-3,5,8-10 file1
> cut
cat file2
a11a a1
a11:a12:a13
b21b b2
b21:b22
c31c
c3 c33
c31 c32
cut file2
-d" " |-f2,4
file1 f1
> cat
"cut -d":
a12 a14
a11
b22 b24
b21
c32 c32
c34 c33
c31
> cat file2 | cut -d":" f3
a13
c31 c32 c33

wc
]wc [options] [files
,

:
-c .
-l .
-w .

- wc
> wc -l phonebook
12 phonebook
> wc -w bible
333333 bible
> wc -c data
8843 data

:
<# lines> <# words> <# chars> filename
<wc data
<193 1808 8843 data
:

> wc data phonebook


193
1808
8843 data
12
100
654 phonebook
295
1908
9497 total

printf
printf format strings
string .format
.
:

- %s
.strings
- %[-]m[.n]s
m ,
(
) .n -
.-

- printf
> echo $HOME
/home/rotics
< printf My files are in %s\n $HOME
My files are in /home/rotics
< printf number is : %10.5s 123456789a
number is:
12345
< printf number is : #%-10.3s# %s\n "123456789a" xxx
number is: #123
# xxx
< printf My files are in %s\n $HOME my PC
My files are in /home/rotics
My files are in my PC

(%s) strings

CSHELL

Unix
. shell
Shell

Shell

" prompt
login ( prompt < ) . prompt
shell-
, shell - ,
. shell prompt

> echo hello
hello
<

Shells in UNIX

Shell . Unix
shell . ,
" "
.
shells ,kshell ,cshell :Unix
bourne shell.
cshell shell.

SHELL-
Shell
shell - :
shell-
. , shell- " " :

- Alias
- History

- File name expansion
-

) (script shell
. ""
. shell ,
"" .
C- ,

Command Aliases
alias <new name> <command name>
command name new name
> alias del rm
> del file2
.file2
: " alias , .aliases - alias
> alias
del rm
:
alias cdex2 "cd ~mtm/public/0506b/ex2"

history

- !!
- !vi vi -
- history .
" shell- "
history
- !<n> n
Shell-

>set history=100
100

File name expansions

UNIX- , -
Shell .
, Shell-

Wildcards

*
?
a[rxz]b -> arb, axb, azb
][ [ ] -

File name expansions

*.c
c
**AD
AD
> gcc -c *.c
.c

?<rm prog1.
prog1.-
]file[13
file - 1 .3
]file[A-Za-z13
file -
-" 1 .3


>set <variable> = <value
variable .value -
Value



:cshell .
$ -

>$<variable
variable
> set v = abc
> echo $v
abc
> set v = 123
> echo $v
123


cshell -

'@' .
.set
@
>@i=3
> echo $i
3
> @ i = $i + 1
> echo $i
4
> @ i ++
> echo $i
5
> set v = 12
> @ v = $v + $i
> echo $v
17

:
'@'
. 2-3+4 -5 3


,cshell - ,
( )
( " ).
"> set a = "abc def ghe
> echo $a
abc def ghe


a ] a[i i-
a
cshell- a ( 1- .)0-
)> set v = (123 def ghi
> echo $v
123 def ghi
]> echo $v[2
def
> set v[3] = ww
> echo $v
123 def ww

cshell ( ) :
)> set v[3] = (12 abc 34
:
set: syntax error


a ,
} ${#a
] a[m-n - , m - n -
] a[-n - , n-
] a[m- - , m-
]*[ a

> set a = ( aa bb cc dd ee )
> echo $#a
5
>echo $a[3-]
cc dd ee
>echo $a[2-4]
bb cc dd
> echo $a[-3]
aa bb cc

shift a ,a
.
> set v = ( go to the beach )
> echo $v[1]
go
> shift v
> echo $v[1]
to
> echo $v
to the beach

. :
> set a = abc def ghi
]> echo $a[1
abc def ghe
. ,
]> echo $a[2
a: Subscript out of range.
" .

)>set b = ($a
>echo $b
abc def ghe
]>echo $b[2
def
.
:
> set b = 123
> set a = ${b}4
> echo $a
1234

Command substitution
cshell - , ,

(
backquotes ,)backticks

`> echo you have `ls | wc -l` files in `pwd
you have 43 files in /home/rotics
(
ls
)/home/rotics
- echo

Command substitution

> cat list


file1 file2 file3
> cat file1
you are in file1
Buy a Selkom phone
> cat file2
you are in file2
buy Motorola Pelephone
> cat file3
you are in file3
Im Grimberg Matzliah Ata Marviach
> cat `cat list`
you are in file1
Buy a Selkom phone
you are in file2
buy Motorola Pelephone
you are in file3
Im Grimberg Mazliah Ata Marviach

CSHELL-
C-Shell - Macro Processor- , :

prompt

,

, C-Shell :

.

.alias

:C-shell
: . Tab-

: .
,
:


( redirection )pipeline
.1 (" !)
History Substitution
.2 .
( )

> echo AAA


AAA
!! > echo
echo echo AAA
echo AAA
.3 alias .alias substituion
.4 variable substitution
.5 File name substitution
.6 .command substitution )` back-quoted string (`...


. :

. Shell-
( )
:
).(full path name
C-Shell .
.path

C-shell " Shell


.

)(history
)(set/unset/shift
)alias (alias/unalias
)working directory (cd
( )


I/O redirection
I/O redirection " .Shell-
://
,I/O redirection
" Shell -
Pipeline
pipeline - " | .
, Shell standard output
pipeline standard input

shell- . tab

( )
shell
.


` - )(back quote
" - )(double quote
' - )(single quote
back quotes .command substitution shell-
back quotes - .
. shell-

single quotes double quotes Shell
( ) ."
Shell - .

double quoted -
string . single quoted
string :

> set a = AAA


< echo a=$a
a=AAA
< echo a=$a
a=$a

.single or double quoted strings


back quotes double quote
shell .