msoliver
(usa Debian)
Enviado em 26/06/2017 - 22:04h
ede_linux escreveu:
A saída deste script:
#VAR
log=/home/xx/xx/xx/xx/log4.c
#script
echo "----------------- Initial Folder ----------------------">>$log
date>>$log
echo "-------------------------------------------------------">>$log
cd /home/xx/xx
find -type f -exec file -ib {} \; | awk '{count[$1]++}END{for(j in count) print j,"("count[j]" occurences)"}' | awk '{print NR , $0}' | tee -a $log
awk '/^6|^1|^9/ {print $0}' $log
echo "-------------------------------------------------------">>$log
date>>$log
È esta:
1 application/octet-stream; (959 occurences)
2 application/x-dosexec; (134 occurences)
3 image/jpeg; (4 occurences)
4 application/winhelp; (11 occurences)
5 application/x-rar; (1 occurences)
6 text/plain; (290 occurences)
7 application/vnd.ms-powerpoint; (1 occurences)
8 application/x-archive; (2 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
1 application/octet-stream; (959 occurences)
6 text/plain; (290 occurences)
9 application/msword; (1 occurences)
10 application/pdf; (6 occurences)
11 image/gif; (17 occurences)
Após o negrito, aparece 10 vez, repetido, os valores referente aos números 1, 6 e 9. Isso ocorre por causa desta parte do código, certo:
{print $0}' - em (awk '/^6|^1|^9/ {print $0}' $log)
Eu acho que estamos a pegar o valor do caminho no local errado.
Porque no programa find, na instrução principal, eu apenas contabilizo, logo não considero os caminhos absolutos. Certo?
Nota: Isto é a opinião de quem não percebe nada em shell script :P :) Ao vosso lado ainda sou um menino! hehe
O ideal/objectivo é pegar o caminho absoluto de todos os ficheiros com os "tipos" escolhidos. Que são:
1-octet-stream
6-ext/plain
9-application/msword
Obrigado
Boa noite, Ede.
Vamos aos pontos.
1 - O comando
"awk '/^6|^1|^9/ {print $0}' $log "
Não deve ficar Junto com os comandos que contam os tipos de arquivos . . .
É para ser usado na seguinte situação:
Esses são os "tipos de ARQUIVOS":
1 application/x-xz; (1 occurences)
2 application/gzip; (1 occurences)
3 inode/x-empty; (1 occurences)
4 application/zip; (1 occurences)
5 text/plain; (87 occurences)
6 text/html; (6 occurences)
7 text/x-shellscript; (165 occurences)
8 application/x-sharedlib; (1 occurences)
9 application/vnd.oasis.opendocument.text; (1 occurences)
10 application/pdf; (2 occurences)
read -p " COPIAR quais TIPOS de ARQUIVO: " TIPO
RESPOSTA do USUÁRIO: 1,5,7
TIPO=$(sed -r 's/[0-9]/\^&/g;s/,/|/g' <<< "$TIPO")
Agora, usa aquele comando . . .
awk '/'$TIPO'/ {print $0}' $log
Quanto ao caminho absoluto,
É "perdido" no comando:
awk '{count[$1]++}END{for(j in count) print j,"("count[j]" occurences)"}'
Conforme voce mencionou . . .
Vejo que não tem como "contar" o tipo do arquivo e guardar o caminho . . .
Seu script está muito bom . . .
Tem que desenvolver um modo de copiar pelo tipo ou extensão do arquivo...
att.:
Marcelo Oliver