Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I rename “*.foo” to “*.bar”, or change file names to lowercase?

file lowercase names RENAME
0
Posted

How do I rename “*.foo” to “*.bar”, or change file names to lowercase?

0

Why doesn’t “mv *.foo *.bar” work? Think about how the shell expands wildcards. “*.foo” and “*.bar” are expanded before the mv command ever sees the arguments. Depending on your shell, this can fail in a couple of ways. CSH prints “No match.” because it can’t match “*.bar”. SH executes “mv a.foo b.foo c.foo *.bar”, which will only succeed if you happen to have a single directory named “*.bar”, which is very unlikely and almost certainly not what you had in mind. Depending on your shell, you can do it with a loop to “mv” each file individually. If your system has “basename”, you can use: C Shell: foreach f ( *.foo ) set base=`basename $f .foo` mv $f $base.bar end Bourne Shell: for f in *.foo; do base=`basename $f .foo` mv $f $base.bar done Some shells have their own variable substitution features, so instead of using “basename”, you can use simpler loops like: C Shell: foreach f ( *.foo ) mv $f $f:r.bar end Korn Shell: for f in *.foo; do mv $f ${f%foo}bar done If you don’t have “basenam

0

Why doesn’t ‘mv *.foo *.bar’ work? Think about how the shell expands wildcards. “*.foo” and “*.bar” are expanded before the mv command ever sees the arguments. Depending on your shell, this can fail in a couple of ways. CSH prints “No match.” because it can’t match “*.bar”. SH executes “mv a.foo b.foo c.foo *.bar”, which will only succeed if you happen to have a single directory named “*.bar”, which is very unlikely and almost certainly not what you had in mind. Depending on your shell, you can do it with a loop to mv each file individually. If your system has basename, you can use: • csh: foreach f ( *.foo ) set base=`basename $f .foo` mv $f $base.bar end • sh: for f in *.foo; do base=`basename $f .foo` mv $f $base.bar done If you don’t have basename or want to do something like renaming foo.* to bar.*, you can use something like sed to strip apart the original file name in other ways, but the general looping idea is the same. You can also convert file names into mv commands with sed,

0

Why doesn’t “mv *.foo *.bar” work? Think about how the shell expands wildcards. “*.foo” and “*.bar” are expanded before the mv command ever sees the arguments. Depending on your shell, this can fail in a couple of ways. CSH prints “No match.” because it can’t match “*.bar”. SH executes “mv a.foo b.foo c.foo *.bar”, which will only succeed if you happen to have a single directory named “*.bar”, which is very unlikely and almost certainly not what you had in mind. Depending on your shell, you can do it with a loop to “mv” each file individually. If your system has “basename”, you can use: C Shell: foreach f ( *.foo ) set base=`basename $f .foo` mv $f $base.bar end Bourne Shell: for f in *.foo; do base=`basename $f .foo` mv $f $base.bar done Some shells have their own variable substitution features, so instead of using “basename”, you can use simpler loops like: C Shell: foreach f ( *.foo ) mv $f $f:r.bar end Korn Shell: for f in *.foo; do mv $f ${f%foo}bar done If you don’t have “basenam

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.