Batch renaming files using Bash

Such as adding prefix, replacing strings, removing suffix etc.

A few examples:

fisher_Parenchyma_1.genes_Results.txt –> pfam_Parenchyma_1.genes_Results.txt

for i in fisher*.txt; do mv "$i" "${i/fisher/pfam}";done

Xft2-2.1.13.pkg –> Xft2.pkg

for i in ./*.pkg ; do mv "$i" "${i/-[0-9.]*.pkg/.pkg}" ; done

replace all whitespaces with dashes

for i in *; do mv "$i" ${i//\ /-}; done

delete .sh extensions

for i in *.sh; do mv $i ${i/%.sh/}; done # % indicates the end and # indicates the start

add prefix a.txt –> prefix_a.txt

for i in *.txt; do mv "$i" "prefix_$i"; done
comments powered by Disqus
CC-BY-NC 4.0
Built with Hugo Theme Stack