Skip to content

[Solved][Linux] Argument list too long ...

When we are processing a large number of files in Linux, such as copy, move, delete... if the number of files is really too large and we use wildcard character * to match files, then we are likely see the following error:

Argument list too long

As shown in the error message, this is caused by too many parameters of the command we ordered (after all, it is a lot of files).

A simple and intuitive way is to use us to process these files recursively, or we can directly use the xargs command to solve it-this is also one of the most recommended methods.

xargs is an instruction that accepts parameters but executes the "rear command". The easiest way is to use find or ls to display the files, and then use xargs to execute the commands one by one. Several common situations are provided below:

1. We want to delete all .log files in folder A

find A/ -name "*.log" | xargs -i rm {}


2. We want to move all the .log files under folder A to folder B

find A/ -name "*.log" | xargs -i mv {} B/


3. We want to copy all the .log files under folder A to folder B

find A/ -name "*.log" | xargs -i cp {} B/

In this way, we can successfully avoid the Argument list too long problem.


References


Read More

Tags:

Leave a Reply