I used the following command to attempt to remove special characters and replace them with a "." how can I undo this action?

find . -type f -exec rename 's/[^A-Za-z0-9._]/./g' {} +

I have used Ubuntu for over 10 years, but don't have much regex experience, I should have tested the above command on unimportant files first, DOH!

When I browse the folder from a windows machine, it flashes a bunch of hidden files for a second, so I assume they are all still there, just with some odd naming that prevents them from being accessed.

Obviously the command had a syntax error, or that I should have used a "_" instead of a "."

Any help is greatly appreciated.

  • Not possible to undo the action. Try to get a pattern/view in the current names, and then we can help with renaming these to your desired form (now). – heemayl Nov 23 '16 at 3:41
  • when I do from the command line "ls -l" it does not show the files any longer, when browsing the share from windows it shows the files for a split second and they all start with two ".." would it be possible to rename the first two characters of all files to _ I think maybe that would unhide them. – xekon Nov 23 '16 at 3:44
  • yes all files now start with ".." also they are now all in the root directory instead of their respective sub folders. – xekon Nov 23 '16 at 3:48
  • would this work? rename 's/^/1_/' * – xekon Nov 23 '16 at 3:51
  • 1
    Since ``find` prepends the starting point to its results, find . -type f would have resulted in a listing like ./dir/file, then your -exec rename would have replaced all the path separators as periods resulting in ..dir.file and so on – steeldriver Nov 23 '16 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.