Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Are there any legitimate uses for newlines in filenames?

Parent

Are there any legitimate uses for newlines in filenames?

+8
−0

Unix is very permissive with filenames, and this can sometimes lead to a bunch of annoying corner cases when printing files. A well known example is when you put a newline in a filename, and it breaks naive parsing of a file list later in the pipeline.

There's not much mystery around why Unix decided to be permissive with filenames, so I'm not asking why newlines are allowed in filenames.

However, are there any situations where it is useful (or necessary, or desirable...) to have newlines in filenames? Hypothetical is okay, but "in the wild" would be even better.

I've only seen it when someone is deliberately trying to set up a trap (hacking, pranks) or by accident (programmer forgot to add a whitespace normalizer to their filename generator).

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

3 comment threads

A related question (opinion based) is are there practical cases where a very long file name is useful... (2 comments)
About newlines and other problems with filenames (2 comments)
Fun fact: comparison of allowed characters (1 comment)
Post
+3
−0

I do this occasionally. It is sometimes useful to compare file titles where they aren't fixed lengths.

For example:

01           02
The Beatles  The Rolling Stones
Help         Satisfaction
.mp3         .flac

That can be the file name, or the first few lines of a file.

I don't use it terribly often.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

2 comment threads

id3tool for music (1 comment)
What tool do you use to display these names in a way that makes use of the newlines? Or how exactly d... (1 comment)
What tool do you use to display these names in a way that makes use of the newlines? Or how exactly d...
Kamil Maciorowski‭ wrote over 1 year ago

What tool do you use to display these names in a way that makes use of the newlines? Or how exactly do you "compare files titles"? Many modern tools sanitize such names when displaying to a human (i.e. in GUI or when printing to a terminal) and it takes some effort to make them stop. Do you use like ls | cat? My point is: if one does not know how to display the newlines in filenames nor how to make a good use of them in a script then he or she won't find newlines (and your answer) useful.