0

I have a large number of files which I would like to rename. Here is an example of how I would like to change the file names:

From:

PD5 grey nice display 1.jpg

To:

pd5-grey-nice-display-showcase-1.jpg

What is the command line code I would need to use?

1 Answer 1

6

If you have Perl's rename:

rename -n '$_=lc;s/ /-/g;s/([0-9]+)\./showcase-$1\./' your_file_name

should do the trick.

Explanation:

  • $_=lc convert all characters to lowercase
  • s/ /-/g replace all single spaces by a dash (use s/ +/-/g if you anticipate multiple consecutive spaces)
  • s/([0-9]+)\./showcase-$1\./ looks for a sequence of consecutive digits followed by a dot (marking the filename extension) and adds showcase- before that sequence.

Note

  • The above code won't do anything, it will just print out the new file name without actually renaming the file. After you make sure it works correctly, you can remove the -n switch.
0

You must log in to answer this question.

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