일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 우분투
- 도커 설치
- netplan
- docker
- passwd
- 패스워드초기화
- sudoer
- Ubuntu 22.04
- dmesg
- python
- sysstat
- 리눅스 기본명령어
- 도커
- nvidia-docker
- 모니터링
- CUDA
- 엔비디아 도커
- TAIL
- nvidia
- uname
- ethtool
- 우분투 22.04 패스워드 초기화
- V100
- grub
- 우분투패스워드초기화
- NGC
- ifconfig
- Cat
- A100
- TensorFlow
- Today
- Total
또이리의 Server Engineer
리눅스 파일보기 명령어 - cat, more, less, head, tail 본문
리눅스 파일보기 명령어 - cat, more, less, head, tail
리눅스 파일보기 명령어 - 기본 명령어 cat, more, less, head, tail
안녕하세요. 오늘은 리눅스에서 기본적으로 파일의 내용을 확인할 때 사용하는 기본 명령어에 대해서 알아보겠습니다. 대부분의 리눅스 OS에서 사용이 가능하니 알아 두시면 도움이 돼 실 겁니다.
서버 엔지니어 입장에서는 무조건 알고 있어야 되는 명령어라 생각합니다.
일단 cat, more, less, head, tail을 단독으로 사용할 수 있습니다.
그리고,
cat /경로/파일 | more, less, head, tail과 같은 형태로 사용할 수도 있습니다.
아래 화면과 함께 설명드리겠습니다.
리눅스 파일보기 명령어 cat
명령어를 사용하여
/var/log/syslog 파일을 살펴보도록 하겠습니다.
root@ubuntu:~# cat /var/log/syslog
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'iscsi_tcp'
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'ib_iser'
Nov 17 23:30:09 ubuntu systemd[1]: Starting Flush Journal to Persistent Storage...
Nov 17 23:30:09 ubuntu systemd[1]: Started udev Kernel Device Manager.
Nov 17 23:30:09 ubuntu systemd[1]: Started Apply Kernel Variables.
Nov 17 23:30:09 ubuntu systemd[1]: Started Set the console keyboard layout.
Nov 17 23:30:09 ubuntu systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local Encrypted Volumes.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Commit a transient machine-id on disk...
Nov 17 23:30:09 ubuntu systemd[1]: Starting ebtables ruleset management...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Set console font and keymap...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Tell Plymouth To Write Out Runtime Data...
Nov 17 23:30:09 ubuntu systemd[1]: Starting AppArmor initialization...
Nov 17 23:30:09 ubuntu systemd[1]: Started Flush Journal to Persistent Storage.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Create Volatile Files and Directories...
Nov 17 23:30:09 ubuntu systemd[1]: Started Tell Plymouth To Write Out Runtime Data.
Nov 17 23:30:09 ubuntu systemd[1]: Started Create Volatile Files and Directories.
~~~~~
Mar 28 21:21:10 ubuntu systemd[1]: Started Message of the Day.
Mar 28 21:21:21 ubuntu systemd[1]: Created slice User Slice of root.
Mar 28 21:21:21 ubuntu systemd[1]: Starting User Manager for UID 0...
Mar 28 21:21:21 ubuntu systemd[1]: Started Session 1 of user root.
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers).
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on GnuPG cryptographic agent and passphrase cache.
Mar 28 21:21:21 ubuntu systemd[1321]: Reached target Paths.
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on REST API socket for snapd user session agent.
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on GnuPG network certificate management daemon.
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Mar 28 21:21:21 ubuntu systemd[1321]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Mar 28 21:21:21 ubuntu systemd[1321]: Reached target Sockets.
Mar 28 21:21:21 ubuntu systemd[1321]: Reached target Timers.
Mar 28 21:21:21 ubuntu systemd[1321]: Reached target Basic System.
Mar 28 21:21:21 ubuntu systemd[1]: Started User Manager for UID 0.
Mar 28 21:21:21 ubuntu systemd[1321]: Reached target Default.
Mar 28 21:21:21 ubuntu systemd[1321]: Startup finished in 44ms.
Mar 28 21:21:22 ubuntu systemd[1]: Started Session 3 of user root.
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:540: gracefully waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:542: done waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon stop requested to wait for socket activation
Mar 28 21:21:53 ubuntu systemd[1]: Started Daily apt download activities.
Mar 28 21:21:53 ubuntu systemd[1]: Starting Daily apt upgrade and clean activities...
Mar 28 21:21:54 ubuntu systemd[1]: Started Daily apt upgrade and clean activities.
Mar 28 21:21:54 ubuntu systemd[1]: Startup finished in 4.128s (kernel) + 49.800s (userspace) = 53.928s.
Mar 28 21:36:40 ubuntu systemd[1]: Starting Cleanup of Temporary Directories...
Mar 28 21:36:40 ubuntu systemd[1]: Started Cleanup of Temporary Directories.
root@ubuntu:~#
이렇게 cat 명령어만 사용해서 파일을 보게 되면 쉴 새 없이 화면이 지나가며 파일내용을 전부 출력하게 됩니다.
파일의 내용이 간단하다면, 파일 내용을 충분히 파악할 수 있겠지만 페이지가 많다면, 쭉쭉 넘어가서 파일의 전체 내용을 확인할 수가 없습니다.
이때 사용하는 명령어가 more, less, head, tail 명령어입니다.
리눅스 파일보기 명령어 more
자, 이제 위의 cat 명령어 대신 more 명령어를 사용해 보겠습니다.
more /var/log/syslog
root@ubuntu:~# more /var/log/syslog
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'iscsi_tcp'
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'ib_iser'
Nov 17 23:30:09 ubuntu systemd[1]: Starting Flush Journal to Persistent Storage...
Nov 17 23:30:09 ubuntu systemd[1]: Started udev Kernel Device Manager.
Nov 17 23:30:09 ubuntu systemd[1]: Started Apply Kernel Variables.
Nov 17 23:30:09 ubuntu systemd[1]: Started Set the console keyboard layout.
Nov 17 23:30:09 ubuntu systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local Encrypted Volumes.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Commit a transient machine-id on disk...
Nov 17 23:30:09 ubuntu systemd[1]: Starting ebtables ruleset management...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Set console font and keymap...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Tell Plymouth To Write Out Runtime Data...
Nov 17 23:30:09 ubuntu systemd[1]: Starting AppArmor initialization...
Nov 17 23:30:09 ubuntu systemd[1]: Started Flush Journal to Persistent Storage.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Create Volatile Files and Directories...
Nov 17 23:30:09 ubuntu systemd[1]: Started Tell Plymouth To Write Out Runtime Data.
Nov 17 23:30:09 ubuntu systemd[1]: Started Create Volatile Files and Directories.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Update UTMP about System Boot/Shutdown...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Time Synchronization...
Nov 17 23:30:09 ubuntu systemd[1]: Started Set console font and keymap.
Nov 17 23:30:09 ubuntu systemd[1]: Started Update UTMP about System Boot/Shutdown.
Nov 17 23:30:09 ubuntu systemd[1]: Started Commit a transient machine-id on disk.
Nov 17 23:30:09 ubuntu systemd[1]: Started ebtables ruleset management.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Network (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Service...
Nov 17 23:30:09 ubuntu apparmor[532]: * Starting AppArmor profiles
Nov 17 23:30:09 ubuntu systemd-networkd[547]: Enumeration completed
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Service.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Wait for Network to be Configured...
Nov 17 23:30:09 ubuntu systemd-networkd[547]: lo: Link is not managed by us
Nov 17 23:30:09 ubuntu systemd-networkd[547]: ens34: Link is not managed by us
Nov 17 23:30:09 ubuntu systemd-networkd[547]: ens33: Gained carrier
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Name Resolution...
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Time Synchronization.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target System Time Synchronized.
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Positive Trust Anchors:
Nov 17 23:30:09 ubuntu systemd-resolved[552]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Nov 17 23:30:09 ubuntu systemd-resolved[552]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa
22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.19
2.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Using system hostname 'ubuntu'.
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Name Resolution.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Host and Network Name Lookups.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Network.
Nov 17 23:30:09 ubuntu systemd-udevd[520]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd-udevd[523]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd-udevd[525]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd[1]: Listening on Load/Save RF Kill Switch Status /dev/rfkill Watch.
Nov 17 23:30:09 ubuntu apparmor[532]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Nov 17 23:30:09 ubuntu apparmor[532]: ...done.
Nov 17 23:30:09 ubuntu systemd[1]: Started AppArmor initialization.
Nov 17 23:30:09 ubuntu systemd[1]: Started Authentication service for virtual machines hosted on VMware.
Nov 17 23:30:09 ubuntu systemd[1]: Started Service for virtual machines hosted on VMware.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target System Initialization.
Nov 17 23:30:09 ubuntu systemd[1]: Listening on UUID daemon activation socket.
--More--(0%)
위와 같이 출력이 됩니다.
화면에 출력할 수 있는 처음 페이지를 보여주고 그 이상 다음 페이지로 넘어가지 않습니다. 아래 --More-- (0%) 보이시나요? 문서 전체 페이지의 퍼센티지를 보여줍니다.
여기서 엔터키를 누르게 되면, 한 줄씩 화면이 넘어가며, 스페이스 바를 누르게 되면 한 페이지씩 화면이 넘어가게 됩니다.
리눅스 파일보기 명령어 less
이번엔 less 명령어를 사용해 보겠습니다.
less /var/log/syslog
root@ubuntu:~# less /var/log/syslog
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'iscsi_tcp'
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'ib_iser'
Nov 17 23:30:09 ubuntu systemd[1]: Starting Flush Journal to Persistent Storage...
Nov 17 23:30:09 ubuntu systemd[1]: Started udev Kernel Device Manager.
Nov 17 23:30:09 ubuntu systemd[1]: Started Apply Kernel Variables.
Nov 17 23:30:09 ubuntu systemd[1]: Started Set the console keyboard layout.
Nov 17 23:30:09 ubuntu systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local Encrypted Volumes.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Commit a transient machine-id on disk...
Nov 17 23:30:09 ubuntu systemd[1]: Starting ebtables ruleset management...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Set console font and keymap...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Tell Plymouth To Write Out Runtime Data...
Nov 17 23:30:09 ubuntu systemd[1]: Starting AppArmor initialization...
Nov 17 23:30:09 ubuntu systemd[1]: Started Flush Journal to Persistent Storage.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Create Volatile Files and Directories...
Nov 17 23:30:09 ubuntu systemd[1]: Started Tell Plymouth To Write Out Runtime Data.
Nov 17 23:30:09 ubuntu systemd[1]: Started Create Volatile Files and Directories.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Update UTMP about System Boot/Shutdown...
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Time Synchronization...
Nov 17 23:30:09 ubuntu systemd[1]: Started Set console font and keymap.
Nov 17 23:30:09 ubuntu systemd[1]: Started Update UTMP about System Boot/Shutdown.
Nov 17 23:30:09 ubuntu systemd[1]: Started Commit a transient machine-id on disk.
Nov 17 23:30:09 ubuntu systemd[1]: Started ebtables ruleset management.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Network (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Service...
Nov 17 23:30:09 ubuntu apparmor[532]: * Starting AppArmor profiles
Nov 17 23:30:09 ubuntu systemd-networkd[547]: Enumeration completed
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Service.
Nov 17 23:30:09 ubuntu systemd[1]: Starting Wait for Network to be Configured...
Nov 17 23:30:09 ubuntu systemd-networkd[547]: lo: Link is not managed by us
Nov 17 23:30:09 ubuntu systemd-networkd[547]: ens34: Link is not managed by us
Nov 17 23:30:09 ubuntu systemd-networkd[547]: ens33: Gained carrier
Nov 17 23:30:09 ubuntu systemd[1]: Starting Network Name Resolution...
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Time Synchronization.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target System Time Synchronized.
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Positive Trust Anchors:
Nov 17 23:30:09 ubuntu systemd-resolved[552]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Nov 17 23:30:09 ubuntu systemd-resolved[552]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa d.f.ip6.arpa corp home internal intranet lan local private test
Nov 17 23:30:09 ubuntu systemd-resolved[552]: Using system hostname 'ubuntu'.
Nov 17 23:30:09 ubuntu systemd[1]: Started Network Name Resolution.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Host and Network Name Lookups.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Network.
Nov 17 23:30:09 ubuntu systemd-udevd[520]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd-udevd[523]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd-udevd[525]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 17 23:30:09 ubuntu systemd[1]: Listening on Load/Save RF Kill Switch Status /dev/rfkill Watch.
Nov 17 23:30:09 ubuntu apparmor[532]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Nov 17 23:30:09 ubuntu apparmor[532]: ...done.
Nov 17 23:30:09 ubuntu systemd[1]: Started AppArmor initialization.
Nov 17 23:30:09 ubuntu systemd[1]: Started Authentication service for virtual machines hosted on VMware.
Nov 17 23:30:09 ubuntu systemd[1]: Started Service for virtual machines hosted on VMware.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target System Initialization.
Nov 17 23:30:09 ubuntu systemd[1]: Listening on UUID daemon activation socket.
/var/log/syslog
less 명령어는 기본적으로 more 명령어와 비슷 하지만 조금 다릅니다. more의 경우에는 지나간 페이지나 라인을 다시 돌려 볼 수 없습니다.
일단 페이지 하단에 more와 다르게 파일의 경로가 확인됩니다.
less 명령어의 경우는 엔터키와 스페이스바 키는 more와 동일 하지만 방향키를 사용하여 지나간 페이지나 라인을 다시 확인할 수 있습니다.
리눅스 파일보기 명령어 head
head /var/log/syslog
head 명령어는 파일의 시작 10줄을 출력해 줍니다. 필요에 따라 유용하게 사용할 수 있습니다.
root@ubuntu:~# head /var/log/syslog
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'iscsi_tcp'
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'ib_iser'
Nov 17 23:30:09 ubuntu systemd[1]: Starting Flush Journal to Persistent Storage...
Nov 17 23:30:09 ubuntu systemd[1]: Started udev Kernel Device Manager.
Nov 17 23:30:09 ubuntu systemd[1]: Started Apply Kernel Variables.
Nov 17 23:30:09 ubuntu systemd[1]: Started Set the console keyboard layout.
Nov 17 23:30:09 ubuntu systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local Encrypted Volumes.
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems (Pre).
Nov 17 23:30:09 ubuntu systemd[1]: Reached target Local File Systems.
root@ubuntu:~#
요렇게 확인할 수 있습니다.
root@ubuntu:~# head -n 5 /var/log/syslog
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'iscsi_tcp'
Nov 17 23:30:09 ubuntu systemd-modules-load[482]: Inserted module 'ib_iser'
Nov 17 23:30:09 ubuntu systemd[1]: Starting Flush Journal to Persistent Storage...
Nov 17 23:30:09 ubuntu systemd[1]: Started udev Kernel Device Manager.
Nov 17 23:30:09 ubuntu systemd[1]: Started Apply Kernel Variables.
root@ubuntu:~#
head -n 5 /var/log/syslog 이렇게 -n 5 옵션을 사용하면, 파일의 시작 5줄을 확인할 수 있습니다.
리눅스 파일보기 명령어 tail
다음은 마지막으로 tail 명령어에 대해서 알아보겠습니다.
의외로 활용도가 높은 명령어이니 꼭 기억해두시기 바랍니다. 도움이 많이 됩니다.
root@ubuntu:~# tail /var/log/syslog
Mar 28 21:21:22 ubuntu systemd[1]: Started Session 3 of user root.
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:540: gracefully waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:542: done waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon stop requested to wait for socket activation
Mar 28 21:21:53 ubuntu systemd[1]: Started Daily apt download activities.
Mar 28 21:21:53 ubuntu systemd[1]: Starting Daily apt upgrade and clean activities...
Mar 28 21:21:54 ubuntu systemd[1]: Started Daily apt upgrade and clean activities.
Mar 28 21:21:54 ubuntu systemd[1]: Startup finished in 4.128s (kernel) + 49.800s (userspace) = 53.928s.
Mar 28 21:36:40 ubuntu systemd[1]: Starting Cleanup of Temporary Directories...
Mar 28 21:36:40 ubuntu systemd[1]: Started Cleanup of Temporary Directories.
root@ubuntu:~#
head와 반대로 마지막 10줄을 출력해줍니다.
root@ubuntu:~# tail -n 5 /var/log/syslog
Mar 28 21:21:53 ubuntu systemd[1]: Starting Daily apt upgrade and clean activities...
Mar 28 21:21:54 ubuntu systemd[1]: Started Daily apt upgrade and clean activities.
Mar 28 21:21:54 ubuntu systemd[1]: Startup finished in 4.128s (kernel) + 49.800s (userspace) = 53.928s.
Mar 28 21:36:40 ubuntu systemd[1]: Starting Cleanup of Temporary Directories...
Mar 28 21:36:40 ubuntu systemd[1]: Started Cleanup of Temporary Directories.
root@ubuntu:~#
tail -n 5 /var/log/syslog 옵션 -n 5를 사용하여 파일의 마지막 5줄을 확인할 수 있습니다.
tail 명령어의 진가는 -f 옵션입니다.
보통 해당 로그나 파일을 실시간으로 모니터링할 때,
tail -f /var/log/syslog 이런 식으로 활용할 수 있습니다.
이렇게 명령어를 입력하면 화면에 실시간으로 로그나 이벤트가 발생하면 라인을 업데이트해서 출력해줍니다.
root@ubuntu:~# tail -f /var/log/syslog
Mar 28 21:21:22 ubuntu systemd[1]: Started Session 3 of user root.
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:540: gracefully waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon.go:542: done waiting for running hooks
Mar 28 21:21:22 ubuntu snapd[626]: daemon stop requested to wait for socket activation
Mar 28 21:21:53 ubuntu systemd[1]: Started Daily apt download activities.
Mar 28 21:21:53 ubuntu systemd[1]: Starting Daily apt upgrade and clean activities...
Mar 28 21:21:54 ubuntu systemd[1]: Started Daily apt upgrade and clean activities.
Mar 28 21:21:54 ubuntu systemd[1]: Startup finished in 4.128s (kernel) + 49.800s (userspace) = 53.928s.
Mar 28 21:36:40 ubuntu systemd[1]: Starting Cleanup of Temporary Directories...
Mar 28 21:36:40 ubuntu systemd[1]: Started Cleanup of Temporary Directories.
위와 같은 화면에서 추가로 로그나 이벤트가 발생하면 맨 마지막 라인이 업데이트되면서 화면에 출력해 줍니다. 실시간으로 모니터링할 때 사용하면 유용합니다.
추가적으로 아래와 같은 명령어 형식으로도 사용할 수 있습니다.
cat /var/log/syslog | more
cat /var/log/syslog | less
cat /var/log/syslog | head
cat /var/log/syslog | tail
감사합니다.
'Linux Engineer' 카테고리의 다른 글
ubuntu 22.04 server 우분투 패스워드 초기화 passwd / grub / reset (0) | 2023.04.19 |
---|---|
Linux time / date 설정 명령어 - 날짜 / 시간 (0) | 2021.02.16 |
TensorFlow install (NVIDA NGC) 텐서플로우 설치 (0) | 2021.01.21 |
FIO test - NVMe / SSD / HDD 속도 테스트 (0) | 2020.12.27 |
리눅스 ls 명령어 - 기본 명령어 (0) | 2020.12.09 |