수색…


통사론

  • [시간 [-p]] [!] command1 [| 또는 | & command2] ...

비고

파이프 라인은 제어 연산자 중 하나에 의해 분리 간단한 명령의 순서입니다 | 또는 |& ( 소스 ).

| command1 의 출력을 command2 의 입력에 연결합니다.

|& 는 표준 출력과 command1 표준 오류를 command2 의 표준 입력에 연결합니다.

페이지가 매겨진 모든 프로세스 표시

ps -e | less

ps -e 는 모든 프로세스를 보여주고, 그 출력은 | 결과에 페이지 매김이 less .

| &

|& 는 첫 x 째 명령의 표준 출력과 표준 오류를 두 x 째 명령에 연결하고 | 첫 번째 명령의 표준 출력 만 두 번째 명령에 연결합니다.

이 예에서는 curl 통해 페이지가 다운로드됩니다. -v 옵션을 사용하면 curl stderr 몇 가지 정보를 쓰고, 다운로드 한 페이지는 stdout 기록됩니다. 페이지 제목은 <title></title> 사이에서 찾을 수 있습니다.

curl -vs 'http://www.google.com/' |& awk '/Host:/{print} /<title>/{match($0,/<title>(.*)<\/title>/,a);print a[1]}'

출력은 다음과 같습니다.

> Host: www.google.com
Google

그러나 | stdout 만 다음 명령으로 파이프되기 때문에 stderr 로 전송되는 정보가 더 많이 인쇄됩니다. 이 예에서는 마지막 행 (Google)을 제외한 모든 행이 curl 하여 stderr 로 전송되었습니다.

* Hostname was NOT found in DNS cache
*   Trying 172.217.20.228...
* Connected to www.google.com (172.217.20.228) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.google.com
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Sun, 24 Jul 2016 19:04:59 GMT
< Expires: -1
< Cache-Control: private, max-age=0
< Content-Type: text/html; charset=ISO-8859-1
< P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
< Server: gws
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: NID=82=jX0yZLPPUE7u13kKNevUCDg8yG9Ze_C03o0IM-EopOSKL0mMITEagIE816G55L2wrTlQwgXkhq4ApFvvYEoaWF-oEoq2T0sBTuQVdsIFULj9b2O8X35O0sAgUnc3a3JnTRBqelMcuS9QkQA; expires=Mon, 23-Jan-2017 19:04:59 GMT; path=/; domain=.google.com; HttpOnly
< Accept-Ranges: none
< Vary: Accept-Encoding
< X-Cache: MISS from jetsib_appliance
< X-Loop-Control: 5.202.190.157 81E4F9836653D5812995BA53992F8065
< Connection: close
< 
{ [data not shown]
* Closing connection 0
Google

명령의 연속 출력 수정

~$ ping -c 1 google.com # unmodified output
PING google.com (16.58.209.174) 56(84) bytes of data.
64 bytes from wk-in-f100.1e100.net (16.58.209.174): icmp_seq=1 ttl=53 time=47.4 ms
~$ ping google.com | grep -o '^[0-9]\+[^()]\+' # modified output
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
...

파이프 ( | )는 pingstdoutgrepstdin 에 연결하고 즉시 처리합니다. sed 와 같은 다른 명령은 stdin 을 버퍼링하는 것으로 기본 설정되어 있습니다. 즉, 아무 것도 인쇄하기 전에 데이터를 충분히 받아야하므로 처리가 지연 될 수 있습니다.



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow