Change all file extensions in a folder using CLI on Linux

How to change all file extensions in a folder with a single command in CLI on Linux?

+4
source share
4 answers

Use rename:

rename 's/.old$/.new/' *.old

+11
source

If you have perl installed rename(there are various implementations rename), you can do something like this:

$ ls -1
test1.foo
test2.foo
test3.foo

$ rename 's/\.foo$/.bar/' *.foo

$ ls -1
test1.bar
test2.bar
test3.bar
+4
source

for-loop :

for foo in *.old; do mv $foo `basename $foo .old`.new; done

.old .new

+1

: ( .)

find . -type f -exec mv '{}' '{}'.jpg \;

Explanation: this recursively finds all files (-type f), starting from the current directory (.) And applies the move (mv) command to each of them. Also note the quotes around {} so that file names with spaces (and even newlines ...) are handled correctly.

-1
source

Source: https://habr.com/ru/post/1530211/


All Articles