1

I have about 50 files in a directory that contain spaces, apostrophes, etc. How can I go about mass-renaming them to remove the apostrophes and replaces spaces with underscores?

I can do

ls | grep '*.txt' | xargs ....

but I'm not sure what to do in the xargs bit

Geuis
  • 41,122
  • 56
  • 157
  • 219
  • possible duplicate of [How to do a mass rename?](http://stackoverflow.com/questions/417916/how-to-do-a-mass-rename) – Greg Hewgill Apr 12 '11 at 04:14

1 Answers1

2

I use ren-regexp, which is a Perl script that lets you mass-rename files very easily.

You'd do something like ren-regexp 's/ /_/g' *.txt.

$ ls -l
total 16
-rw-r--r--  1 marc  marc  7 Apr 11 21:18 That's a wrap.txt
-rw-r--r--  1 marc  marc  6 Apr 11 21:18 What's the time.txt

$ ren-regexp "s/\'//g" "s/ /_/g" *.txt

  That's a wrap.txt
1 Thats a wrap.txt
2 Thats_a_wrap.txt

  What's the time.txt
1 Whats the time.txt
2 Whats_the_time.txt


$ ls -l
total 16
-rw-r--r--  1 marc  marc  7 Apr 11 21:18 Thats_a_wrap.txt
-rw-r--r--  1 marc  marc  6 Apr 11 21:18 Whats_the_time.txt
Marc Abramowitz
  • 3,447
  • 3
  • 24
  • 30