Limit on file name length in bash [closed] Limit on file name length in bash [closed] bash bash

Limit on file name length in bash [closed]


It depends very much on the filesystem. For the ext FS (currently the most used on Linux):

  • max filename length: 255 bytes
  • max path length: none

The extension is not something the FS is aware of, it 255 bytes, extension included (you can have file names without any extensions).

Here is a more exhaustive list of these limits, per FS.

There can also be extensions to your file system that can change your maximum length as well. For example, eCryptFS which uses part of the lower file name to keep metadata and limits the file name to a maximum length of 143 characters. See Ubuntu eCryptFS launchpad entry.


In a temp directory, run:

num=1while [ true ]do    if ! touch $(printf "%${num}s"  | tr ' ' 'a')   then       echo $num       break   fi   ((num++))done

and I get:

touch: cannot touch `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': File name too long256

which means my limit is 255.


On Mac OS X 10.6.7:

man getconfgetconf NAME_MAX /   # 255 bytesgetconf PATH_MAX /   # 1024 bytes# check file path length with wc before using touch, mkdir, etc.echo '/very/lllooooonnnnnggggg/file/path.txt' | wc -c