I have a number of files that end in a '.1', for example:
example.file.ex1.1
example.file.ex2.1
example.file.ex3.1
Is there a way that I can quickly rename them all without the '.1' at the end (e.g. example.file.ex1, example.file.ex2, etc.)?
Thanks!
Change File Extensions From the Terminal And if you want to change the extension (or the name), you'd use the mv command. mv stands for "move" and is the standard command on Linux for moving and renaming files.
Yes, try this with rename :
rename -n 's/\.1$//' *
remove the -n
(dry-run mode switch) if your tests are valid.
There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command (linux
)
$ file $(readlink -f $(type -p rename))
and you have a result like
.../rename: Perl script, ASCII text executable
then this seems to be the right tool =)
If not, to make it the default (usually already the case) on Debian
and derivative like Ubuntu
:
$ sudo update-alternatives --set rename /path/to/rename
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.
Pure bash solution:
for curFile in example.file.*.1; do
mv -- "$curFile" "${curFile:0:-2}"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With