Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove part of filename and add extension programmatically?

I have hundreds of files in one folder named like this:

index.html?tab=This is - the file name

I would like to remove "index.html?tab=" part and add extension ".txt" to all files. How can I do this using Unix command line tools (I'm using MacOSX 10.6.2)?

like image 893
jraja Avatar asked Feb 01 '26 00:02

jraja


2 Answers

In bash,

for i in index.html\?tab\=*; do mv "$i" "${i:15}.txt"; done
like image 130
kennytm Avatar answered Feb 02 '26 17:02

kennytm


for file in index.html\?*
do
   mv "$file" "${file#*=}".txt
done
like image 39
ghostdog74 Avatar answered Feb 02 '26 16:02

ghostdog74



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!