A maneira como eu abordaria isso é obter os uuids do arquivo primeiro e depois usar find
awk '{print $1}' listfile.txt | while read fileName;do find /etc -name "$fileName*" -printf "%p FOUND\n" 2> /dev/null;done
Para facilitar a leitura,
awk '{print $1}' listfile.txt | \
while read fileName;do \
find /etc -name "$fileName*" -printf "%p FOUND\n" 2> /dev/null;
done
Exemplo com uma lista de arquivos em /etc/, procurando nomes de arquivos passwd, group, fstab e THISDOESNTEXIST.
$ awk '{print $1}' listfile.txt | while read fileName;do find /etc -name "$fileName*" -printf "%p FOUND\n" 2> /dev/null; done
/etc/pam.d/passwd FOUND
/etc/cron.daily/passwd FOUND
/etc/passwd FOUND
/etc/group FOUND
/etc/iproute2/group FOUND
/etc/fstab FOUND
Como você mencionou que o diretório é plano, você pode usar a -printf "%f\n"opção para imprimir o próprio nome do arquivo
O que isso não faz é listar os arquivos ausentes. findA pequena desvantagem é que ele não informa se não encontra um arquivo, apenas quando corresponde a algo. O que se poderia fazer, no entanto, é verificar a saída - se a saída estiver vazia, temos um arquivo ausente
awk '{print $1}' listfile.txt | while read fileName;do RESULT="$(find /etc -name "$fileName*" -printf "%p\n" 2> /dev/null )"; [ -z "$RESULT" ] && echo "$fileName not found" || echo "$fileName found" ;done
Mais legível:
awk '{print $1}' listfile.txt | \
while read fileName;do \
RESULT="$(find /etc -name "$fileName*" -printf "%p\n" 2> /dev/null )"; \
[ -z "$RESULT" ] && echo "$fileName not found" || \
echo "$fileName found"
done
E aqui está como ele funciona como um pequeno script:
skolodya@ubuntu:$ ./listfiles.sh
passwd found
group found
fstab found
THISDONTEXIST not found
skolodya@ubuntu:$ cat listfiles.sh
#!/bin/bash
awk '{print $1}' listfile.txt | \
while read fileName;do \
RESULT="$(find /etc -name "$fileName*" -printf "%p\n" 2> /dev/null )"; \
[ -z "$RESULT" ] && echo "$fileName not found" || \
echo "$fileName found"
done
Pode-se usar statcomo alternativa, já que é um diretório simples, mas o código abaixo não funcionará recursivamente para subdiretórios se você decidir adicioná-los:
$ awk '{print $1}' listfile.txt | while read fileName;do stat /etc/"$fileName"* 1> /dev/null ;done
stat: cannot stat ‘/etc/THISDONTEXIST*’: No such file or directory
Se pegarmos a statideia e executá-la, poderíamos usar o código de saída stat como indicação para a existência ou não de um arquivo. Efetivamente, queremos fazer o seguinte:
$ awk '{print $1}' listfile.txt | while read fileName;do if stat /etc/"$fileName"* &> /dev/null;then echo "$fileName found"; else echo "$fileName NOT found"; fi ;done
Exemplo de execução:
skolodya@ubuntu:$ awk '{print $1}' listfile.txt | \
> while read FILE; do
> if stat /etc/"$FILE" &> /dev/null ;then
> echo "$FILE found"
> else echo "$FILE NOT found"
> fi
> done
passwd found
group found
fstab found
THISDONTEXIST NOT found