I have 8k+ text files that I would like to rename with the first line of text of the respective file. Most lines are up to three words but some are more complex, with commas and other punctuation, e.g. "My Milk(also known as Annie Ps 'Tell The Milk' ".
I have used this:
for i in *.txt; do mv "$i" "$(head -1 "$i")".txt; done
Only issue I am having is files getting overwritten. I guess I will have to append a sequence to mitigate this.