I have several files with names like '8.7blahblahblah', and I want to change the '.' to a '-' in all of them without having to rename each file one by one using 'mv'. Is there a way to do this in bulk?
5 Answers
You can also script the rename process using a bash script to handle the moving. This involves creating a script that generates new names for you. It's a bit complex, but a powerful method if you're comfortable with some coding!
Before running any commands, I suggest testing them on some example files to make sure they perform as you expect. For instance, you can create a test directory and test files. Then, to replace the first '.' with a '-', run this command: `find . -type f -name '*.*' -exec rename 's/./-/g' {} +`. For replacing all occurrences, there’s a more complex script that can handle it. Just try to double-check what each command does before applying!
If you install Midnight Commander, you can easily select your files in the target directory and use the F6 key to rename them all at once. Just specify the source mask as '*.*' and the destination pattern like '1-2'. It's a simple way to change characters in the file names!
You might want to try using 'mmv', which stands for multiple move. Not every Linux distro includes it in their repositories, but most do. It's pretty handy for bulk renaming tasks like this!
Be sure you have the 'rename' command installed. If you don't have it yet, install it with 'sudo apt install rename'. Then you can run this in your terminal: `rename 's/./-/g' *.*` to rename your files.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures