Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • This is close to correct but it will fail on filenames with spaces or punctuation in them. It would also be a better answer if you explained why you are using -type. Commented Jul 24, 2013 at 10:04
  • @msw What problem do you see with file names with whitespace? This will, however, fail on files in subdirectories that contain lowercase letters, as it will attempt to rename e.g. foo/bar.ext to FOO/BAR.ext (hd. used -execdir to work around this problem). Commented Jul 24, 2013 at 21:56
  • @Gilles , there is no fail with directory as -type f only gives the file path. and renames $1 & $2 only touches the files inside the dir. Commented Jul 25, 2013 at 5:01
  • @Giles I think you know the answer as you used the more inclusive pattern in your answer, but \w+ will not match test file or test-file and many other such likely names. It also uses . when it should have \.. Also since @Ameer commented while I was writing this, without -execdir you need to ensure that only the last path component is matched yielding (untested) s!/([^/]*)\.([^/]*)$!—! Commented Jul 25, 2013 at 5:08