[Linux] '/dev/null 2<&1'ÀÇ ÀǹÌ

   Á¶È¸ 14686   Ãßõ 0    

Summary존재하지않는 파일 'nofile.txt'을 cat 명령어로 지정하면 일반적으로 아래와 같은 결과를 얻는다. 즉, 실행결과와 에러를 표준 출력장치(/dev/tty)로 출력합니다.

[opradm@hvdev-tst-svr01 ~]$ cat nofile.txt
cat: nofile.txt: No such file or directory



'>'는 표준출력의 FD를 변경

[opradm@hvdev-tst-svr01 ~]$ cat nofile.txt > /dev/null
cat: nofile.txt: No such file or directory
[opradm@hvdev-tst-svr01 ~]$

'>'는 '1>'와 동일하다.




'2>&1 > /dev/null'과 '> /dev/null 2>&1'의 차이점

[opradm@hvdev-tst-svr01 ~]$ cat nofile.txt 2>&1 > /dev/null
cat: nofile.txt: No such file or directory
[opradm@hvdev-tst-svr01 ~]$ cat nofile.txt > /dev/null 2>&1
[opradm@hvdev-tst-svr01 ~]$


The&means file descriptor1. So2>&1redirects standard error to whatever standard output currently points at, while2>1redirects standard error into a file called1.

Also, the redirects happen in order. So if you say2>&1 >/dev/null, it redirects standard error to point at what standard output currently points at (which is probably a noop), then redirects stdout to /dev/null.

'> /dev/null 2>&1'은 '&> /dev/null'와 동일하다.


References

https://codingdog.tistory.com/entry/%EB%A6%AC%EB%88%85%EC%8A%A4-%EB%AA%85%EB%A0%B9%EC%96%B4-devnull-21-%EC%9D%98-%EC%9D%98%EB%AF%B8%EB%A5%BC-%EC%95%8C%EC%95%84%EB%B4%85%EC%8B%9C%EB%8B%A4

https://linuxhint.com/redirect-stdout-and-stderr-to-file/



Á¦¸ñPage 3/28
2019-10   8760   ±èÁØ¿¬
2019-10   8761   Á¦¿ÂÇÁ·Î
2021-05   8787   shipse
2023-12   8824   inquisitive
2024-11   8839   QS¿ÕÅëÅ°¼Õ¡¦
2020-07   8868   ÀüÁ÷P¿¬±¸¿ø
2021-01   9035   µö·¯´×¼­¹ö
2022-01   9066   ¹Ú¹®Çü
2014-03   9122   ÁÖ¿µÁø¿µ¾Æºü
2019-10   9243   ±èÁØ¿¬
2019-10   9245   ¿µ¿øÇÑÇõ½Å
2020-01   9253   ȲÁø¿ì
2021-02   9294   ĸƾ¾Æ¸Þ¸®Ä«³ë
2020-10   9415   wwwdjw
2014-03   9436   ÁÖ¿µÁø¿µ¾Æºü
2020-08   9500   tedious
2020-02   9542   ȲÁø¿ì
2021-10   9547   ¼ÛÁÖȯ
2024-09   9613   rpki
2022-02   9676   µö·¯´×¼­¹ö