Home » Technology » Understanding and Solving the Argument List Too Long Error in Linux

Understanding and Solving the Argument List Too Long Error in Linux

Image Source…

The origin of the story…

Image Source…

First, let’s check how many files are in the target directory, but the result is…

# Check the size of the file
ll *.txt|wc -l

# Tragedy happened…
-bash: /usr/bin/ls: Argument list too long

So how about we try to move the file?

# Move the file to the upper directory
mv *.txt ../

# Do not move
-bash: /usr/bin/mv: Argument list too long

I tried “cp, rm”… and other commands and got the same result. Why is this happening? Let’s track down why!

reason

The main reason is that the parameter passed to the system command is too long, and the Linux system itself has a limit to avoid too long, so it is a policy of guard inspection.

Interested friends can refer to “argmax“, here is a detailed description.

Solution

There are mainly two solutions:

find /path/to/files -type f -name “*.txt” | xargs rm
find /path/to/files -type f -name “*.txt” -exec rm \;

epilogue

Although the Linux system has a relatively high threshold, users are also very willing to share the situations they encounter and how to deal with them, so basically there is no need to be afraid of this system, and the processing performance is relatively good, especially when we develop cloud service applications. Linux skills are very much needed, so you might as well study hard to keep up with the trend of the times.

If you like to write articles, you may wish to find out:

An exclusive win-win platform for creators and readers in the era of Web3.0—why join?

Welcome to join us to practice writing and earn knowledge

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.