๋จธ๋ฆฌ๋ง
์๋ ํ์ธ์ ์ฌ๋ฌ๋ถ! ์ ์ด๋ฆ์ Sasha์ด๊ณ XNUMX๋ ๋๊ฒ ๋ฐฑ์๋(Linux ์๋น์ค ๋ฐ API)๋ฅผ ํ ์คํธํด ์์ต๋๋ค. ์ด ๊ธฐ์ฌ์ ๋ํ ์์ด๋์ด๋ ํ ์คํฐ ์น๊ตฌ๊ฐ ์ธํฐ๋ทฐ ์ ์ Linux ๋ช ๋ น์ ๋ํด ์ฝ์ ์ ์๋ ๋ด์ฉ์ ์๋ ค ๋ฌ๋ผ๋ ๋ ๋ค๋ฅธ ์์ฒญ์ ๋ฐ์ ํ์ ๋์๊ฒ ์์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก QA ์์ง๋์ด ์ง์ฑ ์ ํ๋ณด์๋ ๊ธฐ๋ณธ ๋ช ๋ น์ ์์์ผ ํ์ง๋ง(๋ฌผ๋ก Linux ์์ ๊ณผ ๊ด๋ จ๋ ๊ฒฝ์ฐ), ์ธํฐ๋ทฐ๋ฅผ ์ค๋นํ๋ ๋์ ์ฝ์ด๋ณผ ๊ฐ์น๊ฐ ์๋ ๋ช ๋ น์ด ๋ฌด์์ธ์ง ์ด๋ป๊ฒ ์ ์ ์์ต๋๊น? ์๋๋ฉด Linux์ ๋ํ ๊ฒฝํ์ด ์์ต๋๊น?
๋ฐ๋ผ์ ์ด๊ฒ์ ์ด๋ฏธ ์ฌ๋ฌ ๋ฒ ์์ฑ๋์์ง๋ง ์ฌ์ ํ "์ด๋ณด์๋ฅผ ์ํ Linux"๋ผ๋ ๋ ๋ค๋ฅธ ๊ธฐ์ฌ๋ฅผ ์์ฑํ๊ธฐ๋ก ๊ฒฐ์ ํ๊ณ Linux๋ฅผ ์ฌ์ฉํ๋ ๋ถ์(๋๋ ํ์ฌ)์์ ์ธํฐ๋ทฐํ๊ธฐ ์ ์ ์์์ผ ํ ๊ธฐ๋ณธ ๋ช
๋ น์ ์ฌ๊ธฐ์ ๋์ดํ์ต๋๋ค. ์ด๋ค ๋ช
๋ น๊ณผ ์ ํธ๋ฆฌํฐ, ์ด๋ค ๋งค๊ฐ๋ณ์๋ฅผ ๊ฐ์ฅ ์์ฃผ ์ฌ์ฉํ๋์ง ์๊ฐํด ๋ณด๊ณ , ๋๋ฃ๋ค๋ก๋ถํฐ ํผ๋๋ฐฑ์ ์์งํ์ฌ ๋ชจ๋ ํ๋์ ๋ฌธ์๋ก ์ ๋ฆฌํ์ต๋๋ค. ์ด ๊ธฐ์ฌ๋ ์ธ ๋ถ๋ถ์ผ๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. ๋จผ์ Linux ํฐ๋ฏธ๋์ I/O ๊ธฐ๋ณธ ์ฌํญ์ ๋ํ ๊ฐ๋ตํ ์ ๋ณด, ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋ช
๋ น์ ๋ํ ๊ฐ์, ์ธ ๋ฒ์งธ ๋ถ๋ถ์์๋ Linux์์ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช
ํฉ๋๋ค.
๊ฐ ๋ช ๋ น์๋ ๋ง์ ์ต์ ์ด ์์ผ๋ฉฐ ์ฌ๊ธฐ์ ๋ชจ๋ ๋์ด๋์ง๋ ์์ต๋๋ค. ์ธ์ ๋ ์ง `๋ฅผ ์ ๋ ฅํ ์ ์์ต๋๋ค.๋จ์ <๋ช ๋ น์ด>`` ๋๋ `<๋ช ๋ น> --help`` ํ์ ๋ํด ๋ ์์ธํ ์์๋ณด์ธ์.
์ :
[user@testhost ~]$ mkdir --help Usage: mkdir [OPTION]... DIRECTORY... Create the DIRECTORY(ies), if they do not already exist. Mandatory arguments to long options are mandatory for short options too. -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask -p, --parents no error if existing, make parent directories as needed -v, --verbose print a message for each created directory -Z set SELinux security context of each created directory to the default type --context[=CTX] like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'mkdir invocation'
๋ช ๋ น์ ์๋ฃํ๋ ๋ฐ ์๊ฐ์ด ๋๋ฌด ์ค๋ ๊ฑธ๋ฆฌ๋ ๊ฒฝ์ฐ ์ฝ์์์ ๋ฅผ ํด๋ฆญํ์ฌ ๋ช ๋ น์ ์ข ๋ฃํ ์ ์์ต๋๋ค. Ctrl + C (ํ๋ก์ธ์ค์ ์ ํธ๊ฐ ์ ์ก๋ฉ๋๋ค. ์ฌ์ธํธ).
๋ช ๋ น ์ถ๋ ฅ์ ๋ํด ์กฐ๊ธ
Linux์์ ํ๋ก์ธ์ค๊ฐ ์์๋๋ฉด ํด๋น ํ๋ก์ธ์ค์ ๋ํด 3๊ฐ์ ํ์ค ๋ฐ์ดํฐ ์คํธ๋ฆผ์ด ์์ฑ๋ฉ๋๋ค. ํ์ค, ํ์ค ์ถ๋ ฅ ะธ ํ์ค ์ค๋ฅ. ๊ฐ๊ฐ 0, 1, 2๋ก ๋ฒํธ๊ฐ ๋งค๊ฒจ์ ธ ์์ต๋๋ค. ํ์ง๋ง ์ด์ ์ฐ๋ฆฌ๋ ๊ด์ฌ์ ๊ฐ๊ณ ์์ต๋๋ค. ํ์ค ์ถ๋ ฅ ๊ทธ๋ฆฌ๊ณ ๋ํ์ง๋ง, ํ์ค ์ค๋ฅ. ์ด๋ฆ๋ง ๋ด๋ ์ง์ํ๊ธฐ ์ฝ์ฃ ํ์ค ์ถ๋ ฅ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํ๋๋ฐ ์ฌ์ฉ๋๋ฉฐ, ํ์ค ์ค๋ฅ โ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ์ํฉ๋๋ค. Linux์์ ๋ช ๋ น์ ์คํํ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ค ์ถ๋ ฅ ะธ ํ์ค ์ค๋ฅ ๋ชจ๋ ์ ๋ณด๋ฅผ ์ฝ์์ ์ถ๋ ฅํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ช ๋ น ์ถ๋ ฅ์ด ํฐ ๊ฒฝ์ฐ ํ์ผ๋ก ๋ฆฌ๋๋ ์ ํ๋ ๊ฒ์ด ํธ๋ฆฌํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์์ต๋๋ค.
[user@testhost ~]$ man signal > man_signal
ํ์ผ ๋ด์ฉ์ ์ถ๋ ฅํ๋ฉด ๋งจ_์๊ทธ๋, ๊ทธ๋ฌ๋ฉด ๋จ์ํ ` ๋ช ๋ น์ ์คํํ์ ๋์ ๊ฒฐ๊ณผ์ ๋์ผํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.๋จ์ ์ ํธ`.
๋ฆฌ๋๋ ์ ์์ `>` ๊ธฐ๋ณธ๊ฐ์ ํ์ค ์ถ๋ ฅ. ๋ฆฌ๋๋ ์ ์ ์ง์ ํ ์ ์์ต๋๋ค. ํ์ค ์ถ๋ ฅ ๋ช ์์ ์ผ๋ก: `1>`. ๋ง์ฐฌ๊ฐ์ง๋ก ๋ฆฌ๋๋ ์ ์ ์ง์ ํ ์ ์์ต๋๋ค. ํ์ค ์ค๋ฅ:`2>`. ์ด๋ฌํ ์์ ์ ๊ฒฐํฉํ์ฌ ์ผ๋ฐ ๋ช ๋ น ์ถ๋ ฅ๊ณผ ์ค๋ฅ ๋ฉ์์ง ์ถ๋ ฅ์ ๋ถ๋ฆฌํ ์ ์์ต๋๋ค.
[user@testhost ~]$ man signal 1> man_signal 2> man_signal_error_log
๋ฆฌ๋๋ ์ ๋ฐ ํ์ค ์ถ๋ ฅ๊ณผ ํ์ค ์ค๋ฅ ๋ค์๊ณผ ๊ฐ์ด ํ๋์ ํ์ผ๋ก ๋ง๋ญ๋๋ค.
[user@testhost ~]$ man signal > man_signal 2>&1
๋ฆฌ๋๋ ์ ์์ `2> ๋ฐ 1`๋ ๋ฆฌ๋๋ ์ ์ ์๋ฏธํฉ๋๋ค. ํ์ค ์ค๋ฅ ์๋ด๋ฐ์ ๊ณณ๊ณผ ๊ฐ์ ๊ณณ์ผ๋ก ํ์ค ์ถ๋ ฅ.
I/O ์์ ์ ์ํ ๋ ๋ค๋ฅธ ํธ๋ฆฌํ ๋๊ตฌ(๋๋ ํ๋ก์ธ์ค ๊ฐ ํต์ ์ ์ํ ํธ๋ฆฌํ ๋๊ตฌ)๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ํ์ดํ (๋๋ ์ปจ๋ฒ ์ด์ด). ํ์ดํ๋ผ์ธ์ ์ข ์ข ์ฌ๋ฌ ๋ช ๋ น์ ์ ๋ฌํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ํ์ค ์ถ๋ ฅ ๋ช ๋ น์ ๋ค์์ผ๋ก ๋ฆฌ๋๋ ์ ๋ฉ๋๋ค. ํ์ค ๋ค์ ๋ฑ์ด ์ฒด์ธ์ ํฌํจ๋ฉ๋๋ค.
[user@testhost ~]$ ps aux | grep docker | tail -n 2
root 1045894 0.0 0.0 7512 3704 ? Sl 16:04 0:00 docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/2fbfddaf91c1bb7b9a0a6f788f3505dd7266f1139ad381d5b51ec1f47e1e7b28 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
531 1048313 0.0 0.0 110520 2084 pts/2 S+ 16:12 0:00 grep --color=auto docker
๊ธฐ๋ณธ Linux ๋ช ๋ น
pwd
ํ์ฌ(์์ ) ๋๋ ํฐ๋ฆฌ๋ฅผ ํ์ํฉ๋๋ค.
[user@testhost ~]$ pwd
/home/user
๋ฐ์ดํฐ
ํ์ฌ ์์คํ ๋ ์ง์ ์๊ฐ์ ํ์ํฉ๋๋ค.
[user@testhost ~]$ date
Mon Dec 16 13:37:07 UTC 2019
[user@testhost ~]$ date +%s
1576503430
w
์ด ๋ช ๋ น์ ์์คํ ์ ๋ก๊ทธ์ธํ ์ฌ๋์ ๋ณด์ฌ์ค๋๋ค. ๋ํ ๊ฐ๋ ์๊ฐ๊ณผ LA(๋ถํ ํ๊ท )๋ ํ๋ฉด์ ํ์๋ฉ๋๋ค.
[user@testhost ~]$ w
05:47:17 up 377 days, 17:57, 1 user, load average: 0,00, 0,01, 0,05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user pts/0 32.175.94.241 05:47 2.00s 0.01s 0.00s w
ls
๋๋ ํ ๋ฆฌ์ ๋ด์ฉ์ ์ธ์ํฉ๋๋ค. ๊ฒฝ๋ก๋ฅผ ์ ๋ฌํ์ง ์์ผ๋ฉด ํ์ฌ ๋๋ ํฐ๋ฆฌ์ ๋ด์ฉ์ด ํ์๋ฉ๋๋ค.
[user@testhost ~]$ pwd
/home/user
[user@testhost ~]$ ls
qqq
[user@testhost ~]$ ls /home/user
qqq
[user@testhost ~]$ ls /
bin boot cgroup dev etc home lib lib64 local lost+found media mnt opt proc root run sbin selinux srv swap sys tmp usr var
๊ฐ์ธ์ ์ผ๋ก ์ต์ ์ ์์ฃผ ์ฌ์ฉํ๋๋ฐ -l (๊ธด ๋ชฉ๋ก ํ์ - ํ์ผ์ ๋ํ ์ถ๊ฐ ์ ๋ณด๊ฐ ํฌํจ๋ ์ด๋ก ์ถ๋ ฅ) -t (ํ์ผ/๋๋ ํ ๋ฆฌ ์์ ์๊ฐ๋ณ๋ก ์ ๋ ฌ) ๋ฐ -r (์ญ๋ฐฉํฅ ์ ๋ ฌ - ๋ค์๊ณผ ๊ฒฐํฉ -t ๊ฐ์ฅ ์ต๊ทผ ํ์ผ์ด ๋งจ ์๋์ ํ์๋ฉ๋๋ค):
[user@testhost ~]$ ls -ltr /
total 4194416
drwxr-xr-x 2 root root 4096 Jan 6 2012 srv
drwxr-xr-x 2 root root 4096 Jan 6 2012 selinux
drwxr-xr-x 2 root root 4096 Jan 6 2012 mnt
drwxr-xr-x 2 root root 4096 Jan 6 2012 media
drwx------ 2 root root 16384 Oct 1 2017 lost+found
drwxr-xr-x 2 root root 4096 Oct 1 2017 local
drwxr-xr-x 13 root root 4096 Oct 1 2017 usr
drwxr-xr-x 11 root root 4096 Apr 10 2018 cgroup
drwxr-xr-x 4 root root 4096 Apr 10 2018 run
-rw------- 1 root root 4294967296 Sep 10 2018 swap
dr-xr-xr-x 10 root root 4096 Dec 13 2018 lib
drwxr-xr-x 6 root root 4096 Mar 7 2019 opt
drwxr-xr-x 20 root root 4096 Mar 19 2019 var
dr-xr-xr-x 10 root root 12288 Apr 9 2019 lib64
dr-xr-xr-x 2 root root 4096 Apr 9 2019 bin
dr-xr-xr-x 4 root root 4096 Apr 9 2019 boot
dr-xr-xr-x 2 root root 12288 Apr 9 2019 sbin
dr-xr-xr-x 3229 root root 0 Jul 2 10:19 proc
drwxr-xr-x 34 root root 4096 Oct 28 13:27 home
drwxr-xr-x 93 root root 4096 Oct 30 16:00 etc
dr-xr-x--- 11 root root 4096 Nov 1 13:02 root
dr-xr-xr-x 13 root root 0 Nov 13 20:28 sys
drwxr-xr-x 16 root root 2740 Nov 26 08:55 dev
drwxrwxrwt 3 root root 4096 Nov 26 08:57 tmp
2๊ฐ์ ํน๋ณํ ๋๋ ํ ๋ฆฌ ์ด๋ฆ์ด ์์ต๋๋ค: "."๊ทธ๋ฆฌ๊ณ "..". ์ฒซ ๋ฒ์งธ๋ ํ์ฌ ๋๋ ํฐ๋ฆฌ๋ฅผ ์๋ฏธํ๊ณ ๋ ๋ฒ์งธ๋ ์์ ๋๋ ํฐ๋ฆฌ๋ฅผ ์๋ฏธํฉ๋๋ค. ํนํ ๋ค์ํ ํ์์ ์ฌ์ฉํ๊ธฐ ํธ๋ฆฌํ ์ ์์ต๋๋ค. ls:
[user@testhost home]$ pwd
/home
[user@testhost home]$ ls ..
bin boot cgroup dev etc home lib lib64 local lost+found media mnt opt proc root run sbin selinux srv swap sys tmp usr var
[user@testhost home]$ ls ../home/user/
qqq
์จ๊ฒจ์ง ํ์ผ์ ํ์ํ๋ ์ ์ฉํ ์ต์ ๋ ์์ต๋๋ค(".") - -a:
[user@testhost ~]$ ls -a
. .. 1 .bash_history .bash_logout .bash_profile .bashrc .lesshst man_signal man_signal_error_log .mongorc.js .ssh temp test .viminfo
์ต์ ์ ์ฌ์ฉํ ์๋ ์์ต๋๋ค. -h โ ์ฌ๋์ด ์ฝ์ ์ ์๋ ํ์์ผ๋ก ์ถ๋ ฅํฉ๋๋ค(ํ์ผ ํฌ๊ธฐ์ ์ฃผ์):
[user@testhost ~]$ ls -ltrh
total 16K
-rwxrwx--x 1 user user 31 Nov 26 11:09 temp
-rw-rw-r-- 1 user user 6.0K Dec 3 16:02 1
drwxrwxr-x 2 user user 4.0K Dec 4 10:39 test
cd
ํ์ฌ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
[user@testhost ~]$ pwd
/home/user
[user@testhost ~]$ cd /home/
[user@testhost home]$ pwd
/home
๋๋ ํฐ๋ฆฌ ์ด๋ฆ์ ์ธ์๋ก ์ ๋ฌํ์ง ์์ผ๋ฉด ํ๊ฒฝ ๋ณ์๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. $ HOME, ์ฆ ํ ๋๋ ํ ๋ฆฌ์ ๋๋ค. `๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๋ ํธ๋ฆฌํ ์ ์์ต๋๋ค.~`๋ ํน์ ๋ฌธ์ ์๋ฏธ์ ๋๋ค. $ HOME:
[user@testhost etc]$ pwd
/etc
[user@testhost etc]$ cd ~/test/
[user@testhost test]$ pwd
/home/user/test
mkdir
๋๋ ํฐ๋ฆฌ๋ฅผ ๋ง๋ญ๋๋ค.
[user@testhost ~]$ mkdir test
[user@testhost ~]$ ls -ltr
total 38184
-rw-rw-r-- 1 user user 39091284 Nov 22 14:14 qqq
drwxrwxr-x 2 user user 4096 Nov 26 10:29 test
๋๋ก๋ ์กด์ฌํ์ง ์๋ ๋๋ ํฐ๋ฆฌ ๋ด์ ๋๋ ํฐ๋ฆฌ์ ๊ฐ์ด ํน์ ๋๋ ํฐ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์ด์ผ ํ๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. ์ฐ์์ผ๋ก ์ฌ๋ฌ ๋ฒ ์ ๋ ฅํ๋ ๊ฒ์ ๋ฐฉ์งํ๋ ค๋ฉด mkdir, ์ต์ ์ ์ฌ์ฉํ ์ ์์ต๋๋ค -p โ ๊ณ์ธต ๊ตฌ์กฐ์์ ๋๋ฝ๋ ๋ชจ๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค. ๋ํ ์ด ์ต์ ์ ์ฌ์ฉํ๋ฉด mkdir ๋๋ ํ ๋ฆฌ๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ ์ค๋ฅ๋ฅผ ๋ฐํํ์ง ์์ต๋๋ค.
[user@testhost ~]$ ls
qqq test
[user@testhost ~]$ mkdir test2/subtest
mkdir: cannot create directory โtest2/subtestโ: No such file or directory
[user@testhost ~]$ mkdir -p test2/subtest
[user@testhost ~]$ ls
qqq test test2
[user@testhost ~]$ ls test2/
subtest
[user@testhost ~]$ mkdir test2/subtest
mkdir: cannot create directory โtest2/subtestโ: File exists
[user@testhost ~]$ mkdir -p test2/subtest
[user@testhost ~]$ ls test2/
subtest
rm
ํ์ผ์ ์ญ์ ํฉ๋๋ค.
[user@testhost ~]$ ls
qqq test test2
[user@testhost ~]$ rm qqq
[user@testhost ~]$ ls
test test2
์ต์ -r ๋ชจ๋ ๋ด์ฉ์ด ํฌํจ๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ์ญ์ ํ ์ ์์ต๋๋ค. ์ต์ -f ์ญ์ ์ ์ค๋ฅ(์: ์กด์ฌํ์ง ์๋ ํ์ผ ๊ด๋ จ ์ค๋ฅ)๋ฅผ ๋ฌด์ํ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ต์ ์ ์ฌ์ฉํ๋ฉด ๋๋ต์ ์ผ๋ก ํ์ผ ๋ฐ ๋๋ ํฐ๋ฆฌ์ ์ ์ฒด ๊ณ์ธต ๊ตฌ์กฐ๋ฅผ ์ญ์ ํ ์ ์์ผ๋ฏ๋ก(์ฌ์ฉ์์๊ฒ ๊ทธ๋ ๊ฒ ํ ๊ถํ์ด ์๋ ๊ฒฝ์ฐ) ์ฃผ์ํด์ ์ฌ์ฉํด์ผ ํฉ๋๋ค(๊ณ ์ ์ ์ธ ๋๋ด ์๋ "rm-rf /", ํน์ ์ํฉ์์๋ ์ ์ฒด ์์คํ ์ ์๋๋๋ผ๋ ์ฑ๋ฅ์ ์ค์ํ ๋ง์ ํ์ผ์ด ์ญ์ ๋ฉ๋๋ค.)
[user@testhost ~]$ ls
test test2
[user@testhost ~]$ ls -ltr test2/
total 4
-rw-rw-r-- 1 user user 0 Nov 26 10:40 temp
drwxrwxr-x 2 user user 4096 Nov 26 10:40 temp_dir
[user@testhost ~]$ rm -rf test2
[user@testhost ~]$ ls
test
cp
ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํฉ๋๋ค.
[user@testhost ~]$ ls
temp test
[user@testhost ~]$ cp temp temp_clone
[user@testhost ~]$ ls
temp temp_clone test
์ด ๋ช ๋ น์๋ ์ต์ ๋ ์์ต๋๋ค -r ะธ -f, ๋๋ ํฐ๋ฆฌ ๋ฐ ํด๋์ ๊ณ์ธต ๊ตฌ์กฐ๊ฐ ๋ค๋ฅธ ์์น์ ๋ณต์ฌ๋๋๋ก ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค.
mv
ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ๋ฅผ ์ด๋ํ๊ฑฐ๋ ์ด๋ฆ์ ๋ฐ๊ฟ๋๋ค.
[user@testhost ~]$ ls -ltr
total 4
drwxrwxr-x 2 user user 4096 Nov 26 10:29 test
-rw-rw-r-- 1 user user 0 Nov 26 10:45 temp
-rw-rw-r-- 1 user user 0 Nov 26 10:46 temp_clone
[user@testhost ~]$ ls test
[user@testhost ~]$ mv test test_renamed
[user@testhost ~]$ mv temp_clone test_renamed/
[user@testhost ~]$ ls
temp test_renamed
[user@testhost ~]$ ls test_renamed/
temp_clone
๋ฐฉ๋ฒ
ํ์ผ(๋ค)์ ๋ด์ฉ์ ์ธ์ํฉ๋๋ค.
[user@testhost ~]$ cat temp
Content of a file.
Lalalala...
๋ช ๋ น์์ฃผ์๋ฅผ ๊ธฐ์ธ์ผ ๊ฐ์น๊ฐ ์์ต๋๋ค. ๋จธ๋ฆฌ (์ฐ์ถ n ํ์ผ์ ์ฒซ ๋ฒ์งธ ์ค ๋๋ ๋ฐ์ดํธ) ๋ฐ ๊ผฌ๋ฆฌ (๋์ค์ ๊ทธ๋ ์ ๋ํด ๋ ์์ธํ ์ค๋ช ํฉ๋๋ค).
๊ผฌ๋ฆฌ
์ฒ ์ n ํ์ผ์ ๋ง์ง๋ง ์ค์ด๋ ๋ฐ์ดํธ.
[user@testhost ~]$ tail -1 temp
Lalalala...
์ด ์ต์ ์ ๋งค์ฐ ์ ์ฉํฉ๋๋ค -f โ ์ค์๊ฐ์ผ๋ก ํ์ผ์ ์ ๋ฐ์ดํฐ๋ฅผ ํ์ํ ์ ์์ต๋๋ค.
์ ๊ฒ
๋๋ก๋ ํ ์คํธ ํ์ผ์ด ๋๋ฌด ์ปค์ ๋ช ๋ น์ผ๋ก ํ์ํ๊ธฐ๊ฐ ๋ถํธํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฐฉ๋ฒ. ๊ทธ๋ฐ ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ์ด ์ ์์ต๋๋ค ์ ๊ฒ: ํ์ผ์ด ์ฌ๋ฌ ๋ถ๋ถ์ผ๋ก ์ถ๋ ฅ๋๋ฉฐ, ํด๋น ๋ถ๋ถ์ ํตํ ํ์, ๊ฒ์ ๋ฑ ๊ฐ๋จํ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
[user@testhost ~]$ less temp
์ด์ฉํ๊ธฐ์๋ ํธ๋ฆฌํ ๊ฒ ๊ฐ์์ ์ ๊ฒ ์ปจ๋ฒ ์ด์ด ํฌํจ(ํ์ดํ):
[user@testhost ~]$ grep "ERROR" /tmp/some.log | less
ps
ํ๋ก์ธ์ค๋ฅผ ๋์ดํฉ๋๋ค.
[user@testhost ~]$ ps
PID TTY TIME CMD
761020 pts/2 00:00:00 bash
809720 pts/2 00:00:00 ps
๋ ์์ ์ ๋ณดํต BSD ์ต์ ์ ์ฌ์ฉํฉ๋๋ค "์" - ์์คํ ์ ๋ชจ๋ ํ๋ก์ธ์ค๋ฅผ ํ์ํฉ๋๋ค(ํ๋ก์ธ์ค๊ฐ ๋ง์ ์ ์์ผ๋ฏ๋ก ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ์ฌ ์ฒ์ 5๊ฐ๋ง ํ์ํ์ต๋๋ค(ํ์ดํ) ๋ฐ ํ ๋จธ๋ฆฌ):
[user@testhost ~]$ ps aux | head -5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 19692 2600 ? Ss Jul02 0:10 /sbin/init
root 2 0.0 0.0 0 0 ? S Jul02 0:03 [kthreadd]
root 4 0.0 0.0 0 0 ? I< Jul02 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? I< Jul02 0:00 [mm_percpu_wq]
๋ง์ ์ฌ๋๋ค์ด BSD ์ต์ ๋ ์ฌ์ฉํฉ๋๋ค."์ถ"๋ฅผ ์ฌ์ฉํ๋ฉด ํ๋ก์ธ์ค ํธ๋ฆฌ๋ฅผ ํ์ํ ์ ์์ต๋๋ค(์ฌ๊ธฐ์์๋ ๋ฐ๋ชจ๋ฅผ ์ํด ์ถ๋ ฅ์ ์ผ๋ถ๋ฅผ ์ ๊ฑฐํ์ต๋๋ค).
[user@testhost ~]$ ps axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 2 0 0 ? -1 S 0 0:03 [kthreadd]
2 4 0 0 ? -1 I< 0 0:00 _ [kworker/0:0H]
2 6 0 0 ? -1 I< 0 0:00 _ [mm_percpu_wq]
2 7 0 0 ? -1 S 0 4:08 _ [ksoftirqd/0]
...
...
...
1 4293 4293 4293 tty6 4293 Ss+ 0 0:00 /sbin/mingetty /dev/tty6
1 532967 532964 532964 ? -1 Sl 495 0:00 /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent --log /var/log/td-agent/td-agent.log --use-v1-config --group td-agent --daemon /var/run/td-agent/td-agent.pid
532967 532970 532964 532964 ? -1 Sl 495 803:06 _ /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent --log /var/log/td-agent/td-agent.log --use-v1-config --group td-agent --daemon /var/run/td-agent/td-agent.pid
1 537162 533357 532322 ? -1 Sl 0 5067:43 /usr/bin/dockerd --default-ulimit nofile=262144:262144 --dns=172.17.0.1
537162 537177 537177 537177 ? -1 Ssl 0 4649:28 _ docker-containerd --config /var/run/docker/containerd/containerd.toml
537177 537579 537579 537177 ? -1 Sl 0 4:48 | _ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/0ee89b20deb3cf08648cd92e1f3e3c661ccffef7a0971
537579 537642 537642 537642 ? -1 Ss 1000 32:11 | | _ /usr/bin/python /usr/bin/supervisord -c /etc/supervisord/api.conf
537642 539764 539764 537642 ? -1 S 1000 0:00 | | _ sh -c echo "READY"; while read -r line; do echo "$line"; supervisorctl shutdown; done
537642 539767 539767 537642 ? -1 S 1000 5:09 | | _ php-fpm: master process (/etc/php73/php-fpm.conf)
539767 783097 539767 537642 ? -1 S 1000 0:00 | | | _ php-fpm: pool test
539767 783131 539767 537642 ? -1 S 1000 0:00 | | | _ php-fpm: pool test
539767 783185 539767 537642 ? -1 S 1000 0:00 | | | _ php-fpm: pool test
...
...
...
์ด ๋ช ๋ น์๋ ๋ค์ํ ์ต์ ์ด ์์ผ๋ฏ๋ก ์ ๊ทน์ ์ผ๋ก ์ฌ์ฉํ๋ค๋ฉด ์ค๋ช ์๋ฅผ ์ฝ์ด ๋ณด๋ ๊ฒ์ด ์ข์ต๋๋ค. ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ''๋ฅผ ์๋ ๊ฒ๋ง์ผ๋ก๋ ์ถฉ๋ถํฉ๋๋ค.ps aux".
์ฃฝ์ด๊ธฐ
ํ๋ก์ธ์ค์ ์ ํธ๋ฅผ ๋ณด๋ ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ ํธ๊ฐ ์ ์ก๋ฉ๋๋ค. ์๊ทธํ , ํ๋ก์ธ์ค๊ฐ ์ข ๋ฃ๋ฉ๋๋ค.
[user@testhost ~]$ ps ux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
531 1027147 0.0 0.0 119956 4260 ? S 14:51 0:00 sshd: user@pts/1
531 1027149 0.0 0.0 115408 3396 pts/1 Ss 14:51 0:00 -bash
531 1027170 0.0 0.0 119956 4136 ? R 14:51 0:00 sshd: user@pts/2
531 1027180 0.0 0.0 115408 3564 pts/2 Ss 14:51 0:00 -bash
531 1033727 0.0 0.0 107960 708 pts/1 S+ 15:17 0:00 sleep 300
531 1033752 0.0 0.0 117264 2604 pts/2 R+ 15:17 0:00 ps ux
[user@testhost ~]$ kill 1033727
[user@testhost ~]$ ps ux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
531 1027147 0.0 0.0 119956 4260 ? S 14:51 0:00 sshd: user@pts/1
531 1027149 0.0 0.0 115408 3396 pts/1 Ss+ 14:51 0:00 -bash
531 1027170 0.0 0.0 119956 4136 ? R 14:51 0:00 sshd: user@pts/2
531 1027180 0.0 0.0 115408 3564 pts/2 Ss 14:51 0:00 -bash
531 1033808 0.0 0.0 117268 2492 pts/2 R+ 15:17 0:00 ps ux
ํ๋ก์ธ์ค์๋ ์ ํธ ์ฒ๋ฆฌ๊ธฐ๊ฐ ์์ ์ ์์ผ๋ฏ๋ก ์ฃฝ์ด๊ธฐ ํญ์ ์์๋ ๊ฒฐ๊ณผ๋ก ์ด์ด์ง๋ ๊ฒ์ ์๋๋๋ค. ํ๋ก์ธ์ค๊ฐ ์ฆ์ ์๋ฃ๋ฉ๋๋ค. ํ๋ก์ธ์ค๋ฅผ ํ์คํ "์ข ๋ฃ"ํ๋ ค๋ฉด ํด๋น ํ๋ก์ธ์ค์ ์ ํธ๋ฅผ ๋ณด๋ด์ผ ํฉ๋๋ค. ์๊ทธํฌ. ๊ทธ๋ฌ๋ ์ด๋ก ์ธํด ๋ฐ์ดํฐ ์์ค์ด ๋ฐ์ํ ์ ์์ผ๋ฏ๋ก(์: ํ๋ก์ธ์ค๊ฐ ์ข ๋ฃ๋๊ธฐ ์ ์ ์ผ๋ถ ์ ๋ณด๋ฅผ ๋์คํฌ์ ์ ์ฅํด์ผ ํ๋ ๊ฒฝ์ฐ) ์ด ๋ช ๋ น์ ์ฃผ์ํด์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์ ํธ๋ฒํธ ์๊ทธํฌ - 9์ด๋ฏ๋ก ๋ช ๋ น์ ์งง์ ๋ฒ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
[user@testhost ~]$ ps ux | grep sleep
531 1034930 0.0 0.0 107960 636 pts/1 S+ 15:21 0:00 sleep 300
531 1034953 0.0 0.0 110516 2104 pts/2 S+ 15:21 0:00 grep --color=auto sleep
[user@testhost ~]$ kill -9 1034930
[user@testhost ~]$ ps ux | grep sleep
531 1035004 0.0 0.0 110516 2092 pts/2 S+ 15:22 0:00 grep --color=auto sleep
์ธ๊ธ๋ ๊ฒ ์ธ์๋ ์๊ทธํ ะธ ์๊ทธํฌ ๋ ๋ง์ ์ ํธ๊ฐ ์์ผ๋ฉฐ ๊ทธ ๋ชฉ๋ก์ ์ธํฐ๋ท์์ ์ฝ๊ฒ ์ฐพ์ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ ํธ๊ฐ ์๋ค๋ ๊ฒ์ ์์ง ๋ง์ธ์ ์๊ทธํฌ ะธ ์๊ทธ์คํฑ ๊ฐ๋ก์ฑ๊ฑฐ๋ ๋ฌด์ํ ์ ์์ต๋๋ค.
ํ
ICMP ํจํท์ ํธ์คํธ๋ก ๋ณด๋ด๊ธฐ ECHO_REQUEST.
[user@testhost ~]$ ping google.com
PING google.com (172.217.15.78) 56(84) bytes of data.
64 bytes from iad23s63-in-f14.1e100.net (172.217.15.78): icmp_seq=1 ttl=47 time=1.85 ms
64 bytes from iad23s63-in-f14.1e100.net (172.217.15.78): icmp_seq=2 ttl=47 time=1.48 ms
64 bytes from iad23s63-in-f14.1e100.net (172.217.15.78): icmp_seq=3 ttl=47 time=1.45 ms
64 bytes from iad23s63-in-f14.1e100.net (172.217.15.78): icmp_seq=4 ttl=47 time=1.46 ms
64 bytes from iad23s63-in-f14.1e100.net (172.217.15.78): icmp_seq=5 ttl=47 time=1.45 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 1.453/1.541/1.850/0.156 ms
๊ธฐ๋ณธ์ ์ผ๋ก ํ ์๋์ผ๋ก ์ข ๋ฃ๋ ๋๊น์ง ์๋ํฉ๋๋ค. ๋ฐ๋ผ์ ์ด ์ต์ ์ด ์ ์ฉํ ์ ์์ต๋๋ค. -c โ ์ ์ก ํ ํจํท ์ ํ ์์ฒด์ ์ผ๋ก ์๋ฃ๋ฉ๋๋ค. ์ ๊ฐ ๊ฐ๋ ์ฌ์ฉํ๋ ๋ ๋ค๋ฅธ ์ต์ ์ -i, ํจํท ์ ์ก ์ฌ์ด์ ๊ฐ๊ฒฉ์ ๋๋ค.
[user@testhost ~]$ ping -c 3 -i 5 google.com
PING google.com (172.217.5.238) 56(84) bytes of data.
64 bytes from iad30s07-in-f238.1e100.net (172.217.5.238): icmp_seq=1 ttl=47 time=1.55 ms
64 bytes from iad30s07-in-f14.1e100.net (172.217.5.238): icmp_seq=2 ttl=47 time=1.17 ms
64 bytes from iad30s07-in-f14.1e100.net (172.217.5.238): icmp_seq=3 ttl=47 time=1.16 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 10006ms
rtt min/avg/max/mdev = 1.162/1.295/1.551/0.181 ms
SSH
OpenSSH SSH ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉด ์๊ฒฉ ํธ์คํธ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
MacBook-Pro-User:~ user$ ssh [email protected]
Last login: Tue Nov 26 11:27:39 2019 from another_host
[user@testhost ~]$ hostname
testhost
SSH ์ฌ์ฉ์๋ ๋ฏธ๋ฌํ ์ฐจ์ด๊ฐ ๋ง์ด ์์ผ๋ฉฐ ์ด ํด๋ผ์ด์ธํธ์๋ ๋ง์ ๊ธฐ๋ฅ์ด ์์ผ๋ฏ๋ก ์ํ๊ฑฐ๋ ํ์ํ ๊ฒฝ์ฐ ์ด์ ๋ํด ์ฝ์ ์ ์์ต๋๋ค.
scp
ํธ์คํธ ๊ฐ ํ์ผ ๋ณต์ฌ(์ด ์ฉ๋๋ก SSH).
[user@testhost ~]$ pwd
/home/user
[user@testhost ~]$ ls
temp test_renamed
[user@testhost ~]$ exit
logout
Connection to 11.11.22.22 closed.
MacBook-Pro-Aleksandr:~ user$ scp [email protected]:/home/user/temp Downloads/
temp 100% 31 0.2KB/s 00:00
MacBook-Pro-Aleksandr:~ user$ cat Downloads/temp
Content of a file.
Lalalala...
rsync
ํธ์คํธ ๊ฐ์ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋๊ธฐํํ๋ ๋ฐ ์ฌ์ฉํ ์๋ ์์ต๋๋ค. rsync (-a โ ์์นด์ด๋ธ ๋ชจ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ ํ ๋ฆฌ์ ์ ์ฒด ๋ด์ฉ์ "์๋ ๊ทธ๋๋ก" ๋ณต์ฌํ ์ ์์ต๋๋ค. -v โ ์ถ๊ฐ ์ ๋ณด๋ฅผ ์ฝ์์ ์ถ๋ ฅ):
MacBook-Pro-User:~ user$ ls Downloads/user
ls: Downloads/user: No such file or directory
MacBook-Pro-User:~ user$ rsync -av user@testhost:/home/user Downloads
receiving file list ... done
user/
user/.bash_history
user/.bash_logout
user/.bash_profile
user/.bashrc
user/.lesshst
user/.mongorc.js
user/.viminfo
user/1
user/man_signal
user/man_signal_error_log
user/temp
user/.ssh/
user/.ssh/authorized_keys
user/test/
user/test/created_today
user/test/temp_clone
sent 346 bytes received 29210 bytes 11822.40 bytes/sec
total size is 28079 speedup is 0.95
MacBook-Pro-User:~ user$ ls -a Downloads/user
. .bash_history .bash_profile .lesshst .ssh 1 man_signal_error_log test
.. .bash_logout .bashrc .mongorc.js .viminfo man_signal temp
์์ฝ
ํ ์คํธ ํ ์ค์ ํ์ํฉ๋๋ค.
[user@testhost ~]$ echo "Hello"
Hello
์ฌ๊ธฐ์ ๊ณ ๋ คํด ๋ณผ ๋งํ ์ต์ -n - ๋์ ์ค ๋ฐ๊ฟ์ ์ฌ์ฉํ์ฌ ์ค์ ์ถ๊ฐํ์ง ๋ง์ญ์์ค. -e โ ""๋ฅผ ์ฌ์ฉํ์ฌ ์ด์ค์ผ์ดํ ํด์์ ํ์ฑํํฉ๋๋ค.
[user@testhost ~]$ echo "tHellon"
tHellon
[user@testhost ~]$ echo -n "tHellon"
tHellon[user@testhost ~]$
[user@testhost ~]$ echo -ne "tHellon"
Hello
์ด ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ๋ณ์์ ๊ฐ์ ํ์ํ ์๋ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด Linux์์๋ ๋ง์ง๋ง์ผ๋ก ์๋ฃ๋ ๋ช ๋ น์ ์ข ๋ฃ ์ฝ๋๊ฐ ํน์ ๋ณ์์ ์ ์ฅ๋ฉ๋๋ค. $?, ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ง์ง๋ง์ผ๋ก ์คํ ์ค์ธ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ ํํ ์ด๋ค ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ํ์ธํ ์ ์์ต๋๋ค.
[user@testhost ~]$ ls # ะพัะธะฑะบะธ ะฝะต ะฑัะดะตั
1 man_signal man_signal_error_log temp test
[user@testhost ~]$ echo $? # ะฟะพะปััะธะผ 0 โ ะพัะธะฑะบะธ ะฝะต ะฑัะปะพ
0
[user@testhost ~]$ ls qwerty # ะฑัะดะตั ะพัะธะฑะบะฐ
ls: cannot access qwerty: No such file or directory
[user@testhost ~]$ echo $? # ะฟะพะปััะธะผ 2 โ Misuse of shell builtins (according to Bash documentation)
2
[user@testhost ~]$ echo $? # ะฟะพัะปะตะดะฝะธะน echo ะพััะฐะฑะพัะฐะป ะฑะตะท ะพัะธะฑะพะบ, ะฟะพะปััะธะผ 0
0
ํ ๋ท
TELNET ํ๋กํ ์ฝ์ฉ ํด๋ผ์ด์ธํธ์ ๋๋ค. ๋ค๋ฅธ ํธ์คํธ์ ํต์ ํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
[user@testhost ~]$ telnet example.com 80
Trying 93.184.216.34...
Connected to example.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: example.com
HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Tue, 26 Nov 2019 11:59:18 GMT
Etag: "3147526947+gzip+ident"
Expires: Tue, 03 Dec 2019 11:59:18 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dcb/7F3B)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
... ะทะดะตัั ะฑัะปะพ ัะตะปะพ ะพัะฒะตัะฐ, ะบะพัะพัะพะต ั ะฒััะตะทะฐะป ััะบะฐะผะธ ...
TLS ํ๋กํ ์ฝ์ ์ฌ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ(SSL์ด ์ค๋ ์ ๋ถํฐ ์ฌ์ฉ๋์๋ค๋ ์ ์ ์๊ธฐ์์ผ ๋๋ฆฝ๋๋ค) ํ ๋ท ์ด๋ฌํ ๋ชฉ์ ์๋ ์ ํฉํ์ง ์์ต๋๋ค. ํ์ง๋ง ๊ณ ๊ฐ์ด ์ฌ ๊ฒ์ด๋ค ํ๋ ค๋ฉด openssl:
GET ์์ฒญ์ ๋ํ ์๋ต์ ์ถ๋ ฅํ๋ฉด์ openssl์ ์ฌ์ฉํ๋ ์
[user@testhost ~]$ openssl s_client -connect example.com:443
CONNECTED(00000003)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA
verify return:1
depth=0 C = US, ST = California, L = Los Angeles, O = Internet Corporation for Assigned Names and Numbers, OU = Technology, CN = www.example.org
verify return:1
---
Certificate chain
0 s:/C=US/ST=California/L=Los Angeles/O=Internet Corporation for Assigned Names and Numbers/OU=Technology/CN=www.example.org
i:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
1 s:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA
2 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIHQDCCBiigAwIBAgIQD9B43Ujxor1NDyupa2A4/jANBgkqhkiG9w0BAQsFADBN
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E
aWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTgxMTI4MDAwMDAwWhcN
MjAxMjAyMTIwMDAwWjCBpTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3Ju
aWExFDASBgNVBAcTC0xvcyBBbmdlbGVzMTwwOgYDVQQKEzNJbnRlcm5ldCBDb3Jw
b3JhdGlvbiBmb3IgQXNzaWduZWQgTmFtZXMgYW5kIE51bWJlcnMxEzARBgNVBAsT
ClRlY2hub2xvZ3kxGDAWBgNVBAMTD3d3dy5leGFtcGxlLm9yZzCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBANDwEnSgliByCGUZElpdStA6jGaPoCkrp9vV
rAzPpXGSFUIVsAeSdjF11yeOTVBqddF7U14nqu3rpGA68o5FGGtFM1yFEaogEv5g
rJ1MRY/d0w4+dw8JwoVlNMci+3QTuUKf9yH28JxEdG3J37Mfj2C3cREGkGNBnY80
eyRJRqzy8I0LSPTTkhr3okXuzOXXg38ugr1x3SgZWDNuEaE6oGpyYJIBWZ9jF3pJ
QnucP9vTBejMh374qvyd0QVQq3WxHrogy4nUbWw3gihMxT98wRD1oKVma1NTydvt
hcNtBfhkp8kO64/hxLHrLWgOFT/l4tz8IWQt7mkrBHjbd2XLVPkCAwEAAaOCA8Ew
ggO9MB8GA1UdIwQYMBaAFA+AYRyCMWHVLyjnjUY4tCzhxtniMB0GA1UdDgQWBBRm
mGIC4AmRp9njNvt2xrC/oW2nvjCBgQYDVR0RBHoweIIPd3d3LmV4YW1wbGUub3Jn
ggtleGFtcGxlLmNvbYILZXhhbXBsZS5lZHWCC2V4YW1wbGUubmV0ggtleGFtcGxl
Lm9yZ4IPd3d3LmV4YW1wbGUuY29tgg93d3cuZXhhbXBsZS5lZHWCD3d3dy5leGFt
cGxlLm5ldDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG
AQUFBwMCMGsGA1UdHwRkMGIwL6AtoCuGKWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNv
bS9zc2NhLXNoYTItZzYuY3JsMC+gLaArhilodHRwOi8vY3JsNC5kaWdpY2VydC5j
b20vc3NjYS1zaGEyLWc2LmNybDBMBgNVHSAERTBDMDcGCWCGSAGG/WwBATAqMCgG
CCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAgGBmeBDAEC
AjB8BggrBgEFBQcBAQRwMG4wJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2lj
ZXJ0LmNvbTBGBggrBgEFBQcwAoY6aHR0cDovL2NhY2VydHMuZGlnaWNlcnQuY29t
L0RpZ2lDZXJ0U0hBMlNlY3VyZVNlcnZlckNBLmNydDAMBgNVHRMBAf8EAjAAMIIB
fwYKKwYBBAHWeQIEAgSCAW8EggFrAWkAdwCkuQmQtBhYFIe7E6LMZ3AKPDWYBPkb
37jjd80OyA3cEAAAAWdcMZVGAAAEAwBIMEYCIQCEZIG3IR36Gkj1dq5L6EaGVycX
sHvpO7dKV0JsooTEbAIhALuTtf4wxGTkFkx8blhTV+7sf6pFT78ORo7+cP39jkJC
AHYAh3W/51l8+IxDmV+9827/Vo1HVjb/SrVgwbTq/16ggw8AAAFnXDGWFQAABAMA
RzBFAiBvqnfSHKeUwGMtLrOG3UGLQIoaL3+uZsGTX3MfSJNQEQIhANL5nUiGBR6g
l0QlCzzqzvorGXyB/yd7nttYttzo8EpOAHYAb1N2rDHwMRnYmQCkURX/dxUcEdkC
wQApBo2yCJo32RMAAAFnXDGWnAAABAMARzBFAiEA5Hn7Q4SOyqHkT+kDsHq7ku7z
RDuM7P4UDX2ft2Mpny0CIE13WtxJAUr0aASFYZ/XjSAMMfrB0/RxClvWVss9LHKM
MA0GCSqGSIb3DQEBCwUAA4IBAQBzcIXvQEGnakPVeJx7VUjmvGuZhrr7DQOLeP4R
8CmgDM1pFAvGBHiyzvCH1QGdxFl6cf7wbp7BoLCRLR/qPVXFMwUMzcE1GLBqaGZM
v1Yh2lvZSLmMNSGRXdx113pGLCInpm/TOhfrvr0TxRImc8BdozWJavsn1N2qdHQu
N+UBO6bQMLCD0KHEdSGFsuX6ZwAworxTg02/1qiDu7zW7RyzHvFYA4IAjpzvkPIa
X6KjBtpdvp/aXabmL95YgBjT8WJ7pqOfrqhpcmOBZa6Cg6O1l4qbIFH/Gj9hQB5I
0Gs4+eH6F9h3SojmPTYkT+8KuZ9w84Mn+M8qBXUQoYoKgIjN
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Los Angeles/O=Internet Corporation for Assigned Names and Numbers/OU=Technology/CN=www.example.org
issuer=/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
---
No client certificate CA names sent
Peer signing digest: SHA256
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 4643 bytes and written 415 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Session-ID: 91950DC50FADB57BF026D2661E6CFAA1F522E5CA60D2310E106EE0E0FD6E70BD
Session-ID-ctx:
Master-Key: 704E9145253EEB4E9DC47E3DC6725D296D4A470EA296D54F71D65E74EAC09EB096EA1305CBEDD9E7020B8F72FD2B68A5
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 68 84 4e 77 be e3 f5 00-49 c5 44 40 53 4d b9 61 [email protected]
0010 - c9 fe df e4 05 51 d0 53-ae cf 89 4c b6 ef 6c 9e .....Q.S...L..l.
0020 - fe 12 9a f0 e8 e5 4e 87-42 89 ac af ca e5 4a 85 ......N.B.....J.
0030 - 38 08 26 e3 22 89 08 b5-62 c0 8b 7e b8 05 d3 54 8.&."...b..~...T
0040 - 8c 24 91 a7 b4 4f 79 ad-36 59 7c 69 2d e5 7f 62 .$...Oy.6Y|i-..b
0050 - f6 73 a3 8b 92 63 c1 e3-df 78 ba 8c 5a cc 82 50 .s...c...x..Z..P
0060 - 33 4e 13 4b 10 e4 97 31-cc b4 13 65 45 60 3e 13 3N.K...1...eE`>.
0070 - ac 9e b1 bb 4b 18 d9 16-ea ce f0 9b 5b 0c 8b bf ....K.......[...
0080 - fd 78 74 a0 1a ef c2 15-2a 0a 14 8d d1 3f 52 7a .xt.....*....?Rz
0090 - 12 6b c7 81 15 c4 c4 af-7e df c2 20 a8 dd 4b 93 .k......~.. ..K.
Start Time: 1574769867
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
GET / HTTP/1.1
Host: example.com
HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Tue, 26 Nov 2019 12:04:38 GMT
Etag: "3147526947+ident"
Expires: Tue, 03 Dec 2019 12:04:38 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dcb/7EC8)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
Linux์ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ํด๊ฒฐ
ํ์ผ ์์ ์ ๋ณ๊ฒฝ
๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ์ ์์ ์๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. chownํ์ง:
[user@testhost ~]$ chown user:user temp
[user@testhost ~]$ ls -l temp
-rw-rw-r-- 1 user user 31 Nov 26 11:09 temp
์ด ๋ช ๋ น์ ๋งค๊ฐ๋ณ์์๋ ์ฝ๋ก ์ผ๋ก ๊ตฌ๋ถ๋ ์ ์์ ์ ๋ฐ ๊ทธ๋ฃน(์ ํ ์ฌํญ)์ด ์ ๊ณต๋์ด์ผ ํฉ๋๋ค. ๋ํ ๋๋ ํ ๋ฆฌ ์์ ์๋ฅผ ๋ณ๊ฒฝํ ๋ ์ด ์ต์ ์ด ์ ์ฉํ ์ ์์ต๋๋ค. -R - ๊ทธ๋ฌ๋ฉด ๋๋ ํ ๋ฆฌ์ ๋ชจ๋ ๋ด์ฉ์ ๋ํ ์์ ์๊ฐ ๋ณ๊ฒฝ๋ฉ๋๋ค.
ํ์ผ ๊ถํ ๋ณ๊ฒฝ
์ด ๋ฌธ์ ๋ ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ํด๊ฒฐํ ์ ์์ต๋๋ค. chmod๋ฅผ. ์๋ฅผ ๋ค์ด, "์์ ์๋ ์ฝ๊ธฐ, ์ฐ๊ธฐ ๋ฐ ์คํ์ด ํ์ฉ๋๊ณ ๊ทธ๋ฃน์๋ ์ฝ๊ธฐ ๋ฐ ์ฐ๊ธฐ๊ฐ ํ์ฉ๋๋ฉฐ ๋ค๋ฅธ ๋ชจ๋ ์ฌ๋์๊ฒ๋ ์๋ฌด๊ฒ๋ ํ์ฉ๋์ง ์์ต๋๋ค"๋ผ๋ ๊ถํ ์ค์ ์ ์ ๊ณตํ๊ฒ ์ต๋๋ค.
[user@testhost ~]$ ls -l temp
-rw-rw-r-- 1 user user 31 Nov 26 11:09 temp
[user@testhost ~]$ chmod 760 temp
[user@testhost ~]$ ls -l temp
-rwxrw---- 1 user user 31 Nov 26 11:09 temp
๋งค๊ฐ๋ณ์์ ์ฒซ ๋ฒ์งธ 7(๋นํธ ํํ์์ 0b111)์ "์์ ์์ ๋ชจ๋ ๊ถ๋ฆฌ"๋ฅผ ์๋ฏธํ๊ณ , ๋ ๋ฒ์งธ 6(๋นํธ ํํ์์ 0b110)์ "์ฝ๊ธฐ ๋ฐ ์ฐ๊ธฐ"๋ฅผ ์๋ฏธํ๋ฉฐ, 0์ ๋๋จธ์ง์ ๋ํด์๋ ์๋ฌด ์๋ฏธ๋ ์์์ ์๋ฏธํฉ๋๋ค. . ๋นํธ๋ง์คํฌ๋ XNUMX๊ฐ์ ๋นํธ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. ์ตํ์("์ค๋ฅธ์ชฝ") ๋นํธ๋ ์คํ์ ๋ด๋นํ๊ณ , ๋ค์("์ค๊ฐ") ๋นํธ๋ ์ฐ๊ธฐ๋ฅผ, ์ต์์("์ผ์ชฝ") ๋นํธ๋ ์ฝ๊ธฐ๋ฅผ ๋ด๋นํฉ๋๋ค.
ํน์ ๋ฌธ์(๋๋ชจ๋ ๊ตฌ๋ฌธ). ์๋ฅผ ๋ค์ด ๋ค์ ์์์๋ ๋จผ์ ํ์ฌ ์ฌ์ฉ์์ ์คํ ๊ถํ์ ์ ๊ฑฐํ ๋ค์ ๋ค์ ๋ณ๊ฒฝํฉ๋๋ค.
[user@testhost ~]$ ls -l temp
-rwxrw---- 1 user user 31 Nov 26 11:09 temp
[user@testhost ~]$ chmod -x temp
[user@testhost ~]$ ls -l temp
-rw-rw---- 1 user user 31 Nov 26 11:09 temp
[user@testhost ~]$ chmod +x temp
[user@testhost ~]$ ls -l temp
-rwxrwx--x 1 user user 31 Nov 26 11:09 temp
์ด ๋ช
๋ น์ ๋ค์ํ ์ฉ๋๋ก ์ฌ์ฉ๋๋ฏ๋ก ์ด์ ๋ํด ๋ ์์ธํ ์ฝ์ด ๋ณด์๊ธฐ ๋ฐ๋๋๋ค(ํนํ ๋๋ชจ๋ ๊ตฌ๋ฌธ์ ๋ํ ๋ด์ฉ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๋ฐ์ด๋๋ฆฌ ํ์ผ์ ๋ด์ฉ ์ธ์
์ด ์์ ์ ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ํํ ์ ์์ต๋๋ค. ํฅ์ค ๋คํ. ์๋๋ ๊ทธ ์ฌ์ฉ ์์ ๋๋ค.
[user@testhost ~]$ cat temp
Content of a file.
Lalalala...
[user@testhost ~]$ hexdump -c temp
0000000 C o n t e n t o f a f i l
0000010 e . n L a l a l a l a . . . n
000001f
[user@testhost ~]$ hexdump -x temp
0000000 6f43 746e 6e65 2074 666f 6120 6620 6c69
0000010 2e65 4c0a 6c61 6c61 6c61 2e61 2e2e 000a
000001f
[user@testhost ~]$ hexdump -C temp
00000000 43 6f 6e 74 65 6e 74 20 6f 66 20 61 20 66 69 6c |Content of a fil|
00000010 65 2e 0a 4c 61 6c 61 6c 61 6c 61 2e 2e 2e 0a |e..Lalalala....|
0000001f
์ด ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฅธ ํ์์ผ๋ก ์ถ๋ ฅํ ์ ์์ง๋ง ์ด๋ ์ด ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ ๋ ๊ฐ์ฅ ์ ์ฉํ ์ต์ ์ ๋๋ค.
ํ์ผ ๊ฒ์
๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ๋๋ ํ ๋ฆฌ ํธ๋ฆฌ์์ ์ด๋ฆ์ ์ผ๋ถ๋ก ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค. ๋ฐ๊ฒฌ:
[user@testhost ~]$ find test_dir/ -name "*le*"
test_dir/file_1
test_dir/file_2
test_dir/subdir/file_3
๋ค๋ฅธ ๊ฒ์ ์ต์ ๊ณผ ํํฐ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ํด๋์์ ํ์ผ์ ์ฐพ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. test์์ฑ๋ ์ง 5์ผ์ด ๋์์ต๋๋ค:
[user@testhost ~]$ ls -ltr test
total 0
-rw-rw-r-- 1 user user 0 Nov 26 10:46 temp_clone
-rw-rw-r-- 1 user user 0 Dec 4 10:39 created_today
[user@testhost ~]$ find test/ -type f -ctime +5
test/temp_clone
ํ์ผ์์ ํ ์คํธ ๊ฒ์
ํ์ ๊ทํ๊ฐ ์ด ์์ ์ ์ฒ๋ฆฌํ๋ ๋ฐ ๋์์ ์ค ๊ฒ์ ๋๋ค GREP. ์ฉ๋๋ ๋ค์ํ์ง๋ง ์ฌ๊ธฐ์๋ ๊ฐ์ฅ ๊ฐ๋จํ ์ฉ๋๋ฅผ ์๋ก ๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
[user@testhost ~]$ grep -nr "content" test_dir/
test_dir/file_1:1:test content for file_1
test_dir/file_2:1:test content for file_2
test_dir/subdir/file_3:1:test content for file_3
๋ช ๋ น์ ์ฌ์ฉํ๋ ๋๋ฆฌ ์ฌ์ฉ๋๋ ๋ฐฉ๋ฒ ์ค ํ๋ GREP - ํ์ดํ๋ผ์ธ์์ ์ฌ์ฉ(ํ์ดํ):
[user@testhost ~]$ sudo tail -f /var/log/test.log | grep "ERROR"
์ต์ -v ํจ๊ณผ๋ฅผ ๋ผ ์ ์๊ฒ ํด์ค๋ค GREP'๊ทธ๋ฆฌ๊ณ ๊ทธ ๋ฐ๋ - ์ ๋ฌ๋ ํจํด์ ํฌํจํ์ง ์๋ ์ค๋ง GREP.
์ค์น๋ ํจํค์ง ๋ณด๊ธฐ
๋ชจ๋ ๊ฒ์ด Linux ๋ฐฐํฌํ๊ณผ ์ฌ์ฉ๋ ํจํค์ง ๊ด๋ฆฌ์์ ๋ฐ๋ผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๋ฒ์ฉ ๋ช ๋ น์ ์์ต๋๋ค. ๋ค์ ๋ช ๋ น ์ค ํ๋๊ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค.
yum list installed
apt list --installed
zypper se โinstalled-only
pacman -Qqe
dpkg -l
rpm -qa
๋๋ ํ ๋ฆฌ ํธ๋ฆฌ๊ฐ ์ฐจ์งํ๋ ๊ณต๊ฐ ํ์ธ
๋ช ๋ น ์ฌ์ฉ ์ต์ ์ค ํ๋ du:
[user@testhost ~]$ du -h -d 1 test_dir/
8,0K test_dir/subdir
20K test_dir/
๋งค๊ฐ๋ณ์ ๊ฐ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. -d๋๋ ํ ๋ฆฌ ํธ๋ฆฌ์ ๋ํ ์์ธํ ์ ๋ณด๋ฅผ ์ป์ผ๋ ค๋ฉด ๋ช ๋ น์ ๋ค์๊ณผ ํจ๊ป ์ฌ์ฉํ ์๋ ์์ต๋๋ค. ์ข ๋ฅ:
[user@testhost ~]$ du -h -d 1 test_dir/ | sort -h
8,0K test_dir/subdir
16K test_dir/subdir_2
36K test_dir/
[user@testhost ~]$ du -h -d 1 test_dir/ | sort -h -r
36K test_dir/
16K test_dir/subdir_2
8,0K test_dir/subdir
์ต์ -h ํ ์ข ๋ฅ ์ฌ๋์ด ์ฝ์ ์ ์๋ ํ์(์: 1K, 2G)์ผ๋ก ์์ฑ๋ ํฌ๊ธฐ๋ฅผ ์ ๋ ฌํ ์ ์์ต๋๋ค. -r ๋ฐ์ดํฐ๋ฅผ ์ญ์์ผ๋ก ์ ๋ ฌํ ์ ์์ต๋๋ค.
ํ์ผ, ๋๋ ํ ๋ฆฌ์ ํ์ผ์์ "์ฐพ๊ธฐ ๋ฐ ๋ฐ๊พธ๊ธฐ"
์ด ์์ ์ ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋ฉ๋๋ค. SED (ํ๋๊ทธ ์์ g ๋ง์ง๋ง์๋ ํด๋น ์ค์์ ์ฒ์ ๋ํ๋๋ "old-text"๋ง ๋์ฒด๋ฉ๋๋ค.
sed -i 's/old-text/new-text/g' input.txt
ํ ๋ฒ์ ์ฌ๋ฌ ํ์ผ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
[user@testhost ~]$ cat test_dir/file_*
test content for file_1
test content for file_2
[user@testhost ~]$ sed -i 's/test/edited/g' test_dir/file_*
[user@testhost ~]$ cat test_dir/file_*
edited content for file_1
edited content for file_2
์ถ๋ ฅ์์ ์ด ๊ทธ๋ฆฌ๊ธฐ
์ด ์์ ์ ๋์ฒํ๋ ๋ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค AWK. ์ด ์์์๋ ๋ช ๋ น ์ถ๋ ฅ `์ ๋ ๋ฒ์งธ ์ด์ ํ์ํฉ๋๋ค.์ถ์ ux`:
[user@testhost ~]$ ps ux | awk '{print $2}'
PID
11023
25870
25871
25908
25909
๋์์ ๋ค์ ์ฌํญ๋ ๋ช ์ฌํด์ผ ํฉ๋๋ค. AWK ๊ธฐ๋ฅ์ด ํจ์ฌ ํ๋ถํ๋ฏ๋ก ๋ช ๋ น์ค์์ ํ ์คํธ ์์ ์ ํด์ผ ํ๋ ๊ฒฝ์ฐ ์ด ๋ช ๋ น์ ๋ํด ์์ธํ ์ฝ์ด์ผ ํฉ๋๋ค.
ํธ์คํธ ์ด๋ฆ์ผ๋ก IP ์ฃผ์ ์ฐพ๊ธฐ
๋ค์ ๋ช ๋ น ์ค ํ๋๊ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค.
[user@testhost ~]$ host ya.ru
ya.ru has address 87.250.250.242
ya.ru has IPv6 address 2a02:6b8::2:242
ya.ru mail is handled by 10 mx.yandex.ru.
[user@testhost ~]$ dig +short ya.ru
87.250.250.242
[user@testhost ~]$ nslookup ya.ru
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: ya.ru
Address: 87.250.250.242
๋คํธ์ํฌ ์ ๋ณด
์ฌ์ฉํ ์ ์์ต๋๋ค ifconfig๋ฅผ:
[user@testhost ~]$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 47.89.93.67 netmask 255.255.224.0 broadcast 47.89.95.255
inet6 fd90::302:57ff:fe79:1 prefixlen 64 scopeid 0x20<link>
ether 04:01:57:79:00:01 txqueuelen 1000 (Ethernet)
RX packets 11912135 bytes 9307046034 (8.6 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14696632 bytes 2809191835 (2.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 10 bytes 866 (866.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 866 (866.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
์๋๋ฉด ์ด์ฉ๋ฉด ip:
[user@testhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 04:01:57:79:00:01 brd ff:ff:ff:ff:ff:ff
inet 47.89.93.67/19 brd 47.89.95.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fd90::302:57ff:fe79:1/64 scope link
valid_lft forever preferred_lft forever
3: ip_vti0: <NOARP> mtu 1500 qdisc noop state DOWN group default
link/ipip 0.0.0.0 brd 0.0.0.0
๋ํ ์๋ฅผ ๋ค์ด IPv4์๋ง ๊ด์ฌ์ด ์๋ ๊ฒฝ์ฐ ๋ค์ ์ต์ ์ ์ถ๊ฐํ ์ ์์ต๋๋ค. -4:
[user@testhost ~]$ ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 47.89.93.67/19 brd 47.89.95.255 scope global eth0
valid_lft forever preferred_lft forever
์ด๋ฆฐ ํฌํธ ๋ณด๊ธฐ
์ด๋ ๊ฒ ํ๋ ค๋ฉด ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ์ญ์์ค. NETSTAT. ์๋ฅผ ๋ค์ด, ํฌํธ์์ ์์ ์ค์ธ ํ๋ก์ธ์ค์ PID ํ์์ ํฌํธ์ ์ซ์ ํํ์ ์ฌ์ฉํ์ฌ ๋ชจ๋ TCP ๋ฐ UDP ์์ ํฌํธ๋ฅผ ๋ณด๋ ค๋ฉด ๋ค์ ์ต์ ๊ณผ ํจ๊ป ์ฌ์ฉํด์ผ ํฉ๋๋ค.
[user@testhost ~]$ netstat -lptnu
์์คํ ์ ๋ณด
์ด ์ ๋ณด๋ ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ์ป์ ์ ์์ต๋๋ค. uname.
[user@testhost ~]$ uname -a
Linux alexander 3.10.0-123.8.1.el7.x86_64 #1 SMP Mon Sep 22 19:06:58 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
์ถ๋ ฅ์ด ์์ฑ๋๋ ํ์์ ์ดํดํ๋ ค๋ฉด ๋ค์์ ์ฐธ์กฐํ์ธ์. ๋์'์ด ๋ช ๋ น์ ๊ฒฝ์ฐ:
[user@testhost ~]$ uname --help
ะัะฟะพะปัะทะพะฒะฐะฝะธะต: uname [ะะะฎะง]โฆ
ะะตัะฐัะฐะตั ะพะฟัะตะดะตะปะตะฝะฝัะต ัะฒะตะดะตะฝะธั ะพ ัะธััะตะผะต. ะัะปะธ ะะะฎะง ะฝะต ะทะฐะดะฐะฝ,
ะฟะพะดัะฐะทัะผะตะฒะฐะตััั -s.
-a, --all ะฝะฐะฟะตัะฐัะฐัั ะฒัั ะธะฝัะพัะผะฐัะธั, ะฒ ัะปะตะดัััะตะผ ะฟะพััะดะบะต,
ะบัะพะผะต -p ะธ -i, ะตัะปะธ ะพะฝะธ ะฝะตะธะทะฒะตััะฝั:
-s, --kernel-name ะฝะฐะฟะตัะฐัะฐัั ะธะผั ัะดัะฐ
-n, --nodename ะฝะฐะฟะตัะฐัะฐัั ะธะผั ะผะฐัะธะฝั ะฒ ัะตัะธ
-r, --release ะฝะฐะฟะตัะฐัะฐัั ะฝะพะผะตั ะฒัะฟััะบะฐ ะพะฟะตัะฐัะธะพะฝะฝะพะน ัะธััะตะผั
-v, --kernel-version ะฝะฐะฟะตัะฐัะฐัั ะฒะตััะธั ัะดัะฐ
-m, --machine ะฝะฐะฟะตัะฐัะฐัั ัะธะฟ ะพะฑะพััะดะพะฒะฐะฝะธั ะผะฐัะธะฝั
-p, --processor ะฝะฐะฟะตัะฐัะฐัั ัะธะฟ ะฟัะพัะตััะพัะฐ ะธะปะธ ยซะฝะตะธะทะฒะตััะฝะพยป
-i, --hardware-platform ะฝะฐะฟะตัะฐัะฐัั ัะธะฟ ะฐะฟะฟะฐัะฐัะฝะพะน ะฟะปะฐััะพัะผั ะธะปะธ ยซะฝะตะธะทะฒะตััะฝะพยป
-o, --operating-system ะฝะฐะฟะตัะฐัะฐัั ะธะผั ะพะฟะตัะฐัะธะพะฝะฝะพะน ัะธััะตะผั
--help ะฟะพะบะฐะทะฐัั ััั ัะฟัะฐะฒะบั ะธ ะฒัะนัะธ
--version ะฟะพะบะฐะทะฐัั ะธะฝัะพัะผะฐัะธั ะพ ะฒะตััะธะธ ะธ ะฒัะนัะธ
๋ฉ๋ชจ๋ฆฌ ์ ๋ณด
RAM์ด ์ผ๋ง๋ ์ฌ์ฉ๋๊ณ ์๋์ง ๋๋ ์ฌ์ฉ ๊ฐ๋ฅํ์ง ์ดํดํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋น์ด ์๋.
[user@testhost ~]$ free -h
total used free shared buff/cache available
Mem: 3,9G 555M 143M 56M 3,2G 3,0G
Swap: 0B 0B 0B
ํ์ผ ์์คํ ์ ๋ํ ์ ๋ณด(์ฌ์ ๋์คํฌ ๊ณต๊ฐ)
ํ df ๋ง์ดํธ๋ ํ์ผ ์์คํ ์์ ์ฌ์ฉ ๊ฐ๋ฅํ ๊ณต๊ฐ๊ณผ ์ ์ ๋ ๊ณต๊ฐ์ ํ์ธํ ์ ์์ต๋๋ค.
[user@testhost ~]$ df -hT
ะคะฐะนะปะพะฒะฐั ัะธััะตะผะฐ ะขะธะฟ ะ ะฐะทะผะตั ะัะฟะพะปัะทะพะฒะฐะฝะพ ะะพัั ะัะฟะพะปัะทะพะฒะฐะฝะพ% Cะผะพะฝัะธัะพะฒะฐะฝะพ ะฒ
/dev/vda1 ext4 79G 21G 55G 27% /
devtmpfs devtmpfs 2,0G 0 2,0G 0% /dev
tmpfs tmpfs 2,0G 0 2,0G 0% /dev/shm
tmpfs tmpfs 2,0G 57M 1,9G 3% /run
tmpfs tmpfs 2,0G 0 2,0G 0% /sys/fs/cgroup
tmpfs tmpfs 396M 0 396M 0% /run/user/1001
์ต์ -T ํ์ผ ์์คํ ์ ํ์ ์ถ๋ก ํด์ผ ํจ์ ์ง์ ํฉ๋๋ค.
์์คํ ์ ์์ ๋ฐ ๊ฐ์ข ํต๊ณ์ ๋ํ ์ ๋ณด
์ด๋ ๊ฒ ํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ญ์์ค. ์๋จ. ์๋ฅผ ๋ค์ด RAM ์ฌ์ฉ๋ ๊ธฐ์ค ์์ ํ๋ก์ธ์ค, CPU ์๊ฐ ์ฌ์ฉ๋ ๊ธฐ์ค ์์ ํ๋ก์ธ์ค ๋ฑ ๋ค์ํ ์ ๋ณด๋ฅผ ํ์ํ ์ ์์ต๋๋ค. ๋ํ ๋ฉ๋ชจ๋ฆฌ, CPU, ๊ฐ๋ ์๊ฐ ๋ฐ LA(๋ก๋ ํ๊ท )์ ๋ํ ์ ๋ณด๋ ํ์ํฉ๋๋ค.
[user@testhost ~]$ top | head -10
top - 17:19:13 up 154 days, 6:59, 3 users, load average: 0.21, 0.21, 0.27
Tasks: 2169 total, 2 running, 2080 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.7%us, 0.7%sy, 0.0%ni, 97.5%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 125889960k total, 82423048k used, 43466912k free, 16026020k buffers
Swap: 0k total, 0k used, 0k free, 31094516k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25282 user 20 0 16988 3936 1964 R 7.3 0.0 0:00.04 top
4264 telegraf 20 0 2740m 240m 22m S 1.8 0.2 23409:39 telegraf
6718 root 20 0 35404 4768 3024 S 1.8 0.0 0:01.49 redis-server
์ด ์ ํธ๋ฆฌํฐ์๋ ํ๋ถํ ๊ธฐ๋ฅ์ด ์์ผ๋ฏ๋ก ์์ฃผ ์ฌ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ ํด๋น ์ค๋ช ์๋ฅผ ์ฝ์ด ๋ณด๋ ๊ฒ์ด ์ข์ต๋๋ค.
๋คํธ์ํฌ ํธ๋ํฝ ๋คํ
Linux์์ ๋คํธ์ํฌ ํธ๋ํฝ์ ๊ฐ๋ก์ฑ๊ธฐ ์ํด ์ ํธ๋ฆฌํฐ๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. TCP ๋คํ. ํฌํธ 12345์์ ํธ๋ํฝ์ ๋คํํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
[user@testhost ~]$ sudo tcpdump -i any -A port 12345
์ต์
-A ์ถ๋ ฅ์ ASCII๋ก ๋ณด๊ณ ์ถ๋ค๊ณ ๋งํฉ๋๋ค(๊ทธ๋์ ํ
์คํธ ํ๋กํ ์ฝ์ ์ข์ต๋๋ค). -๋๋ ์๋ฌด๊ฑฐ๋ ์ด๋ ์ฐ๋ฆฌ๊ฐ ๋คํธ์ํฌ ์ธํฐํ์ด์ค์ ๊ด์ฌ์ด ์์์ ๋ํ๋
๋๋ค. ํฌํธ โ ๋คํํ ํฌํธ ํธ๋ํฝ. ๋์ ์ ํฌํธ ์ฌ์ฉํ ์์๋ค. ์ฃผ์ธ๋๋ ์กฐํฉ ์ฃผ์ธ ะธ ํฌํธ (ํธ์คํธ A ๋ฐ ํฌํธ X). ๋ ๋ค๋ฅธ ์ ์ฉํ ์ต์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. -n โ ์ถ๋ ฅ์์ โโ์ฃผ์๋ฅผ ํธ์คํธ ์ด๋ฆ์ผ๋ก ๋ณํํ์ง ๋ง์ญ์์ค.
ํธ๋ํฝ์ด ๋ฐ์ด๋๋ฆฌ์ธ ๊ฒฝ์ฐ์๋ ์ด๋ป๊ฒ ๋๋์? ๊ทธ๋ฌ๋ฉด ์ต์
์ด ์ฐ๋ฆฌ์๊ฒ ๋์์ด ๋ ๊ฒ์
๋๋ค -X โ XNUMX์ง์ ๋ฐ ASCII๋ก ๋ฐ์ดํฐ ์ถ๋ ฅ:
[user@testhost ~]$ sudo tcpdump -i any -X port 12345
๋ ๊ฐ์ง ์ฌ์ฉ ์ฌ๋ก ๋ชจ๋ IP ํจํท์ด ์ถ๋ ฅ๋๋ฏ๋ก ๊ฐ ํจํท์ ์์ ๋ถ๋ถ์ ๋ฐ์ด๋๋ฆฌ IP ๋ฐ TCP ํค๋๊ฐ ์๋ค๋ ์ ์ ๊ณ ๋ คํด์ผ ํฉ๋๋ค. ๋ค์์ ์ฟผ๋ฆฌ "์ ๋ํ ์ถ๋ ฅ ์์ ๋๋ค.123"๊ฐ ํฌํธ 12345์์ ์์ ๋๊ธฐํ๋ ์๋ฒ๋ก ์ ์ก๋์์ต๋๋ค.
[user@testhost ~]$ sudo tcpdump -i any -X port 12345
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
14:27:13.224762 IP localhost.49794 > localhost.italk: Flags [P.], seq 2262177478:2262177483, ack 3317210845, win 342, options [nop,nop,TS val 3196604972 ecr 3196590131], length 5
0x0000: 4510 0039 dfb6 4000 4006 5cf6 7f00 0001 E..9..@.@......
0x0010: 7f00 0001 c282 3039 86d6 16c6 c5b8 9edd ......09........
0x0020: 8018 0156 fe2d 0000 0101 080a be88 522c ...V.-........R,
0x0030: be88 1833 3132 330d 0a00 0000 0000 0000 ...3123.........
0x0040: 0000 0000 0000 0000 00 .........
์ถ๋ ฅ ๋์
๋ฌผ๋ก Linux์๋ Habrรฉ, StackOverflow ๋ฐ ๊ธฐํ ์ฌ์ดํธ์์ ์ฝ์ ์ ์๋ ๋ ๋ง์ ํฅ๋ฏธ๋ก์ด ๋ด์ฉ์ด ์์ต๋๋ค(์๋ฅผ ๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
์ถ์ฒ : habr.com