2012-10-20 2 views

답변

3

사용 발견 (이 공급 된 디렉토리 경로 CWD 또는 재귀 검색) :

#!/bin/bash 
... 

directory_path=~/src/reviewboard/reviewboard 
file_name=views.py 

file_count=$(find $directory_path -name $file_name | wc -l) 

if [[ $file_count -gt 0 ]]; then 
    echo "Warning: $file_name found $file_count times in $directory_path!" 
fi 
... 
1

find /path/to/dir -name "filename" | wc -l하는 당신에게 줄 것이다 : bash는 스크립트의 일부로이 사용

find $directory_path -name $file_name | wc -l 

예 파일이 /path/to/dir 및 하위 디렉토리 내에있는 횟수입니다. 0보다 큰 결과는 파일이 올바른 경로에 있음을 나타냅니다. 결과가 0이면 파일이 경로 내에 없거나 존재하지 않는다는 의미입니다.

1

find는 파일을 찾을 수없는 경우 아무 것도 반환하지 않습니다 (null 문자열). if [ '' ]은 FALSE로 평가됩니다.

if [ $(find "$search_dir" -name "$filename") ]; then 
    echo "$filename is found in $search_dir" 
else 
    echo "$filename not found" 
fi 
관련 문제