Skip to content

delete file: Argument list too long in Linux


Argument list too long in Linux

use find

find . -name filename | xargs rm -f

too many files may also cause the argument list too long problem in find. Could use ls and grep instead.

ls |grep YOUR_FILE_PATTERN |xargs rm -f

use xargs

ls | xargs -n 50 rm -rf

xargs could control the batch size of an output. In this case, 50 elements in a batch/group, and pass to rm to process progressively.

Back to Table of Contents

  1. License under CC BY-NC 4.0
  2. Copyright issue feedback, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No personal information is collected.