티스토리 뷰

반응형

Input and Output Redirection Introduce

stdin : 표준입력 0 (file descriptor)

stdout : 표준출력 1

stderr : 표준오류 2


Input Redirection <

$ mail user11 < color5

$ mail

.....

<color5 contents>

....

$ cat < "filename" equivalent $ cat "filename"



Output Redirection >(create, overwrite) , >>(create, append)

$ date > date.out

$ cat date.out

Thu Jun 22 10:23:14 KST 2017


$ id > date.out
$ cat date.out
uid=311(user11) gid=301(class) groups=302(class2)
$ cat date.out
uid=311(user11) gid=301(class) groups=302(class2)
Thu Jun 22 10:25:30 KST 2017


$ cat > catfile
have a good day          // type and ctrl + d
$ cat catfile
have a good day


$ cat < names >> catfile
$ cat catfile
have a good day
jupiter
venus
pluto
mercury
saturn
earth
uranus
mars
neptune


$ bdf >> diskusage

$ date >> diskusage

$ bdf >> diskusage

$ date >> diskusage

$ cat diskusage

Filesystem          kbytes    used   avail %used Mounted on

/dev/vg00/lvol3    1048576  235624  806624   23% /

/dev/vg00/lvol1    1835008  188960 1633272   10% /stand

...

/dev/vg00/lvol4    1179648   51384 1119464    4% /home

Thu Jun 22 10:28:01 KST 2017

Filesystem          kbytes    used   avail %used Mounted on

/dev/vg00/lvol3    1048576  235624  806624   23% /

/dev/vg00/lvol1    1835008  188960 1633272   10% /stand

/dev/vg00/lvol8    4587520  460424 4102440   10% /var

...

/dev/vg00/lvol5    10723328 5690896 4993184   53% /opt

/dev/vg00/lvol4    1179648   51408 1119440    4% /home

Thu Jun 22 10:28:23 KST 2017



Error Redirection 2>, 2>>   (with file descriptor number)

$ cp 2> cp.err

$ cat cp.err

Usage:  cp [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file target_file

        cp [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file ... target_directory

        cp [-f|-i] [-p] [-S] -R|-r [-e warn|force|ignore] source_directory ... target_directory

        cp -R[-H | -L | -P] [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file ... target

        cp -r[-H | -L | -P] [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file ... target



$ cp 2> /dev/null    //에러 issue를 무시하고싶을 때 null device로 넘김


What is a Filter?

Reads standard input and produces standard output 


wc - Word count ( -l,w,c)

$ wc

Have a good time

1 4 17

$ wc < catfile
10 13 77
$ wc < funfile
108 527 3081
$ wc funfile
108 527 3081 funfile

$ ps -e > ps.out

$ wc -l ps.out

202 ps.out


$ wc -l $(ls nam*)

9 names

9 names.cp

9 names.orig

27 total

$ cat names

jupiter

venus

pluto

mercury

saturn

earth

uranus

mars

neptune


sort - Alphabetical or Numerical Sort


$ sort sort.out    //Alphabetical sort

100
11
198
2
231
24
3
32
321
4
55
59
9
$ sort -n sort.out   //Numerical sort

2
3
4
9
11
24
32
55
59
100
198
231
321


$ sort -nt: -k 3 /etc/passwd  [ numerical, field :, key value=3, filename]

$ sort names -o names  [$ sort names > names does'nt work]
$ cat names
earth
jupiter
mars
mercury
neptune
pluto
saturn
uranus
venus

grep - Pattern matching (global regular expression print)

$ grep root /etc/passwd

root:9oTPronwCKT9w:0:3::/root:/sbin/sh

$ grep -v user /etc/passwd   (excluded user)
$grep -e user24 -e user23 /etcpasswd


반응형

'IoT 과정' 카테고리의 다른 글

HPUX - Process Control  (0) 2017.06.22
HPUX - Pipes  (0) 2017.06.22
HPUX - Quoting  (0) 2017.06.21
HPUX - File Name Generation  (0) 2017.06.21
HPUX - Shell Advanced Features  (0) 2017.06.21