LINUX locate, find + exec 옵션과 file 명령어

2022. 1. 11. 23:52·System Engineering/리눅스, 라즈베리파이

검색
locate
- 명령어 형식 : locate 파일명
- 목록 데이터베이스를 주기적으로 갱신해줘야 함
- 이름을 기반으로 검색

locate 사용을 위한 데이터베이스 목록 패키지 다운로드
# sudo yum -y install mlocate

locate 데이터베이스 업데이트
# updatedb

locate 명령어 사용
# locate fileA
결과)
/root/fileA
/root/hard_fileA
/root/soft_fileA

 

최상위 디렉토리 하단에 위치한 이름에 file 이라는
단어가 들어가는 모든 파일 중 30k 이상 50k 이하 파일을 검색
# find / -name "*file*" -size +30k -size -50k

최상위 디렉토리 하단에 위치한 이름에 file 이라는
단어가 들어가는 모든 파일 중 30k 이상 50k 이하 파일을 검색하여
dirA에 복사
# mkdir dirA
# find / -name "*file*" -size +30k -size -50k -exec cp {} dirA \;
 - exec 옵션을 사용하여 복사 가능
 - {} 중괄호에 찾은 결과가 들어감
 - exec 옵션을 사용하게 되면 반드시 맨 뒤에 \;

최상위 디렉토리 하단에 위치한 이름에 file 이라는
단어가 들어가는 모든 파일 중 30k 이상 50k 이하 파일을 검색하여
파일 목록을 fileB에 저장
# find / -name "*file*" -size +30k -size -50k > fileB
결과) 
/etc/selinux/targeted/contexts/files/file_contexts.homedirs.bin
/root/dirA/file_contexts.homedirs.bin
/root/dirA/libuser_files.so
/root/dirA/zipfile.pyo
/root/dirA/zipfile.pyc
/usr/lib64/libuser/libuser_files.so
/usr/lib64/python2.7/zipfile.pyo
/usr/lib64/python2.7/zipfile.pyc

file
- file 파일명
- 해당 파일이 무슨 파일인지 확인할 때 사용하는 명령어
# file fileA
결과) fileA: empty
# file fileB
결과) fileB: ASCII text
# file dirA
결과) dirA: directory
# file soft_fileA
결과) soft_fileA: symbolic link to `fileA'

저작자표시 비영리 (새창열림)

'System Engineering > 리눅스, 라즈베리파이' 카테고리의 다른 글

Kernel Update을 해보자 (CentOS7)  (0) 2022.01.25
linux sed command (stream editor)  (0) 2022.01.20
linux tree 명령어  (0) 2021.12.17
apt-get update & apt-get upgrade의 의미  (0) 2021.12.17
vim 검색 방법 (1분만에 배우기)  (0) 2020.06.29
'System Engineering/리눅스, 라즈베리파이' 카테고리의 다른 글
  • Kernel Update을 해보자 (CentOS7)
  • linux sed command (stream editor)
  • linux tree 명령어
  • apt-get update & apt-get upgrade의 의미
Hojae Lee
Hojae Lee
Solutions Architect
  • Hojae Lee
    기억력이 금붕어라
    Hojae Lee
  • 전체
    오늘
    어제
  • 공지사항

    • 참고사항
    • 이 블로그를 잘 활용하는 방법
    • my linkedin
    • 분류 전체보기 (403)
      • Career Path (19)
        • My Achievements (10)
        • About Career (1)
      • Projects for $100 (1)
      • CLOUD (183)
        • Azure Cloud (61)
        • AWS Cloud (120)
      • System Engineering (90)
        • Kubernetes (47)
        • Docker (0)
        • System Design (4)
        • DevOps (2)
        • SRE (5)
        • git (1)
        • 리눅스, 라즈베리파이 (17)
        • Powershell (2)
      • Computer Science (70)
        • Operating System (22)
        • Computer Architecture (5)
        • Network (18)
        • Database (13)
        • Security (9)
        • Machine Learning, AI (1)
      • Cloud Webinar (4)
        • AWS Summit (4)
      • 3D 프린터 (1)
      • IaC (4)
        • CloudFormation (0)
        • Terraform (4)
      • 아두이노 (임베디드) (2)
      • 개발자의 전기 전자 공부 (3)
      • 이전 직장 (11)
        • TMAX Soft (11)
      • 작업 환경 셋업 (3)
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
Hojae Lee
LINUX locate, find + exec 옵션과 file 명령어
상단으로

티스토리툴바