LoginSignup
0
2

More than 3 years have passed since last update.

ディレクトリのファイル数上限

Last updated at Posted at 2021-04-22

ディレクトリのファイル数の上限

そもそも記憶ディスク事体のinode数を超えたファイル数を作成することはでない.ディスの容量を超えてファイルを保存することもできない.

ディスクのinode数,容量を調べる.

$ df -i -h
$ df  -h

inode数を食っているディレクトリを調べる.

$ find . -type f | wc -l
$ echo "### `pwd` ###"; for i in `ls -1`; do echo -n "--- $i --- "; echo "(`find ./$i -type f |wc -l`)"; done | sort -r

1つのディレクトリに保存できるファイル数にも上限がある.運用上は100万以上では保存しない方がよさそう.
できれば1万以下にした方がよい?

大量の連番ファイルを子ディレクトに分類する

pythonを用いて大量の連番ファイルを分類する例を以下に示す.

分類してファイルを生成する

mk.py
import shutil
import os
import math
for num in range(1,100):
    dirname  = "./data/"+str(math.floor(num/10)).zfill(5)
    os.makedirs(dirname, exist_ok=True)
    filename = "dirname" + "/" + "file_" + str(num).zfill(10) + ".txt"
    with open(filename, 'w') as f:
        f.write("txt")

既に存在したファイルを分類する

mv.py
import shutil
import os
import math
for num in range(1,100):
    dirname  = "./data/"+str(math.floor(num/10)).zfill(5)
    os.makedirs(dirname, exist_ok=True)
    filename = "./data/" + "file_" + str(num).zfill(10) + ".txt"
    #with open(filename, 'w') as f:
    #    f.write("txt")
    shutil.move(filename, dirname)

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2