Linux Bash Shell Script - 크기가 0인 파일을 찾아 삭제합니다.

Linux Bash Shell Script - 크기가 0인 파일을 찾아 삭제합니다.

파일 목록은 변수에 저장됩니다 REMOVEFILES. 스크립트는 파일 목록을 하나씩 확인해야 하며 파일이 ZERO충분히 크면 삭제해야 합니다. 문제를 해결하도록 도와주세요.

#!/bin/bash  
REMOVEFILES=target_execution.lst,source_execution.lst;  
echo $REMOVEFILES  
for file in $(REMOVEFILES)  
do  
        echo "$file";  
        if [[ -f "$file" ]]; then  
        find $file -size 0c -delete;  
        else  
         :  
        fi  
done  

./a.sh: line 3: REMOVEFILES: command not found

답변1

에서 zsh이러한 파일에 한 줄에 하나의 파일 경로가 포함되어 있고 크기가 0인 일반 파일인 경우 .lst해당 파일은 삭제하려는 파일입니다(파일 자체가 아님)..lst

#! /bin/zsh -
  
lists=(
  target_execution.lst
  source_execution.lst
)

rm -f -- ${(f)^"$(cat -- $lists)"}(N.L0)

그것으로 bash, 당신은 항상 그것을 할 수 있습니다

#! /bin/bash -
lists=(
  target_execution.lst
  source_execution.lst
)
to_remove=()
process() {
  [[ -f "$1" && ! -L "$1" && ! -s "$1" ]] && to_remove+=( "$1" ) 
}
for file in "${lists[@]}"; do
  readarray -c 1 -C process < "$file"
done
rm -f -- "${to_remove[@]}" 

관련 정보