728x90
Write the output of a command to a file, Basically 10 commonly used ways
출처: Byte Commander
Overview:
Please note that the n.e. in the syntax column means "not existing".
There is a way, but it's too complicated to fit into the column. You can find a helpful link in the List section about it.

List:
- command > output.txt
- The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.
- command >> output.txt
- The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
- command 2> output.txt
- The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.
- command 2>> output.txt
- The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
- command &> output.txt
- Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, it gets overwritten.
- command &>> output.txt
- Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, the new data will get appended to the end of the file..
- command | tee output.txt
- The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, it gets overwritten.
- command | tee -a output.txt
- The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
- (*)
- Bash has no shorthand syntax that allows piping only StdErr to a second command, which would be needed here in combination with tee again to complete the table. If you really need something like that, please look at "How to pipe stderr, and not stdout?" on Stack Overflow for some ways how this can be done e.g. by swapping streams or using process substitution.
- command |& tee output.txt
- Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, it gets overwritten.
- command |& tee -a output.txt
- Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
반응형
'linux' 카테고리의 다른 글
xxd - make a hexdump or do the reverse. (0) | 2021.05.06 |
---|---|
RPM PBone 검색엔진, Debian, Ubuntu 패키지 검색. (0) | 2021.05.01 |
Debian, Ubuntu, RedHat Linux(CentOS, Fedora) 배포판 확인방법 (0) | 2021.04.28 |
Debian date NTP 시간 동기화 (0) | 2021.04.28 |
Debian, Ubuntu, RedHat Linux(CentOS, Fedora) 한글 Locale 설치 (0) | 2021.04.28 |