bash: /usr/bin/rm: Argument list too long – Solution
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
mv, 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.
bash: /usr/bin/rm: Argument list too long
All regular system commands, such as
cp, and so on are subject to this limitation.
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
ARG_MAX limit. The
ARG_MAX defines the maximum length of arguments to the exec function.
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.
There are several solutions to this problem (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