0

So I've accidently gave all my files, php, js, html, css files a .gz ending, so they look like:

.bowerrc.gz
index.php.gz
main.css.gz

etc...

Using Centos 6.4, how can I revert back all the files?

I tried

rename .gz '' *.gz

but it fails, nor find helped me as it doesn't do it recursively in all folders.

Thanks

deb0rian
  • 143
  • 2
  • 8

2 Answers2

2

Whenever I've had to do something similar, I use a for loop with a find:

for file in `find . -name \*.gz`
do
  new=`echo $file | sed 's/.gz//'`
  mv $file $new
done

There's no guarantee this will actually work, since it's from memory, but that's the type of construct I would start with.

John
  • 8,920
  • 1
  • 28
  • 34
1

This should do the trick.

find ./ -type f -name "*.gz" | while read file; do
  mv "${file}" "${file%%.gz}"
done

This may pick up files genuinely named ".gz" and rename them too, be careful. Only does files.

Matthew Ife
  • 22,927
  • 2
  • 54
  • 71