shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Renomear arquivos em massa?


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] Renomear arquivos em massa?
Date: Wed, 5 Dec 2007 10:07:08 -0200

Vinícius,

o que foi utilizado no comando abaixo lembra expressões regulares, mas
não é. Isto é uma feature do shell chamada "Pathname Expansion".

O shell expande os caracteres * ? e [ de forma que todos os arquivos e
diretorios que 'casarem' com o padrão são substituidos na linha de
comando.

Faça esse exemplo:

$ echo *

Alem das expansões normais existe outras, as expandidas, que precisa
que a opção extglob do shell esteja ativada, no bash são

              ?(pattern-list)
                     Matches zero or one occurrence of the given patterns
              *(pattern-list)
                     Matches zero or more occurrences of the given patterns
              +(pattern-list)
                     Matches one or more occurrences of the given patterns
              @(pattern-list)
                     Matches exactly one of the given patterns
              !(pattern-list)
                     Matches anything except one of the given patterns

Mas vc pode utilizar expressões regulares para encotrar arquivos e
mandar para o rm.

find <opcoes>  | xargs rm -i

a opção para o find é -regex

       -regex pattern
              File  name  matches  regular  expression  pattern.
This  is  a match on the whole path, not a search.  For example, to
match a file named
              `./fubar3', you can use the regular expression `.*bar.'
or `.*b.*3', but not `b.*r3'.


[]´s T

On 12/5/07, Vinícius de Figueiredo Silva <address@hidden> wrote:
>
> On Dec 5, 2007 9:38 AM, Flavio Junior <address@hidden> wrote:
>  >
>  > Existe um tal de "rename" pra isso.. mas eu não gosto :P
>  >
>  >  faça:
>  >  $ for file in *.[jJ][Pp][Gg]; do echo mv $file ${file//_/}; done
>  >
>
>
>  Maneiro, não sabia que podia usar expressões regulares ali no mv! :]
>
>


-- 
Tiago B Peczenyj
Linux User #405772

http://peczenyj.blogspot.com/
"what does not kill us makes us stronger"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]