Loading...

Rename multiple files

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

My current migration from WordPress to Jekyll took me the WordPress exporter of Jekyll. It generated html files. I want to migrate them to markdown, therefore I needed a quick solution to rename all html files into files with markdown file extensions.

Let’s have a look first on directory structure:

tan@omega:~/sources/my-awesome-site/_posts$ ll
total 28
drwxrwx--- 1 tan tan     0 Apr 23 21:10 ./
drwxrwx--- 1 tan tan 24576 Apr 24 09:29 ../
drwxrwx--- 1 tan tan     0 Apr 23 21:10 2015/
drwxrwx--- 1 tan tan  4096 Apr 23 21:10 2016/
drwxrwx--- 1 tan tan     0 Apr 23 21:10 2017/

Let’s check the last 10 entries

tan@omega:~/sources/my-awesome-site/_posts$ find . -name "*.html" -exec echo {} \; | tail
./2016/09/2016-09-14-localization-problem-while-deinstalling-oracle-11g-on-windows.html
./2016/09/2016-09-15-handling-logstash-input-multiline-codec.html
./2016/09/2016-09-19-reindex-data-in-elasticsearch.html
./2016/09/2016-09-20-amazing-video-for-an-amazing-song.html
./2016/09/2016-09-21-groups-of-groups-in-ansible.html
./2016/09/2016-09-21-secret-nations-tonight.html
./2016/09/2016-09-24-use-ansible-for-cluster-management.html
./2016/09/2016-09-25-correct-type-mapping-in-index-template-for-elasticsearch.html
./2016/09/2016-09-28-checking-for-running-port-on-windows-cmd.html
./2016/09/2016-09-28-monitor-process-and-used-ports-of-kibana.html

Total sum of affected files

tan@omega:~/sources/my-awesome-site/_posts$ find . -name "*.html" -exec echo {} \; | wc -l
280

Use Perl’s rename command with regular expression:

find . -name "*.html" -exec rename -v 's/\.html$/\.md/' {} \;

The verbose option of rename shows the detailed rename action.

./2016/09/2016-09-15-handling-logstash-input-multiline-codec.html renamed as ./2016/09/2016-09-15-handling-logstash-input-multiline-codec.md
./2016/09/2016-09-19-reindex-data-in-elasticsearch.html renamed as ./2016/09/2016-09-19-reindex-data-in-elasticsearch.md
./2016/09/2016-09-20-amazing-video-for-an-amazing-song.html renamed as ./2016/09/2016-09-20-amazing-video-for-an-amazing-song.md
./2016/09/2016-09-21-groups-of-groups-in-ansible.html renamed as ./2016/09/2016-09-21-groups-of-groups-in-ansible.md
./2016/09/2016-09-21-secret-nations-tonight.html renamed as ./2016/09/2016-09-21-secret-nations-tonight.md
./2016/09/2016-09-24-use-ansible-for-cluster-management.html renamed as ./2016/09/2016-09-24-use-ansible-for-cluster-management.md
./2016/09/2016-09-25-correct-type-mapping-in-index-template-for-elasticsearch.html renamed as ./2016/09/2016-09-25-correct-type-mapping-in-index-template-for-elasticsearch.md
./2016/09/2016-09-28-checking-for-running-port-on-windows-cmd.html renamed as ./2016/09/2016-09-28-checking-for-running-port-on-windows-cmd.md
./2016/09/2016-09-28-monitor-process-and-used-ports-of-kibana.html renamed as ./2016/09/2016-09-28-monitor-process-and-used-ports-of-kibana.md
Please remember the terms for blog comments.