What Causes the Error?
First, let us see the examples where we encounter this error and then see the cause of its occurrence.
Case 1: When we try to list a large number of files
Let us see the number of files in the temp directory, use the below command:
ls -lrt | wc -l
The number of files is 220001, this is a huge number. Let us try to get all the file names with the word file.
ls -lrt file* | wc -l
The error can be seen in the image.
Case 2: When we try to remove a large number of files
This error can also be seen when we try to remove all the files from this directory.
rm *
The “Argument List Too Long” Error in Linux Commands
There are times when we encounter directories that contain a large number of files, if we try to perform certain operations on those particular directories we may get the error Argument List Too Long. In this article, we will see the cause of this error and how to resolve this error.
We have created a directory(temp) with a large number of files (>200K). All the operations will be performed on that directory. The OS used will be Ubuntu for the demonstration.