Find the answer to your Linux question:
Results 1 to 6 of 6
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    3

    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
    Location
    Either at home or at work or down the pub
    Posts
    3,482
    The safest way to validate for folder names is alpha numeric and _ (underscore) and - (dash)
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    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. #4
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    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 (!#$*\&^).

  5. #5
    Just Joined!
    Join Date
    Sep 2009
    Posts
    3
    Okay thank you that's exactly what I was after.

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    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
  •