# ls -l /etc/passwd

-rw-r--r-- 1 root root 1729 Jul  8 04:41 /etc/passwd

|~~~~~~~~~ ~ ~~~~ ~~~~ ~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~

|    |     |  |    |    |       |             |

|    |     |  |    |    |       |             +-- 파일명 (mv)

|    |     |  |    |    |       +-- 파일수정 날짜 (MAC time) (touch)

|    |     |  |    |    +-- 파일크기 (vi, cat, echo ...)

|    |     |  |    +-- 그룹 (chgrp)

|    |     |  +-- 소유자 (chown)

|    |     +-- 하드링크 개수 (ln)

|    +-- 권한(퍼미션) (chmod)

+- 파일의 종류 (파일을 생성할 때 결정된다.)



1. 파일의 종류

# ls -l /bin/bash         -  (정규 파일)

- jpg, gif, exe, txt ...

- touch , vi , cat , echo ...


# ls -ld /bin             d  (디렉토리 파일)

- 폴더의 개념 

- mkdir 


# ls -l /dev/log          s  (소켓 파일   : 통신용)

- mksock


# ls -l /dev/initctl      p  (파이프  파일: 통신용)

- mkfifo, mknod 


# ls -l /dev/sda1         b  (장치 파일   : 블럭 디바이스)

- mknod


# ls -l /dev/tty1         c  (장치 파일   : 문자 디바이스)

- mknod


# ls -l /bin/sh           l  (링크 파일   : 심볼릭링크 or 소프트링크)

- 윈도우의 바로가기

- ln -s 


- chmod 실습

[root@localhost ~]# mkdir chmod; cd chmod; pwd

/root/chmod

[root@localhost chmod]# cp /etc/passwd .

[root@localhost chmod]# ls 

passwd

[root@localhost chmod]# ls -l

total 4

-rw-r--r-- 1 root root 1729 Jul  9 04:07 passwd

[root@localhost chmod]# chmod o-r  passwd

[root@localhost chmod]# ls -l

total 4

-rw-r----- 1 root root 1729 Jul  9 04:07 passwd


- ln 실습

[root@localhost chmod]# mkdir ../ln ; cd ../ln

[root@localhost ln]# pwd

/root/ln

[root@localhost ln]# touch lntest.txt

[root@localhost ln]# ls -l lntest.txt 

-rw-r--r-- 1 root root 0 Jul  9 04:22 lntest.txt

[root@localhost ln]# ln lntest.txt lntest2.txt

[root@localhost ln]# ls -l

total 0

-rw-r--r-- 2 root root 0 Jul  9 04:22 lntest2.txt

-rw-r--r-- 2 root root 0 Jul  9 04:22 lntest.txt

[root@localhost ln]# ln lntest.txt lntest3.txt

[root@localhost ln]# ls -l

total 0

-rw-r--r-- 3 root root 0 Jul  9 04:22 lntest2.txt

-rw-r--r-- 3 root root 0 Jul  9 04:22 lntest3.txt

-rw-r--r-- 3 root root 0 Jul  9 04:22 lntest.txt



- chown 실습

[root@localhost ln]# mkdir ../chown; cd ../chown

[root@localhost chown]# cat /etc/shadow > shadow

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root root 1227 Jul  9 04:40 shadow

[root@localhost chown]# ls -l /etc/shadow

-r-------- 1 root root 1227 Jul  8 04:41 /etc/shadow

[root@localhost chown]# chown nobody shadow 

[root@localhost chown]# ls -l shadow 

-rw-r--r-- 1 nobody root 1227 Jul  9 04:40 shadow

[root@localhost chown]# chown root shadow

[root@localhost chown]# ls -l shadow 

-rw-r--r-- 1 root root 1227 Jul  9 04:40 shadow


- chgrp 실습

[root@localhost chown]# chgrp users shadow

[root@localhost chown]# ls -l 

total 4

-rw-r--r-- 1 root users 1227 Jul  9 04:40 shadow

[root@localhost chown]# chgrp bin shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root bin 1227 Jul  9 04:40 shadow

[root@localhost chown]# chgrp root shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root root 1227 Jul  9 04:40 shadow


[root@localhost chown]# grep 43 /etc/group

xfs:x:43:

[root@localhost chown]# chgrp xfs shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root xfs 1227 Jul  9 04:40 shadow

[root@localhost chown]# grep 0 /etc/group

root:x:0:root

wheel:x:10:root

games:x:20:

gopher:x:30:

dip:x:40:

ftp:x:50:

users:x:100:

avahi:x:70:

ecryptfs:x:101:

stapdev:x:102:

stapusr:x:103:

webuser:x:500:

testuser:x:501:

user1:x:502:

user2:x:503:

user3:x:504:

[root@localhost chown]# 

[root@localhost chown]# grep 0 /etc/group

[root@localhost chown]# chgrp 0 shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root root 1227 Jul  9 04:40 shadow

[root@localhost chown]# chgrp 43 shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root xfs 1227 Jul  9 04:40 shadow

[root@localhost chown]# grep 1000 /etc/group

[root@localhost chown]# chgrp 1000 shadow 

[root@localhost chown]# ls -l

total 4

-rw-r--r-- 1 root 1000 1227 Jul  9 04:40 shadow



- /etc/passwd, /etc/passwd- 를 확인할 수 있는 실습

[root@localhost chown]# ls -l /etc/passwd*

-rw-r--r-- 1 root root 1729 Jul  8 04:41 /etc/passwd

-rw------- 1 root root 1776 Jul  8 04:40 /etc/passwd-

[root@localhost chown]# useradd abc

[root@localhost chown]# ls -l /etc/passwd*

-rw-r--r-- 1 root root 1764 Jul  9 05:10 /etc/passwd

-rw------- 1 root root 1729 Jul  8 04:41 /etc/passwd-

[root@localhost chown]# tail -2 /etc/passwd-

user2:x:503:503::/home/user2:/bin/bash

user3:x:504:504::/home/user3:/bin/bash

[root@localhost chown]# tail -3 /etc/passwd

user2:x:503:503::/home/user2:/bin/bash

user3:x:504:504::/home/user3:/bin/bash

abc:x:505:505::/home/abc:/bin/bash

[root@localhost chown]# 



touch

- MAC time의 시간을 수정하는 명령어

[root@localhost chown]# mkdir ../touch ; cd ../touch

[root@localhost touch]# install -m 644 /etc/passwd .

[root@localhost touch]# ls -l 

total 4

-rw-r--r-- 1 root root 1764 Jul  9 05:17 passwd

[root@localhost touch]# ls -l /etc/passwd

-rw-r--r-- 1 root root 1764 Jul  9 05:10 /etc/passwd

[root@localhost touch]# date

Thu Jul  9 05:18:08 KST 2015

[root@localhost touch]# stat passwd 

  File: `passwd'

  Size: 1764       Blocks: 8          IO Block: 4096   regular file

Device: 811h/2065d Inode: 672517      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2015-07-09 05:17:19.000000000 +0900

Modify: 2015-07-09 05:17:19.000000000 +0900

Change: 2015-07-09 05:17:19.000000000 +0900


[root@localhost touch]# rdate -s time.bora.net

[root@localhost touch]# date

Thu Jul  9 17:20:35 KST 2015

[root@localhost touch]# touch  passwd 

[root@localhost touch]# stat passwd 

  File: `passwd'

  Size: 1764       Blocks: 8          IO Block: 4096   regular file

Device: 811h/2065d Inode: 672517      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2015-07-09 17:20:44.000000000 +0900

Modify: 2015-07-09 17:20:44.000000000 +0900

Change: 2015-07-09 17:20:44.000000000 +0900


[root@localhost touch]# date

Thu Jul  9 17:24:04 KST 2015

[root@localhost touch]# ls -l

total 4

-rw-r--r-- 1 root root 1764 Jul  9 17:20 passwd

[root@localhost touch]# chmod o-r passwd 

[root@localhost touch]# ls -l

total 4

-rw-r----- 1 root root 1764 Jul  9 17:20 passwd

[root@localhost touch]# stat passwd 

  File: `passwd'

  Size: 1764       Blocks: 8          IO Block: 4096   regular file

Device: 811h/2065d Inode: 672517      Links: 1

Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2015-07-09 17:20:44.000000000 +0900

Modify: 2015-07-09 17:20:44.000000000 +0900

Change: 2015-07-09 17:25:11.000000000 +0900


[root@localhost touch]# date

Thu Jul  9 17:51:34 KST 2015

[root@localhost touch]# head -1 passwd

root:x:0:0:root:/root:/bin/bash

[root@localhost touch]# stat passwd 

  File: `passwd'

  Size: 1764       Blocks: 8          IO Block: 4096   regular file

Device: 811h/2065d Inode: 672517      Links: 1

Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: ( 1000/ UNKNOWN)

Access: 2015-07-09 17:51:46.000000000 +0900

Modify: 2015-07-09 17:20:44.000000000 +0900

Change: 2015-07-09 17:37:17.000000000 +0900




+ Recent posts