I would like to add the .zip extension to all files. I tried this, however it does not work:

ls | awk '{print $1 " " $1".zip"}' | xargs mv -f
up vote 2 down vote accepted

Searching - few links:

  1. Recursively add file extension to all files - Stack Overflow
  2. Add file extension to files with bash - Stack Overflow

man rename:

NAME
       rename - renames multiple files

SYNOPSIS
       rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION
       "rename" renames the filenames supplied according to the rule specified as 
       the first argument.  The perlexpr argument is a Perl expression which is 
       expected to modify the $_ string in Perl for at least some of the filenames 
       specified. If a given filename is not modified by the expression, it will not 
       be renamed.  If no filenames are given on the command line, filenames will be 
       read via standard input...

man wiki: http://en.wikipedia.org/wiki/Man_page

  • thx, based on that I was able to do it like this - ls | xargs -I % mv % %.zip – UAdapter Oct 31 '11 at 9:30
for f in * ; do 
  mv "$f" "$f.zip"
done
rename 's/$/\.zip/' *

Don't use xargs for that!

  • why don't use xargs? – UAdapter Nov 1 '11 at 14:50
  • 1
    Well - there's just no reason! – Adobe Nov 1 '11 at 15:13

A very simple way to do that is :

if you want to keep current extension:

for i in *; do mv $i ${i}.zip; done     

if you want to replace current extension:

for i in *; do mv $i ${i%.*}.zip; done

This should do the trick:

mmv "./*" "./#1.zip"

(Although I have no idea why you would want to do this...)

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.