Super User is a question and answer site for computer enthusiasts and power users. 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

Hi I have file in my directory as below:


I need to rename as below:


Can you please let me the know a one liner that can do this?

share|improve this question
Is this Unix or Linux? Which Unix? Which Linux? What shell do you use? Do you want to do this for one file or for many similar files? – terdon Sep 27 '13 at 15:08
You're just changing occurrences of rd to pt? – John Bensin Sep 27 '13 at 15:29
Its Unix, Shell: SHELL=/bin/ksh Yes i want to change occurrence of rd to pt. – Yugesh Sep 27 '13 at 16:03

rename can be used for batch renaming files

With your example:

$ rename -v 's/^ewPrd/ewPpt/' *ActiveStores*
ewPrd030MmCommonEaiClcBroker034_RSS.ActiveStores_cache.ver renamed as ewPpt030MmCommonEaiClcBroker034_RSS.ActiveStores_cache.ver
ewPrd030MmCommonEaiClcBroker034_RSS.ActiveStores.Count_cache.dat renamed as ewPpt030MmCommonEaiClcBroker034_RSS.ActiveStores.Count_cache.dat
share|improve this answer
Careful, there are various implementations of rename and they have different formats. Since the OP has not mentioned his OS, this may well not work for him. +1 one though cause that's certainly not your fault. – terdon Sep 27 '13 at 15:47
Hi, the rename command is not working. it is throwing below error:ksh: rename: not found – Yugesh Sep 27 '13 at 16:01
On my system (debian 7) rename is a perl script (provided by the perl package). rename.ul is also installed and works for me (provided by util-linux). – pat Sep 27 '13 at 16:15

If you want to rename many files, do something like this:

for f in *Prd*;do mv "$f" "${f/Prd/Ppt}"; done

This will go through all files whose name contains Prd in the current directory and rename them. It takes advantage of bash's (I am assuming you are using bash) string substitution capabilities.

share|improve this answer
Hi my question was to replace Prd to Ppt. – Yugesh Sep 27 '13 at 16:06
@Yugesh sorry, answer updated. What operating system are you using? Which Unix? rename might be better if it is available to you. Also, this assumes you are using bash. – terdon Sep 27 '13 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .