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

I have a set of files that are named in the vein of "some_file-nameN", where N is a number starting at 1, incrementing, and ending somewhere between 10 and 30. I now need to insert a file at the start. How can I increment the number of the file using ZMV and ZSH?

share|improve this question

Starting from the directory containing the files, and assuming the range is 1 to 30:

for n in {30..1};
mv some_file-name$n some_file-name$(( $n+1 ))
share|improve this answer
    
worked for me--thanks for posting. It looks like zmv doesn't provide this feature. – Paul Oliver Jul 16 '14 at 2:28

Of course zsh can do it.

zmv '(some_file_name)(<->)' '$1$(($2 + 1))'

This should work for any number of files.

share|improve this answer

You must log in to answer this question.

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