Menu Home

Raspberry Pi: Renaming all file extensions in a directory

In this post I will show you how I used a single line script that I found buried within a comment to a Unix.Stackexchange answer to rename all the file extensions in a directory.

The single line script

for f in *.OLD; do mv -- "$f" "${f%.PREVIOUS}.NEW"; done

To use, start a new terminal session and change to the directory that were the files reside. Copy and paste the command into the terminal, replacing the two occurrences of OLD and the single NEW.

In the example below I used the script to rename all the file extensions from .h264 to .mp4

for f in *.h264; do mv -- "$f" "${f%.h264}.mp4"; done

Acknowledgements

This Unix.Stackexchange comment was the inspiration for this post.

Categories: Raspberry Pi

oraclefrontovik

Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.