디렉터리 및 하위 디렉터리에서 파일 수를 찾는 방법


이 가이드에서는 현재 작업 디렉토리 또는 Linux 시스템의 다른 디렉토리 및 하위 디렉토리에있는 총 파일 수를 표시하는 방법을 다룹니다.

디렉토리 계층 구조에서 파일을 검색하는 데 사용되는 find 명령과 각 파일의 줄 바꿈, 단어 및 바이트 수를 인쇄하는 wc 명령, 또는 표준 입력에서 읽은 데이터를 사용합니다.

다음은 find 명령과 함께 사용할 수있는 옵션입니다.

  1. -type – specifies the file type to search for, in the case above, the f means find all regular files.
  2. -print – an action to print the absolute path of a file.
  3. -l – this option prints the total number of newlines, which is equals to the total number of absolute file paths output by find command.

find 명령의 일반 구문입니다.

# find . -type f -print | wc -l
$ sudo find . -type f -print | wc -l

중요 : 아래 스크린 샷에서와 같이“Permission denied”오류를 방지하려면 sudo 명령을 사용하여 수퍼 유저 권한이있는 하위 디렉터리의 파일을 포함하여 지정된 디렉터리의 모든 파일을 읽습니다.

위의 첫 번째 명령에서 현재 작업 디렉토리의 모든 파일을 find 명령으로 읽는 것은 아님을 알 수 있습니다.

다음은 각각 /var/log /etc 디렉토리의 총 일반 파일 수를 보여주는 추가 예제입니다.

$ sudo find /var/log/ -type f -print | wc -l
$ sudo find /etc/ -type f -print | wc -l

Linux find 명령 및 wc 명령에 대한 더 많은 예제는 추가 사용 옵션, 팁 및 관련 명령에 대한 다음 일련의 문서를 참조하십시오.

  1. 35 Useful ‘find’ Command Examples in Linux
  2. How to Find Recent or Today’s Modified Files in Linux
  3. Find Top 10 Directoires and Files Disk Space in Linux
  4. 6 Useful ‘wc’ Command Examples to Count Lines, Words and Characters

그게 다야! "디렉토리 및 하위 디렉토리에있는 총 파일 수를 표시하는 다른 방법을 알고있는 경우 의견을 통해 공유하십시오.