명령어: grep, cat
키워드: 공백, 주석 제거
사용처: 리눅스에서 공백, 주석 없이 파일을 보고 싶을 때
리눅스에서는 config 파일의 내용을 자주 들여다 봅니다. 하지만 주석 및 공백의 내용이 많이 들어가 있는 경우 내용확인이 불편할 경우가 있는데요. 공백과 주석을 제거해서 보면 현재 구성된 설정값을 한 눈에 볼 수 있습니다.
사용방법
$ grep -Ev "^$|#" /파일경로/파일명
$ cat /파일경로/파일명 | grep -Ev "^$|#"
아래 짧은 logrotate.conf 을 가지고 실습해보세요.
- logrotate.conf 전체내용
# cat /etc/logrotate.conf
# see "man logrotate" for details
# global options do not affect preceding include directives
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may also be configured here.
grep 명령어로 공백/주석 없이 파일 보기
- 공백 && 주석 제거 1
# grep -Ev "^$|#" /etc/logrotate.conf
weekly
rotate 4
create
dateext
include /etc/logrotate.d
- 공백 && 주석 제거 2
# cat /etc/logrotate.conf | grep -Ev "^$|#"
weekly
rotate 4
create
dateext
include /etc/logrotate.d
- 주석만 제거
# cat /etc/logrotate.conf | grep -Ev "#"
weekly
rotate 4
create
dateext
include /etc/logrotate.d
- 공백만 제거
# cat /etc/logrotate.conf | grep -Ev "^$"
# see "man logrotate" for details
# global options do not affect preceding include directives
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may also be configured here.