I have multiple files in a directory, example: linux_file1.mp4, linux_file2.mp4 and so on. How do I move these files, using shell, so that the names are file1.mp4, file2.mp4 and so on. I have about 30 files that I want to move to the new name.
I have multiple files in a directory, example: linux_file1.mp4 , linux_file2.mp4 and so on.
Share
I like mmv for this kind of thing
But you can also use
rename. Be aware that there are commonly tworenamecommands with very different syntax. One is written in Perl, the other is distributed with util-linux, so I distinguish them as “perl rename” and “util rename” below.With Perl rename:
As cweiske correctly pointed out.
With util rename:
How can you tell which rename you have? Try running
rename -V; if your version is util rename it will print the version number and if it is perl rename it will harmlessly report and unknown option and show usage.If you don’t have either
renameormmvand don’t want to or can’t install them you can still accomplish this with plain old shell code:This syntax will work with any POSIX sh conforming to XPG4 or later, which is essentially all shells these days.