1

I made a mistake with rename command

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

After that the files are not under their folders as they used to be and every file has . in front of them. Now my customers can not see the files. Once I remove the . then they can see the files.

How can I remove . from the files. Like this:

.finacialyear2008half.doc

to

finacialyear2008half.doc

Please help me! I need a fast fix.

1
  • The next time use rename -n for a dry-run. It just prints how it would rename your files without doing anything to them.
    – scai
    Nov 22, 2013 at 14:32

2 Answers 2

1

find . -type f -exec rename 's/\.//' '{}' \;

Think about -n parameter of rename : it just display what it will do after you remove it !

4
  • find . -type f -exec rename 's/\.//' find: missing argument to `-exec'
    – cr0c
    Nov 22, 2013 at 8:16
  • Sorry : I edit my entry
    – Dom
    Nov 22, 2013 at 8:17
  • Can't rename ./.maksuvladtabelina.xlsx /.maksuvladtabelina.xlsx: Invalid cross-device link <- Any ideas?
    – cr0c
    Nov 22, 2013 at 8:21
  • 1
    OK : change the find . to your absolute path !
    – Dom
    Nov 22, 2013 at 8:23
0

Assuming you are using bash you can loop through the files replacing first occurrences of /. with / in the filenames of all files in the current folder.

for filename in $(find . -maxdepth 1 -type f)
do
  mv -v $filename ${filename/\/.//}
done

This assumes that you don't need to recursively rename files, and will only work in current directory (-maxdepth 1).

Disclaimer: always backup your files or at least try with a bunch of test files before performing any actions on your data.

You must log in to answer this question.

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