• Meetings e Workshop
    l'associazione organizza workshop e meeting periodici

  • HowTo e manuali
    come costruire da te gadget elettronici e come programmarli

  • Hacking della PS3
    howto su come installare linux ed effettuare altri hack

  • Una comunità organizzata
    entra a far parte di una associazione organizzata e attiva

  • Strumenti di supporto
    per mantenersi in contatto e favorire la cooperazione

snippet - rename multiplo di file - UPDATED PDF Stampa E-mail
Scritto da Carlo Denaro - Blackout   
Carlo Denaro - Blackout

Stamattina ho imparato a usare il bash script per rinominare tanti file con un solo comando. Prima facevo in maniera molto più dispendiosa e tediosa.

 

 

I miei file erano del tipo:

resized_xxxxxxx_large.jpg e li dovevo rinominare in xxxxxxx_normal.jpg con xxxxxxx = 31 caratteri

Allora il prode xanio mi consiglia di usare rename per fare il task.

rename -v 's/resized_(\w{31})_large\.jpg/$1\_normal\.jpg/' *.jpg

oppure con un semplice ciclo for se si tratta solo dell'estensione

for f in *.tgz; do mv $f `basename $f .tgz`.tar.gz; done;

ancora un altro esempio (by Allanon)

find $1 -name *.cbz -exec rename -v 's/(w+-)(d{1}).cbz/${1}00${2}.cbz/' {} ;

Ecco uno scorcio di man di rename

Syntax

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

-v
Verbose: print names of files successfully renamed.
-n
No Action: show what files would have been renamed.
-f
Force: overwrite existing files.
perlexpr
Perl Expression

Regular Expressions

^
matches the beginning of the line
$
matches the end of the line
.
Matches any single character
(character)*
match arbitrarily many occurences of (character)
(character)?
Match 0 or 1 instance of (character)
[abcdef]
Match any character enclosed in [] (in this instance, a b c d e or f)
ranges of characters such as [a-z] are permitted. The behaviour
of this deserves more description. See the page on grep
for more details about the syntax of lists.
[^abcdef]
Match any character NOT enclosed in [] (in this instance, any character other than a b c d e or f)
(character)\{m,n\}
Match m-n repetitions of (character)
(character)\{m,\}
Match m or more repetitions of (character)
(character)\{,n\}
Match n or less (possibly 0) repetitions of (character)
(character)\{n\}
Match exactly n repetitions of (character)
\(expression\)
Group operator.
\n
Backreference - matches nth group
expression1\|expression2
Matches expression1 or expression 2. Works with GNU sed, but this feature might not work with other forms of sed.
\w
matches any single character classified as a “word” character (alphanumeric or “_”)
\W
matches any non-“word” character
\s
matches any whitespace character (space, tab, newline)
\S
matches any non-whitespace character
\d
matches any digit character, equiv. to [0-9]
\D
matches any non-digit character

 

Commenti  

 
#1 Antibes Moncler 2015-02-18 03:56 My coder is trying to convince me to move to .net from
PHP. I have always disliked the idea because of
the costs. But he's tryiong none the less. I've been using Movable-type on a variety
of websites for about a year and am concerned about
switching to another platform. I have heard fantastic things about blogengine.net.
Is there a way I can import all my wordpress posts into it?
Any kind of help would be greatly appreciated!
Citazione
 

Aggiungi commento


Codice di sicurezza
Aggiorna


grayhats.org, Powered by Joomla!; Joomla templates by SG web hosting
valid xhtml valid css