Problem
The questions below are only for bash and linux users.
If that’s the case, what may these boundaries be? If they’re system-specific, how can I get to them?
Asked by Sriram
Solution #1
It is highly dependent on the filesystem. For the ext file system (which is now the most used on Linux):
The extension is not something the FS is aware of, it 255 bytes, extension included (you can have file names without any extensions).
According to FS, here is a more comprehensive list of these restrictions.
There may also be extensions to your file system that alter your maximum file length. For example, eCryptFS keeps metadata in part of the lower file name and keeps the file name to a maximum of 143 characters. See the eCryptFS launchpad item in Ubuntu.
Answered by e-satis
Solution #2
Run the following commands in a temporary directory:
num=1
while [ 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 long
256
As a result, my limit is 255.
Answered by dogbane
Solution #3
On Mac OS X 10.6.7, follow these steps:
man getconf
getconf NAME_MAX / # 255 bytes
getconf PATH_MAX / # 1024 bytes
# check file path length with wc before using touch, mkdir, etc.
echo '/very/lllooooonnnnnggggg/file/path.txt' | wc -c
Answered by tim
Solution #4
I refer to other answers, please upvote them.
The lengths of filenames and pathnames in Linux are determined by:
To get these properties dynamically in bash, type:
Answered by oHo
Solution #5
The Single UNIX Specification mentions NAME_MAX and PATH_MAX constants in limits.h that can be read with pathconf. However, this is highly reliant on the filesystem, and you are unlikely to reach such a limit.
NOTE: You should not hard-code these constraints as a coder. You should employ dynamic allocation so that whatever you’re doing will always function as long as the underlying system lets it.
Answered by Michael Aaron Safyan
Post is based on https://stackoverflow.com/questions/6571435/limit-on-file-name-length-in-bash