Ubuntu does not limit the size of a directory, it's imposed by the file system. Each file and directory is an so-called inode. You can use
df -i to check the number of inodes in use and available for all mounted filesystems.
I've just created 1 million and one files without issues because my inode limit for my ext4 home partition of 50 GB (46 GiB) is large enough.
I used shell expansion for creating the files, combined with the
This creates 1000001 files which can be verified with
ls | wc -l. Why
300000..600000 and not
300001..600000? Because I was too lazy to put that 1 at the end.
df -i looks like:
/dev/sda6 3055616 1133635 1921981 38% /home
Now remove the test files (
cd ..&&rm -f test took much longer, so use
rm with the filenames):
and the number of inodes in use decreased immediately after removal of the files:
/dev/sda6 3055616 133634 2921982 5% /home
Note that even if the filesystem allows such large numbers of files, it's a horrible idea to store such large files in a single directory. At least use some subdirectories with a structure like
f/i/l/e/filename.ext. Programs do often not expect such large quantities of files.