Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to rename the following:




How do I make it happen with just one simple line of terminal command?

share|improve this question

The Internet is a encyclopedia that unless you know the answer, you won't find it. So I took a little time to understand the EXTREMELY simple solution:


the solution to the above example is:

rename -v -n 's/file_\d{1,3}/upl/' file_*.png

// rename [options] [regex search/replace] [in these files]
// -v = verbose, display what you are doing on screen
// -n = "do Not, just show what might happen", in other words, use '-n' if you want to test the end result

rename MAY take regex as the arguments.

What we are looking at is the content between the apostrophes '. You can place regex separated by /.

formula: s/(1)/(2)/ where:

(1) = search,

(2) replace.

So, familiarize youself with regex, and enjoy pattern based batch file renaming!

share|improve this answer
I know this is Ubuntu, but if anyone ends up here even though they were looking for an OS X solution (I did), rename is easily installed with brew install rename. – sandstrom Mar 14 at 13:41

This can be done with little magic of bash parameter expansion!

for f in file_[0-9]*_*; do mv $f upl_${f#file_[0-9]*_}; done

file_[0-9]*_*; - First pattern is used to go trough all files that begin with 'file_anynumber_'
${f#file_[0-9]*_} - The second pattern file_[0-9]*_ is used in parameter expansion which tells bash to remove 'file_anynumber_' from the begging of the string.

For more information on Parameter expansion:

man bash
share|improve this answer

Your Answer


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.