Fixing Unix/Linux/POSIX Filenames | Linux Today

Fixing Unix/Linux/POSIX Filenames

Written By
Web Webster
Web Webster
Mar 26, 2009

“A Tale of Complications
magine that you don’t know Unix/Linux/POSIX (I presume you really
do), and that you’re trying to do some simple things with it. For
example, let’s try to print out the contents of all files in the
current directory, putting it into a file above:

cat * > ../collection

“The list doesn’t include “hidden” files (filenames beginning
with “.”), but often that’s what you want anyway, so that’s not
unreasonable. The problem is that although this usually works,
filenames could begin with “-” (e.g., “-n”). So if there’s a file
named “-n”, and you’re using GNU cat, all of a sudden your output
will be numbered! Oops; that means on every command we have to
disable option processing; for most commands that means using “–”
everywhere, except not all commands support “–” (ugh!). There are
lots of traps, e.g., for portability you’re supposed to use
printf(1) not echo(1) if the first parameter might start with a
“-“. Many people know that prefixing the filename or glob with “./”
can resolve these kinds of problems (e.g., “cat ./*”), and most
versions of “find” do prefix filenames by default. But not all
programs do such prefixing, because it’s not immediately obvious
that you need to do so. As a result, when you’re writing a new
program, you can’t guarantee that the caller has prefixed it nicely
for you.”

Complete
Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.