1

So I just ran the following command to add a file extension to a bunch of files. I thought I would undo them one by one, but it turns out I need to undo them all at one time, how do I reverse this?

find . -name '*.targetFileType' -type f -exec mv '{}' '{}'.not \;
  • Before the file was: aFile.targetFileType
  • Now it is: aFile.targetFileType.not

I need to return it to aFile.targetFileType

builder-7000
  • 7,131
  • 3
  • 19
  • 43
Sam Carleton
  • 1,339
  • 7
  • 23
  • 45
  • Similar question: [Find and replace filename recursively in a directory](https://stackoverflow.com/questions/9393607/find-and-replace-filename-recursively-in-a-directory#9394625) – builder-7000 Nov 30 '19 at 04:07
  • 1
    `find . -name '*.not' -type f -exec bash -c 'echo "$1" "${1/.not/}"' -- {} \;` – builder-7000 Nov 30 '19 at 04:09

1 Answers1

0

I have managed to reverse with:

for f in $(find . -name '*.not' -type f); do mv ${f} $(echo ${f} | sed 's/.not//g'); done;

dracoboros
  • 55
  • 2
  • 7
  • 1
    note there is no need to launch extra processes to convert `file.not` to just `file`. try `echo mv "${f}" "${f%.not}"` and remove `echo` when you are sure it is working correctly. Good luck. – shellter Nov 30 '19 at 05:13
  • 1
    When a filename starts with `-`, this will be seen as an option. Use `mv -- "${f}" "${f%.not}"`. – Walter A Nov 30 '19 at 07:48