fbpx

Shell command to bulk change file extensions in a directory (Linux)

This article will explain how to change the file extension for all files in a directory in Linux using a simple bash shell command.

1. Change from one extension to another
The command below will rename all files with the extension .php4 to .php

for f in *.php4; do mv $f `basename $f .php4`.php; done;

2. Add (append) an extension to all files
The command below add the extension .txt to all files in the directory

for f in *; do mv $f `basename $f `.txt; done;

3. Remove (delete) an extension from all files
The command below remove the extension .txt from all files in the directory

for f in *.txt; do mv $f `basename $f .txt`; done;

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn
GMS, We Provide Solutions

GMS, We Provide Solutions

We are focused on delivering the best to our clients and visitors.

Get The Latest Updates

Subscribe To Our Deals Newsletter

No spam, notifications only about new products, updates and Deals.