


Assuming you are in the directory where you wish to change all files in the current directory to a new file extension, here is the syntax to use:įor file in *.txt do mv "$file" "$.jpeg" done

In the first example, we’re going to change all files in the present working directory with the extension “.txt” and change them to “.py” instead. How to Change All File Extensions in a Directory via the Command Line Failure to do so could result in data loss, the Terminal is unforgiving to typos or mistakes, so don’t skip your backups. OK? Alright on to the command line approach using a simple one line bash script.īy the way you should always make a copy and/or backup of the files you are modifying, particularly if you are new to the command line. However, the Terminal is not the only way to do this, and so if this is too advanced or irrelevant to your user skill set then recall that Mac OS offers simple tools to both batch rename files in Mac OS and batch change file extensions in the Finder as well, neither of which requires the command line at all. Additionally, this walkthrough approach is intentionally using the command line and is thus aimed at more advanced users. Before beginning, realize this is not changing a file type, it is only changing the file extension.
