Over time, the storage used on Linux systems you manage will grow. As a result, you will, at some point, try to delete, move, search, or otherwise manipulate thousands of files using commands such as
cp, and so on, which are all subject to this limitation. As such, you will eventually come across the “Argument list too long” error detailed below.
Here’s the error:
bash: /usr/bin/rm: Argument list too long
What does “argument list too long” indicate?
“Argument list too long” indicates when a user feeds too many arguments into a single command, which hits the
An argument also called a command-line argument, can be defined as the input given to a command to help control that command-line process. Arguments are entered into the terminal or console after typing the command.
Multiple arguments can be used together; they will be processed in the order they typed, left to right.
This limit for the length of a command is imposed by the operating system.
You can check the limit for maximum arguments on your Linux system using this command:
Which will return something like this:
hydn@centos:~$ getconf ARG_MAX 2097152
The “argument list too long” error means you’ve exceeded the maximum command-line length allowed for arguments in a command.
Solution for bash: /usr/bin/rm: Argument list too long
Remove the folder itself, then recreate it:
If you are trying to delete ALL files and folders in a directory, then instead of using a wild card “*” for removal (i.e.
rm *), you can try the following:
rm -r /path/to/directory/
If you still need that directory, then recreate it with the
Mass delete files using the
You can use the find command to find every file and then delete them:
find . -type f -delete
Or to delete only specific file types (i.e., .txt files) or otherwise, use something like:
find . -name '.txt' -type f -delete
Knowing how to address the “Argument list too long” error is a valuable skill. These solutions ensure that you can efficiently manage and manipulate your files, regardless of their quantity, without running into this limitation. So, the next time you encounter this error, you’ll be well-prepared to tackle it and continue your Linux system administration tasks seamlessly.
Published: October 1st, 2020 | Last updated: October 1st, 2023