Página Inicial > dicas, shell > renomeie arquivos sem muito esforço

renomeie arquivos sem muito esforço

Lembra do rename do antigo MS-DOS? Algo parecido:

$ cat rename.sh
#!/bin/bash
[ $# -eq 2 ] && for i in *${1}; do mv "${i}" "${i%$1}${2}"; done
 
$ ls *htm
page1.htm  page2.htm  page3.htm  page 4.htm
$ ./rename.sh .htm .html
$ ls *html
page1.html  page2.html  page3.html  page 4.html

O interessante dessa solução é que usa apenas comandos built-in no bash, como a substituição de parâmetros, ao invés de invocar uma sub-shell.

Quer saber mais? Veja o Advanced Bash-Scripting Guide.

Compartilhe:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Rec6
  • Reddit
  • StumbleUpon
Categories: dicas, shell Tags:
  1. Nenhum comentário ainda.
  1. Nenhum trackback ainda.

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word