Trying to change multiple files' extensions
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.
I've tried several examples found on StackExchange:
rename foo foo1 *.foo
and
find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;
Both generate the following error multiple times:
rename: not enough arguments
Any ideas appreciated.
find rename
add a comment |Â
up vote
1
down vote
favorite
Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.
I've tried several examples found on StackExchange:
rename foo foo1 *.foo
and
find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;
Both generate the following error multiple times:
rename: not enough arguments
Any ideas appreciated.
find rename
What is the result of justfind . -name '*.foo'
? Yournot enough arguments
may be from the fact that*.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
â Bailey Parker
Aug 10 at 19:25
You also may want to checkman rename
. Not all renames work that way. Therename
on Debian stretch expects a perl expression and a list of files to apply it to:rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
That does seem to be the error message you'd get from theutil-linux
"version" ofrename
(known asrename.ul
on some systems) when*.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bashshopt -s nullglob
or zshsetopt null_glob
for example)
â steeldriver
Aug 10 at 23:00
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.
I've tried several examples found on StackExchange:
rename foo foo1 *.foo
and
find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;
Both generate the following error multiple times:
rename: not enough arguments
Any ideas appreciated.
find rename
Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.
I've tried several examples found on StackExchange:
rename foo foo1 *.foo
and
find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;
Both generate the following error multiple times:
rename: not enough arguments
Any ideas appreciated.
find rename
find rename
asked Aug 10 at 19:19
mike65535
108116
108116
What is the result of justfind . -name '*.foo'
? Yournot enough arguments
may be from the fact that*.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
â Bailey Parker
Aug 10 at 19:25
You also may want to checkman rename
. Not all renames work that way. Therename
on Debian stretch expects a perl expression and a list of files to apply it to:rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
That does seem to be the error message you'd get from theutil-linux
"version" ofrename
(known asrename.ul
on some systems) when*.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bashshopt -s nullglob
or zshsetopt null_glob
for example)
â steeldriver
Aug 10 at 23:00
add a comment |Â
What is the result of justfind . -name '*.foo'
? Yournot enough arguments
may be from the fact that*.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
â Bailey Parker
Aug 10 at 19:25
You also may want to checkman rename
. Not all renames work that way. Therename
on Debian stretch expects a perl expression and a list of files to apply it to:rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
That does seem to be the error message you'd get from theutil-linux
"version" ofrename
(known asrename.ul
on some systems) when*.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bashshopt -s nullglob
or zshsetopt null_glob
for example)
â steeldriver
Aug 10 at 23:00
What is the result of just
find . -name '*.foo'
? Your not enough arguments
may be from the fact that *.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.â Bailey Parker
Aug 10 at 19:25
What is the result of just
find . -name '*.foo'
? Your not enough arguments
may be from the fact that *.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.â Bailey Parker
Aug 10 at 19:25
You also may want to check
man rename
. Not all renames work that way. The rename
on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
You also may want to check
man rename
. Not all renames work that way. The rename
on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
That does seem to be the error message you'd get from the
util-linux
"version" of rename
(known as rename.ul
on some systems) when *.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob
or zsh setopt null_glob
for example)â steeldriver
Aug 10 at 23:00
That does seem to be the error message you'd get from the
util-linux
"version" of rename
(known as rename.ul
on some systems) when *.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob
or zsh setopt null_glob
for example)â steeldriver
Aug 10 at 23:00
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
Your use of rename
might not work everywhere. Another way to achieve this is to use find
, mv
, and some bash substitution.
find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;
A few things to note:
I use -exec
and not -execdir
. The latter effectively cd
s to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .
--will no longer be correct). You want just -exec
which will run the given command for each file that matches -name '*.foo'
(replacing with the path to the matched file).
"$0%.foo"
strips the extension .foo
so if $0
is "hello.foo"
then "$0%.foo"
ends up as "hello"
. Then adding .foo1
to the end just appends that, so "$0%.foo.foo1"
is "hello.foo1"
.
add a comment |Â
up vote
1
down vote
Use a for
loop
for f in *.foo
do
mv $f $f/.foo/.foo1
done
This would rename a file calledfile.foo-something.foo
tofile.foo1-something.foo
. Better to use"$f%.foo.foo1"
.
â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changedfoo.foo-x
tofoo.foo-x.foo1
. Also, the use offor
loop will eliminate the files that do not end in.foo
.
â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file calledfoo.foo-x
. My example in my comment does end with.foo
though.
â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Your use of rename
might not work everywhere. Another way to achieve this is to use find
, mv
, and some bash substitution.
find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;
A few things to note:
I use -exec
and not -execdir
. The latter effectively cd
s to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .
--will no longer be correct). You want just -exec
which will run the given command for each file that matches -name '*.foo'
(replacing with the path to the matched file).
"$0%.foo"
strips the extension .foo
so if $0
is "hello.foo"
then "$0%.foo"
ends up as "hello"
. Then adding .foo1
to the end just appends that, so "$0%.foo.foo1"
is "hello.foo1"
.
add a comment |Â
up vote
1
down vote
Your use of rename
might not work everywhere. Another way to achieve this is to use find
, mv
, and some bash substitution.
find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;
A few things to note:
I use -exec
and not -execdir
. The latter effectively cd
s to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .
--will no longer be correct). You want just -exec
which will run the given command for each file that matches -name '*.foo'
(replacing with the path to the matched file).
"$0%.foo"
strips the extension .foo
so if $0
is "hello.foo"
then "$0%.foo"
ends up as "hello"
. Then adding .foo1
to the end just appends that, so "$0%.foo.foo1"
is "hello.foo1"
.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Your use of rename
might not work everywhere. Another way to achieve this is to use find
, mv
, and some bash substitution.
find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;
A few things to note:
I use -exec
and not -execdir
. The latter effectively cd
s to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .
--will no longer be correct). You want just -exec
which will run the given command for each file that matches -name '*.foo'
(replacing with the path to the matched file).
"$0%.foo"
strips the extension .foo
so if $0
is "hello.foo"
then "$0%.foo"
ends up as "hello"
. Then adding .foo1
to the end just appends that, so "$0%.foo.foo1"
is "hello.foo1"
.
Your use of rename
might not work everywhere. Another way to achieve this is to use find
, mv
, and some bash substitution.
find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;
A few things to note:
I use -exec
and not -execdir
. The latter effectively cd
s to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .
--will no longer be correct). You want just -exec
which will run the given command for each file that matches -name '*.foo'
(replacing with the path to the matched file).
"$0%.foo"
strips the extension .foo
so if $0
is "hello.foo"
then "$0%.foo"
ends up as "hello"
. Then adding .foo1
to the end just appends that, so "$0%.foo.foo1"
is "hello.foo1"
.
answered Aug 10 at 19:36
Bailey Parker
14318
14318
add a comment |Â
add a comment |Â
up vote
1
down vote
Use a for
loop
for f in *.foo
do
mv $f $f/.foo/.foo1
done
This would rename a file calledfile.foo-something.foo
tofile.foo1-something.foo
. Better to use"$f%.foo.foo1"
.
â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changedfoo.foo-x
tofoo.foo-x.foo1
. Also, the use offor
loop will eliminate the files that do not end in.foo
.
â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file calledfoo.foo-x
. My example in my comment does end with.foo
though.
â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
add a comment |Â
up vote
1
down vote
Use a for
loop
for f in *.foo
do
mv $f $f/.foo/.foo1
done
This would rename a file calledfile.foo-something.foo
tofile.foo1-something.foo
. Better to use"$f%.foo.foo1"
.
â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changedfoo.foo-x
tofoo.foo-x.foo1
. Also, the use offor
loop will eliminate the files that do not end in.foo
.
â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file calledfoo.foo-x
. My example in my comment does end with.foo
though.
â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Use a for
loop
for f in *.foo
do
mv $f $f/.foo/.foo1
done
Use a for
loop
for f in *.foo
do
mv $f $f/.foo/.foo1
done
answered Aug 10 at 20:16
unxnut
3,3802918
3,3802918
This would rename a file calledfile.foo-something.foo
tofile.foo1-something.foo
. Better to use"$f%.foo.foo1"
.
â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changedfoo.foo-x
tofoo.foo-x.foo1
. Also, the use offor
loop will eliminate the files that do not end in.foo
.
â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file calledfoo.foo-x
. My example in my comment does end with.foo
though.
â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
add a comment |Â
This would rename a file calledfile.foo-something.foo
tofile.foo1-something.foo
. Better to use"$f%.foo.foo1"
.
â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changedfoo.foo-x
tofoo.foo-x.foo1
. Also, the use offor
loop will eliminate the files that do not end in.foo
.
â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file calledfoo.foo-x
. My example in my comment does end with.foo
though.
â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
This would rename a file called
file.foo-something.foo
to file.foo1-something.foo
. Better to use "$f%.foo.foo1"
.â Kusalananda
Aug 10 at 20:23
This would rename a file called
file.foo-something.foo
to file.foo1-something.foo
. Better to use "$f%.foo.foo1"
.â Kusalananda
Aug 10 at 20:23
Thanks Kusalananda. However, your pattern changed
foo.foo-x
to foo.foo-x.foo1
. Also, the use of for
loop will eliminate the files that do not end in .foo
.â unxnut
Aug 10 at 21:08
Thanks Kusalananda. However, your pattern changed
foo.foo-x
to foo.foo-x.foo1
. Also, the use of for
loop will eliminate the files that do not end in .foo
.â unxnut
Aug 10 at 21:08
I took your loop into account. It would not process a file called
foo.foo-x
. My example in my comment does end with .foo
though.â Kusalananda
Aug 10 at 21:12
I took your loop into account. It would not process a file called
foo.foo-x
. My example in my comment does end with .foo
though.â Kusalananda
Aug 10 at 21:12
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
â unxnut
Aug 10 at 21:19
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461886%2ftrying-to-change-multiple-files-extensions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What is the result of just
find . -name '*.foo'
? Yournot enough arguments
may be from the fact that*.foo
expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.â Bailey Parker
Aug 10 at 19:25
You also may want to check
man rename
. Not all renames work that way. Therename
on Debian stretch expects a perl expression and a list of files to apply it to:rename 's/e.foo$/foo1/' *.foo
â Bailey Parker
Aug 10 at 19:28
That does seem to be the error message you'd get from the
util-linux
"version" ofrename
(known asrename.ul
on some systems) when*.foo
expands to nothing - although in many shells, that would require non-default globbing behavior (bashshopt -s nullglob
or zshsetopt null_glob
for example)â steeldriver
Aug 10 at 23:00