2

bash: /usr/bin/rm: Argument list too long

 1 year ago
source link: https://haydenjames.io/bash-usr-bin-rm-argument-list-too-long-solution/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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 rm, cp, ls, 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.

Datadog

The Error

bash: /usr/bin/rm: Argument list too long
bash: /usr/bin/rm: Argument list too long

All regular system commands, such as rm, ls, mv, 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:

getconf ARG_MAX

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.

The Solution

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 mkdir command.

Datadog

Mass delete files using the find command:

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK