Skip to content

Instantly share code, notes, and snippets.

@washere
washere / filename-firstline.sh
Last active May 18, 2024 05:06 — forked from dylan-k/filename-firstline.sh
rename each text file according to its first line of text
#This is a fork of dylan-k code. Only the actual short line to rename inside a loop is changed to a long line.
#Original code gave errors on some special characters. For example if a back slash \ was in the first line to be used as new name.
#Those files were not renamed. This new line ignores those problematic characters and even more, using alphanumeric naming.
#Many ways to do alpnum renaming are suggested but most actually fail in many cases and bashes and distros.
#This new forked way, alpnum renaming will not fail.
#dylan-k: A shell script that will rename all the text files in a directory
#each file will be named with the first line of text from that file
for file in *
do