Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Legal Folder Names - Many Misconceptions

    Hi all. I have a web server running on an ubuntu linux system. But as I thought today I just realized I know next to nothing about characters which are legal in naming directories. Searching didn't help in the sense that I don't even know if there is a difference between the restrictions of folder names on the web and folder names on a local machine.

    Basically I am asking:
    -What characters are allowed when naming a directory? Punctuation? Standards Symbols? Chinese? These "pictures": ☺ (side question: what are these types of characters referred to as officially)? ™∞§¶¡•£ªº©´†œ¥? etc
    -Even if they are allowed, should I not use them? And why?
    -Can all of these legal characters be stored in a MySQL database?
    -Are different browsers not able to access the folders with certain characters?
    -What is the max folder name length?
    -Do all of these questions vary for whatever OS you are hosting on?

    The reason I ask such a question is that Id like users to be able to create folders on the site based on a string they type in, but I have no idea which characters to restrict.

    Thanks! I know this is a lot, sorry.

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Either at home or at work or down the pub
    The safest way to validate for folder names is alpha numeric and _ (underscore) and - (dash)
    Should you be sitting wondering,
    Which Batman is the best,
    There's only one true answer my friend,
    It's Adam Bloody West!

    The Fifth Continent

  3. #3
    Hi thanks for the response. Why though? I don't understand.

    Using ! and Chinese characters, for example, would allow many users (in a system where the folder name corresponds with the user name) to create many more names, perhaps even preferred by them.

    So it'd be nice to include them but at the same time I have no idea what are the cons, if any, in doing so.

  4. $spacer_open
  5. #4
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Mountain View, CA
    I think that technically, you are allowed to have all characters in a filename except / and the null character (\0). In practice, however, you don't want to have anything that is A) difficult to type, or B) interpreted by a shell (!#$*\&^).

  6. #5
    Okay thank you that's exactly what I was after.

  7. #6
    Linux Guru
    Join Date
    Nov 2007
    Córdoba (Spain)
    Technically, you can use *anything* that's not / or NULL in a Linux file name, this is coincident with posix as far as I know.

    The problem with file names is always the same: possible is not always the same than desirable. Specially when it comes to weird characters that can't be easily typed or when it comes to multibyte characters (accented characters, chinesse and others).

    However, this is becoming less of an issue as the time advances, most new systems nowadays will support utf8 by default, which means they can display virtually any file name correctly as long as there's a font with the needed characters installed in your system. Non utf8 system will not display these file names correctly.

    A particularly problematic character can be the line feed character. It's a common error from lots of programmers, even experienced ones, to assume that in a list or stream a line feed is a valid separator, and this is not always true. This is why it's important to use nulls as separators or terminators, and not anything else.

    PS. Characters that have a meaning for the shell, like ! () {} can be used as long as they are correctly quoted or escaped.
    Last edited by i92guboj; 09-16-2009 at 06:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts