How long can be files names and folder names in Ubuntu Linux and what characters are allowed in file name and folder name in Ubuntu Linux?


File names in Linux were 14 bytes long in earlier Unix version. But The modern Linux system has 255 bytes for file names.

As a character requires 1 byte, The length becomes 255 characters. Also the folders are treated as files in Linux system

See this link for more information

  • 2
    File names are utf-8, so variable length: one byte for any ascii character. 2 or more for any other character e.g. £, ★, ≠, ☺, ¡, ¿, á, …, etc – ctrl-alt-delor Jul 11 '16 at 8:23
  • 1
    If filename is in UTF encoding , the amount of characters decreases with higher number of UTF encoding. See serverfault.com/a/542452/363611 and the comment below that answer – Sergiy Kolodyazhnyy Aug 2 '16 at 1:13

I'm not sure what the maximum file name length can be (for ext4), but it's more dependent on the file system, than Linux itself. On FAT32, I think it is 255 characters. You probably don't ever actually need a file name that long.

As for characters allowed, any byte value is allowed on the ext4 file system, except for the NULL byte (and /, as that is the directory separator1). However, you should limit your file names to the UTF-8 character set, for the widest range of compatibility across applications, and devices.

1. As stated in the glibc manual, "any character except the null character is permitted in a file name string," but a / in the file name string separates the name of one file or folder from that of its parent.

  • I'ld say limit to a-z,A-Z,and numbers. Adding non-alpha-numerics is begging to find url parsing bugs – RobotHumans Jul 22 '12 at 16:40
  • @aking1012 I wish to use '.' and '@' is it not advisable. – Gaurav Agarwal Jul 22 '12 at 16:53
  • '.' is of course fine. I haven't seen @ go wooly, but I guess it could in some corner case. Things parsers use as delimiters and don't escape properly is more what I was referring to - examples: space, /, ", ', etc – RobotHumans Jul 22 '12 at 16:57
  • 1
    The period . is widely used in the system itself, so it is not a problem. The @ should also be fine, I see email servers (e.g. exim) with one directory per account that contain @ and have no problem whatsoever. – Marios Zindilis Jul 22 '12 at 16:58
  • 1
    using a @ is fine. 2 remarks: IF you use something special you can always escape the char. Also do realize that sometimes a char is used as a divider: for instance ssh uses it to seperate user and system: example this: user@system:/dir/dir@dir/ might be iffy and not understood). – Rinzwind Jul 22 '12 at 17:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.