I'm trying to execute

ls -d "$PWD"/* > formmlFileList43k.list

But I get the following error:

bash: /bin/ls: Argument list too long

I've read using a pipe won't have such limitation, how can I use pipe which will accomplish the same as:

ls -d "$PWD"/* > formmlFileList43k.list

Any help would be appreciated


You have too many items in the directory. That causes the shell to expand * into a command line argument that exceeds ARG_MAX bytes:

$ grep ARG_MAX /usr/include/linux/limits.h
#define ARG_MAX       131072    /* # bytes of args + environ for exec() */

I suggest you to use find as a workaround:

$ find "${PWD}" -mindepth 1 -maxdepth 1 > formmlFileList43k.list

EDIT: @hagello wrote an important note about filenames beginning with a dot. These files should be excluded from the find output. So, the correct workaround is:

$ find "${PWD}" -mindepth 1 -maxdepth 1 '!' -name '.*' > formmlFileList43k.list
  • 1
    You should be aware that find prints the dot files while "ls" by default does not. – hagello Mar 16 '16 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.