argument list too long

"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.

  • files
  • shell

danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.

Steps

  1. find . -maxdepth 1 -name '*.log' -delete

    danger delete them without listing them on the command line

  2. find . -maxdepth 1 -name '*.jpg' -exec mv -t /dest/ {} +

    move them, many at a time (GNU mv)

  3. printf '%s\0' *.log | xargs -0 rm

    xargs makes batches that fit

  4. getconf ARG_MAX

    how long a command line can be here

Commands used

  • find
  • xargs
  • getconf

Each has a page in lore: lore find opens it.