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.

cr0c
  • 958
  • 4
  • 16
  • 35
  • 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 '13 at 14:32

2 Answers2

1

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

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

Dom
  • 6,743
  • 1
  • 20
  • 24
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.

Ketola
  • 311
  • 1
  • 3