development

Bash의 파일 이름 길이 제한

big-blog 2020. 11. 7. 10:48
반응형

Bash의 파일 이름 길이 제한


다음 질문은 bash 및 linux에만 해당됩니다.

  1. 파일의 절대 경로 이름의 문자 수에 제한이 있습니까?
  2. 파일 이름 (확장자 없음)의 문자 수에만 제한이 있습니까?

그렇다면 이러한 제한은 무엇일까요? 시스템에 특정한 경우 어떻게 액세스 할 수 있습니까?


파일 시스템에 크게 의존합니다. ext FS의 경우 (현재 Linux에서 가장 많이 사용됨) :

  • 최대 파일 이름 길이 : 255 바이트
  • 최대 경로 길이 : 없음

확장자는 FS가 인식하는 것이 아니라 255 바이트이며 확장자가 포함되어 있습니다 (확장자없이 파일 이름을 가질 수 있음).

다음 은 FS별로 이러한 제한에 대한보다 자세한 목록입니다.

또한 최대 길이를 변경할 수있는 파일 시스템 확장이있을 수 있습니다. 예를 들어, 하위 파일 이름의 일부를 사용하여 메타 데이터를 유지하고 파일 이름을 최대 143 자로 제한하는 eCryptFS가 있습니다. Ubuntu eCryptFS 런치 패드 항목을 참조하십시오 .


임시 디렉토리에서 다음을 실행하십시오.

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

그리고 나는 얻는다 :

touch: cannot touch `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': File name too long
256

내 한도가 255임을 의미합니다.


Mac OS X 10.6.7의 경우 :

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

다른 답변을 참고하여 찬성 해주세요.

Linux에서 파일 이름 및 경로 이름 길이는 다음에 따라 다릅니다.

에서 이러한 속성을 동적으로 가져 오려면 다음을 수행하십시오 .

  • dogbane에서 설명한대로 파일 이름 (또는 경로 이름)을 더 길고 길게 만듭니다.
  • Linux에서도 사용할 수있는 timgetconf제안한 명령 사용하십시오 .

    $ getconf NAME_MAX /mnt/sda2/
    255
    $ getconf PATH_MAX /mnt/sda3/
    4096
    

단일 UNIX 사양 pathconf 로 읽을 수있는 limits.h 에서 언급 NAME_MAXPATH_MAX상수를 언급합니다 . 그러나 이것은 매우 파일 시스템에 따라 다르며 이러한 제한에 도달 할 가능성은 거의 없습니다.

참고 : 프로그래머는 이러한 제한을 하드 코딩해서는 안됩니다. 동적 할당을 사용해야 기본 시스템에서 수행하는 작업을 허용하는 한 항상 작동합니다.


  1. 파일의 절대 경로 이름의 문자 수에 제한이 있습니까?

네, 있습니다.

See answer by sfp at the question Filename length limits on linux? on serverfault

In short:

#define PATH_MAX        4096    /* # chars in a path name including nul */

And for:

  1. Is there a limit on the number of characters for the filename (without extension) only?

in the same linked answer:

#define NAME_MAX         255    /* # chars in a file name */

It depends on the filesystem used. For example, ext4 has maximum filename length of 256 bytes and unlimited pathname length.

See Comparison of file systems for more.


This is not bash-dependent; it's OS dependent. On a mac, its 0xff for a filename and 0x400 or so for a path name. Ubuntu 9 had a limit of 144 characters for file names.

I have found this link in Wikipedia. It tells path and filename limits for numerous file systems.


참고로 Docker에서 파일 이름 제한은 현재 242 자 입니다.

참고 URL : https://stackoverflow.com/questions/6571435/limit-on-file-name-length-in-bash

반응형