Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The man page (http://manpages.ubuntu.com/manpages/dapper/man1/prename.1.html) gives two examples:

rename ’s/\.bak$//’ *.bak
rename ’y/A-Z/a-z/’ *

So it's either s or y and then /replaceThis/withThis

What does the leading s and y mean? Are there other options?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

In the first case:

rename ’s/\.bak$//’ *.bak

you are running a regular expression again filenames and replacing matching part of expressions (.bak at the end of a file name) with the second expression (which is empty).

In the second case:

rename ’y/A-Z/a-z/’ *

you are matching against the regular expression pattern space and transliterating to the target. In other words, 'A-Z' is changed to' a-z', making the filenames lower case.

I suggest you look at the man page for sed for more commands and more details. I'll add that I believe the 's' command is used most often. regex (section 7) and perl documentation may also be of help. In particular, here's a tutorial on perl and regular expressions.


s/regexp/replacement/
Attempt to match regexp against the pattern space. If success‐ ful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.

y/source/dest/
Transliterate the characters in the pattern space which appear in source to the corresponding character in dest.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.