리눅스 파일 관련 명령어2 (file, find, locate)

주영·2023년 10월 25일
0

Linux Master

목록 보기
11/11
post-thumbnail

파일 관련 명령어2 (file, find, locate)

6. file

  • Usage: file [옵션] 파일명
  • 파일의 종류 및 파일 속성값 출력
  • 옵션
    • -b: 파일명은 출력하지 않고 파일 유형만 표시
    • -f: 파일 목록에서 지정한 파일들에 대해서만 명령 실행
    • -z: 압축된 파일의 내용 출력
# file --help
Usage: file [OPTION...] [FILE...]
Determine type of FILEs.

  -z, --uncompress           try to look inside compressed files
  -b, --brief                do not prepend filenames to output lines
  -f, --files-from FILE      read the filenames to be examined from FILE
  ...
  • 예시

    [root@worker juyoung]# file a.txt
    a.txt: empty
    [root@worker juyoung]# file /etc/passwd
    /etc/passwd: ASCII text
    
    // -b 옵션
    [root@worker juyoung]# file -b a.txt
    empty
    [root@worker juyoung]# file -b /etc/passwd
    ASCII text
    

7. find

  • Usage: find [경로][옵션] [정규표현식][파일명]
  • 현재 디렉터리에서부터 하위 디렉터리까지 주어진 조건의 파일을 찾아 해당 경로를 표시
  • 옵션
    • -name: 이름을 기준으로 파일 검색
    • -user: user의 파일이나 디렉터리 검색
    • -perm: 지정된 권한의 파일 검색
    • -size: 지정된 크기의 파일 검색 (+: 이상, -: 이하)
    • -type: 파일 유형에 따라 파일 검색
    • -atime n: n일 이전에 접근한 파일 검색
    • -exec: 검색된 파일에 수행할 명령어 지정
  • 예시
    1) -name 옵션
    // /etc에 확장자 conf 파일 검색
    $ find /etc -name "*.conf"
    /etc/geoclue/geoclue.conf 
    /etc/vmware-tools/vgauth.conf
    ...
    2) -user 옵션
    $ find / -user kube
    /usr/libexec/kubernetes
    /usr/libexec/kubernetes/kubelet-plugins
    /usr/libexec/kubernetes/kubelet-plugins/volume
    /usr/libexec/kubernetes/kubelet-plugins/volume/exec
    /usr/local/bin/kubernetes-scripts
    /opt/cni
    /opt/cni/bin
    /etc/cni
    /etc/cni/net.d
    /etc/kubernetes
    /etc/kubernetes/ssl
    /etc/kubernetes/manifests
    find:/proc/4061923/task/4061923/fd/6: No such file or directory
    find:/proc/4061923/task/4061923/fdinfo/6: No such file or directory
    find:/proc/4061923/fd/7: No such file or directory
    find:/proc/4061923/fdinfo/7: No such file or directory
    /var/lib/calico
    3) -perm 옵션
    // 허가권이 644인 파일 검색
    $ find ~ -perm 644
    /root/.local/share/gnome-shell/gnome-overrides-migrated
    /root/.local/share/gnome-shell/application_state
    ...
    4) -size 옵션
    // 10kbyte 이상 100kbyte 이하인 크기의 파일 검색
    $ find . -size +10k -size -100k
    ./.local/share/tracker/data/tracker-store.ontology.journal
    ./.local/share/tracker/data/tracker-store.journal
    ...
    5) -atime n 옵션
    $ find . -atime 6
    ./.config/user-dirs.dirs

8. locate

  • Usage: locate [파일명]

  • 파일의 위치 찾기

  • 예시

    [root@worker ~]# locate kubelet.conf
    /etc/kubernetes/kubelet.conf
    
    [root@worker ~]# locate *.bak
    /etc/nsswitch.conf.bak
    /var/lib/containers/storage/overlay/f0b4644b09acc454e1e5f4af6bfcac2092590fd5084191aa982e0610c7d1980e/diff/etc/nsswitch.conf.bak
    /var/lib/nfs/statd/sm.bak
    

참고: 2021 이기적 리눅스마스터 2급

0개의 댓글

관련 채용 정보