Bash tip: How to change file extensions in batch mode
Have the article read aloud.
If you have a whole series of files whose endings you want to change, renaming them manually can be quite tedious. Fortunately, this can be done super easily and quickly in the shell - with a single command. Whether it's .txt to .xlf, .csv to .json or any other combination, the trick works for all file extensions.
Here is an example of how you can rename all .txt files in a directory to .xlf:
for file in *.txt; do mv "$file" "${file%.txt}.xlf"; done What exactly happens here?
- for file in *.txt: This part of the command searches the current directory for all files ending with .txt. You can of course replace .txt with any extension.
- mv "$file" "${file%.txt}.xlf": The mv command takes over the renaming. ${file%.txt} removes the old ending and .xlf is added. Again, .txt and .xlf are just placeholders for the endings you want to change.
If you want to see which files are affected first, you can also test the whole thing without renaming the files straight away. Simply use this command:
for file in *.txt; do echo mv "$file" "${file%.txt}.xlf"; done This lists all changes without actually making them. This way you can make sure that everything fits before you execute the command correctly.
This simple shell trick saves you a lot of time and makes editing lots of files at once really efficient.
BackDo you have a question or want to discuss the topic?
In the Community Hub for TYPO3 you can exchange ideas with other TYPO3 users. And if you don't want to miss any new articles: The TYPO3 Newsletter comes once a month, without spam.
Hi, I'm Wolfgang.
I have been working with TYPO3 since 2006. Not in theory, but in real projects with real deadlines. I've probably had the problems you're having three times already.
At some point, I started putting my knowledge into video courses. Not because I like being in front of the camera, but because I kept hearing the same questions over and over again. There are now hundreds of videos. Every single one was the result of a specific question from a specific project.
What makes me different from a YouTube tutorial: I not only know the solution, but also the context. Why something works. When it doesn't work. And which mistakes you can avoid because I've already made them.
My participants use me as a sparring partner. Not in the sense of "call me anytime", but like this: You come to the live session with a specific problem, post your question in the community or watch the appropriate video. And get an answer that works because it comes from practical experience.
As a member of the TYPO3 Education & Certification Committee, I make sure that the certification exams are kept up to date. What is tested there flows directly into my courses.