<p>Is there a maximum number of inodes in a single directory? </p>

<p>I have a directory of over 2 million files and can't get the <code>ls</code> command to work against that directory. So now I'm wondering if I've exceeded a limit on inodes in Linux. Is there a limit before a 2^64 numerical limit?</p>

[{'answer_id': 40385, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>Can you get a real count of the number of files?  Does it fall very near a 2^n boundry?  Could you simply be running out of RAM to hold all the file names?</p>\n\n<p>I know that in windows at least file system performance would drop dramatically as the number of files in the folder went up, but I thought that linux didn't suffer from this issue, at least if you were using a command prompt.  God help you if you try to get something like nautilus to open a folder with that many files.</p>\n\n<p>I'm also wondering where these files come from.  Are you able to calculate file names programmatically?  If that's the case, you might be able to write a small program to sort them into a number of sub-folders.  Often listing the name of a specific file will grant you access where trying to look up the name will fail.  For example, I have a folder in windows with about 85,000 files where this works.  </p>\n\n<p>If this technique is successful, you might try finding a way to make this sort permanent, even if it's just running this small program as a cron job.  It'll work especially well if you can sort the files by date somewhere.</p>\n"}, {'answer_id': 40389, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 4, 'selected': False, 'text': "<p>No. Inode limits are per-filesystem, and decided at filesystem creation time. You could be hitting another limit, or maybe 'ls' just doesn't perform that well.</p>\n\n<p>Try this:</p>\n\n<pre><code>tune2fs -l /dev/DEVICE | grep -i inode\n</code></pre>\n\n<p>It should tell you all sorts of inode related info.</p>\n"}, {'answer_id': 40392, 'author': 'Joseph Bui', 'author_id': 3275, 'author_profile': 'https://Stackoverflow.com/users/3275', 'pm_score': 0, 'selected': False, 'text': "<p>Unless you are getting an error message, ls is working but very slowly. You can try looking at just the first ten files like this:</p>\n\n<p><code>ls -f | head -10</code></p>\n\n<p>If you're going to need to look at the file details for a while, you can put them in a file first. You probably want to send the output to a different directory than the one you are listing at the moment!</p>\n\n<p><code>ls &gt; ~/lots-of-files.txt</code></p>\n\n<p>If you want to do something to the files, you can use xargs. If you decide to write a script of some kind to do the work, make sure that your script will process the list of files as a stream rather than all at once. Here's an example of moving all the files.</p>\n\n<p><code>ls | xargs -I thefilename mv thefilename ~/some/other/directory</code></p>\n\n<p>You could combine that with head to move a smaller number of the files.</p>\n\n<p><code>ls | head -10000 | xargs -I x mv x /first/ten/thousand/files/go/here</code></p>\n\n<p>You can probably combine <code>ls | head</code> into a shell script to that will split up the files into a bunch of directories with a manageable number of files in each.</p>\n"}, {'answer_id': 40441, 'author': 'tonylo', 'author_id': 4071, 'author_profile': 'https://Stackoverflow.com/users/4071', 'pm_score': 6, 'selected': False, 'text': '<p><code>df -i</code> should tell you the number of inodes used and free on the file system.</p>\n'}, {'answer_id': 76514, 'author': 'Robᵩ', 'author_id': 8747, 'author_profile': 'https://Stackoverflow.com/users/8747', 'pm_score': 4, 'selected': False, 'text': '<p>Try <code>ls -U</code> or <code>ls -f</code>.</p>\n\n<p><code>ls</code>, by default, sorts the files alphabetically. If you have 2 million files, that sort can take a long time. If <code>ls -U</code> (or perhaps <code>ls -f</code>), then the file names will be printed immediately.</p>\n'}, {'answer_id': 78653, 'author': 'Charles Duffy', 'author_id': 14122, 'author_profile': 'https://Stackoverflow.com/users/14122', 'pm_score': 2, 'selected': False, 'text': '<p>Maximum directory size is filesystem-dependent, and thus the exact limit varies. However, having very large directories is a bad practice.</p>\n\n<p>You should consider making your directories smaller by sorting files into subdirectories. One common scheme is to use the first two characters for a first-level subdirectory, as follows:</p>\n\n<pre>\n${topdir}/aa/aardvark\n${topdir}/ai/airplane\n</pre>\n\n<p>This works particularly well if using UUID, GUIDs or content hash values for naming.</p>\n'}, {'answer_id': 269512, 'author': 'mpez0', 'author_id': 27898, 'author_profile': 'https://Stackoverflow.com/users/27898', 'pm_score': 1, 'selected': False, 'text': "<p>As noted by Rob Adams, ls is sorting the files before displaying them.  Note that if you are using NFS, the NFS server will be sorting the directory before sending it, and 2 million entries may well take longer than the NFS timeout.  That makes the directory unlistable via NFS, even with the -f flag.</p>\n\n<p>This may be true for other network file systems as well.</p>\n\n<p>While there's no enforced limit to the number of entries in a directory, it's good practice to have some limit to the entries you anticipate.</p>\n"}, {'answer_id': 2566626, 'author': 'mario', 'author_id': 307662, 'author_profile': 'https://Stackoverflow.com/users/307662', 'pm_score': 0, 'selected': False, 'text': '<p>For NetBackup, the binaries that analyze the directories in clients perform some type of listing that timeouts by the enormous quantity of files in every folder (about one million per folder, SAP work directory).</p>\n\n<p>My solution was (as Charles Duffy write in this thread), reorganize the folders in subfolders with less archives.</p>\n'}, {'answer_id': 3555084, 'author': 'markus', 'author_id': 429334, 'author_profile': 'https://Stackoverflow.com/users/429334', 'pm_score': -1, 'selected': False, 'text': '<p>Another option is <a href="http://www.gnu.org/software/findutils/" rel="nofollow noreferrer"><code>find</code></a>:</p>\n\n<p><code>find . -name * -exec somcommands {} \\;</code></p>\n\n<p><code>{}</code> is the absolute filepath.</p>\n\n<p>The advantage/disadvantage  is that the files are processed one after each other.</p>\n\n<p><code>find . -name * &gt; ls.txt</code></p>\n\n<p>would print all filenames in <code>ls.txt</code> </p>\n\n<p><code>find . -name * -exec ls -l {} \\; &gt; ls.txt</code></p>\n\n<p>would print all information form ls for each file in <code>ls.txt</code></p>\n'}, {'answer_id': 7673281, 'author': 'DragonTux', 'author_id': 362457, 'author_profile': 'https://Stackoverflow.com/users/362457', 'pm_score': 2, 'selected': False, 'text': '<p>What you hit is an internal limit of ls. Here is an article which explains it quite well:\n<a href="http://www.olark.com/spw/2011/08/you-can-list-a-directory-with-8-million-files-but-not-with-ls/" rel="nofollow">http://www.olark.com/spw/2011/08/you-can-list-a-directory-with-8-million-files-but-not-with-ls/</a></p>\n'}]
['https://Stackoverflow.com/questions/40368', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1536194/']