2022. 10. 18. 15:48ㆍ리눅스
ln
- link 파일 생성 (soft, hard)
- # ln [옵션] 원본파일 링크파일
옵션
‐s : soft link 생성 (디렉토리의 경우 soft link만 가능)
‐f : 대상이 존재하는 경우 지우고 link파일 생성
심볼릭 링크(symbolic link)와 하드 링크(hard link)
- 심볼릭 링크 : 원본 파일의 위치정보를 가지는 단축 아이콘으로 특정 파일 을 가리키고 있는 파일이다. 다른 파일시스템에서도 링크가 가능하다. 별도의 inode를 가지며 링크 파일이 가지고 있는 용량만큼 디스크의 공간을 차지하며 원본의 링크 카운트가 증가하지 않는다.
- 하드 링크 : 원본 파일과 동일한 inode를 가진다. 그렇기 때문에 원본이었던 파일이 삭제 되더라도 동일 inode를 갖고 있는 링크 파일은 여전히 사용 가능하다. 서로 다른 파일시스템에서는 생성이 불가능하며 링크 카운트가 증가한다.
실습)
[root@Linux1 ~]# echo aa > 1.txt
[root@Linux1 ~]# ln 1.txt 2.txt
[root@Linux1 ~]# ls -li *.txt
33805112 -rw-r--r--. 2 root root 3 10월 7 11:43 1.txt
33805112 -rw-r--r--. 2 root root 3 10월 7 11:43 2.txt
[root@Linux1 ~]# ls -l *.txt
-rw-r--r--. 2 root root 3 10월 7 11:43 1.txt
-rw-r--r--. 2 root root 3 10월 7 11:43 2.txt
[root@Linux1 ~]# ln -s 1.txt 3.txt
[root@Linux1 ~]# ls -li *.txt
33805112 -rw-r--r--. 2 root root 3 10월 7 11:43 1.txt
33805112 -rw-r--r--. 2 root root 3 10월 7 11:43 2.txt
33805135 lrwxrwxrwx. 1 root root 5 10월 7 11:44 3.txt -> 1.txt
[root@Linux1 ~]# rm 1.txt
rm: remove 일반 파일 `1.txt'? y
[root@Linux1 ~]# ls -li *.txt
33805112 -rw-r--r--. 1 root root 3 10월 7 11:43 2.txt
33805135 lrwxrwxrwx. 1 root root 5 10월 7 11:44 3.txt -> 1.txt
more(less)
화면 출력을 화면 단위로 제어
출력되는 내용이 많아서 화면을 넘어가는 경우 사용
# more 파일
| (파이프(연결))
앞 명령의 결과를 뒤 명령의 입력 값으로 이용
# ls –al | more
grep
- 필터링
- 출력 문자열중에 원하는 단어나 글자가 들어있는 라인만 출력하고자 할때 이용
command | grep [필터링 문자열]
ex) ls –al | grep conf
실습)
[root@Linux1 ~]# cat -n /etc/passwd | grep ftp
12 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@Linux1 ~]# env | grep HOME
HOME=/root
env(환경변수)
- 현재 지정되어 있는 환경 변수들을 출력하거나, 새로운 환경변수를 설정하고 적용된 내용을 출력하는 명령어
head, tail
- 파일의 일부분을 출력. 각각 앞 뒤에서 10 라인 씩 출력
옵션
‐n ## : 지정한 라인만큼 출력
‐c ## : 지정한 byte 만큼 출력
‐f : tail에서만 사용, 실시간 추가되는 내용도 출력
주로 log 정보 확인 시 사용한다.
실습)
[root@Linux1 ~]# ls /etc/ > list.txt
[root@Linux1 ~]# head -n 5 list.txt
DIR_COLORS
DIR_COLORS.256color
DIR_COLORS.lightbgcolor
GREP_COLORS
GeoIP.conf
[root@Linux1 ~]# tail -f -n 5 /var/log/messages
Oct 7 12:10:01 Linux1 systemd: Started Session 23 of user root.
Oct 7 12:20:01 Linux1 systemd: Started Session 24 of user root.
Oct 7 12:30:01 Linux1 systemd: Started Session 25 of user root.
Oct 7 12:40:01 Linux1 systemd: Started Session 26 of user root.
Oct 7 12:50:01 Linux1 systemd: Started Session 27 of user root.
find
- 파일시스템에서 조건에 만족하는 파일을 검색한다.
# find 검색경로 검색조건1 검색조건2 …
검색조건
‐name : 파일명으로 검색 (와일드카드문자 사용)
‐perm : 특정 퍼미션을 가진 파일을 검색
‐empty : 크기가 0인 파일 검색
검색조건
‐user : 지정한 사용자가 소유한 파일
‐group : 지정한 구룹이 소유한 파일
‐nouser : 소유자가 없는 파일
‐nogroup : 그룹 소유자가 없는 파일 / 검색하고자 하는 파일의 종류 지정
‐type : b(block), c(char), d(dir), l(slink), f(regular)
‐mount : 마운트된 파일 시스템만 검색
‐empty : 빈 파일 검색
실습)
[root@Linux1 ~]# find /var/ -name *.conf
/var/lib/NetworkManager/NetworkManager-intern.conf
/var/lib/libvirt/dnsmasq/default.conf
[root@Linux1 ~]# find /etc/ /var/ -name ???.conf
/etc/lsm/pluginconf.d/sim.conf
/etc/sos.conf
/etc/rdma/modules/opa.conf
/etc/X11/xinit/xinput.d/xim.conf
/etc/yum.conf
/etc/lvm/lvm.conf
/etc/dbus-1/system.d/gdm.conf
/etc/samba/smb.conf
/etc/PackageKit/Yum.conf
/etc/sane.d/dll.conf
/etc/sane.d/dmc.conf
/etc/sane.d/v4l.conf
/etc/sane.d/ibm.conf
/etc/sane.d/leo.conf
/etc/sane.d/nec.conf
/etc/sane.d/net.conf
/etc/sane.d/pie.conf
/etc/sane.d/u12.conf
/etc/nfs.conf
/etc/ntp.conf
[root@Linux1 ~]# find /dev/ -name sd* -type b
/dev/sda3
/dev/sda2
/dev/sda1
/dev/sda
find 명령 에러
find: paths must precede expression:……
‐name 옵션 사용시 문자열을 인식하지 못하는 에러이다.
이런 경우 문자열에 ''를 추가한다.
find / ‐name *.txt --> find / ‐name '*.txt'
'리눅스' 카테고리의 다른 글
리눅스 기초명령어 3(tar, gzip, bzip, clock, date, rdate) (0) | 2022.10.19 |
---|---|
VI 편집기 (0) | 2022.10.18 |
리눅스 기초명령어 1(cd, pwd, rmdir, mkdir, ls, 리다이렉트, cat, echo, cp, mv, rm) (0) | 2022.10.18 |
리눅스 기초(명령어 표기 및 디렉토리 표현방법) (0) | 2022.10.18 |
기본 설치 (0) | 2022.10.18 |