Como posso pesquisar nomes de arquivos que estão começando com xy_ * e são criados / editados hoje?

0

Olá, no momento, estou tentando pesquisar arquivos de log que estão iniciando com xy_Number e são criados / editados hoje (e não nas últimas 24 horas).

Eu tentei:

find /home/USER/logfilesError/ -maxdepth 1 -type f -daystart -mtime -1 print0 | xargs -0 grep - l xy_*

Saída:

find: paths must precede expression: print0

Eu preciso combinar:

find -maxdepth 1 -type f -daystart -mtime -1

e

ls | grep -E "xy_"

O que eu quero alcançar é:

Pesquise arquivos de log de um local específico que seja a data de hoje e, em seguida, vá um pouco além e pesquise esses arquivos e exiba os que têm linhas iniciando com ERROR. (outras linhas INFO e DEBUG)

Portanto, a pesquisa funciona bem e eu quero ir mais longe com a verificação dos arquivos após a pesquisa com um grep para encontrar os arquivos que contêm ERROR

grep -rl "ERROR" /home/USER/logfilesError/

Como eu combino esses em um script? Com se? Alguém pode me ajudar com isso?

    
por BlueFox 06.06.2014 / 07:34

2 respostas

1

Por que usar o grep, o find pode fazer o trabalho:

find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" -daystart -mtime -1
    
por 06.06.2014 / 07:38
1

Pelo que parece, você está procurando por -name :

find /path -maxdepth 1 -type f -name 'xy_*' -daystart -mtime -1 -exec grep -H ERROR {} +

De man find :

-name pattern

Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (‘*’, ‘?’, and ‘[]’) match a ‘.’ at the start of the base name (this is a change in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a directory and the files under it, use −prune; see an example in the description of −path. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don’t forget to enclose the pattern in quotes in order to protect it from expansion by the shell.

    
por 06.06.2014 / 07:36