Linux/UNIX: Argument list too long error for rm, cp, mv commands in a shell error

Linux/UNIX: Argument list too long error for rm, cp, mv commands in a shell error

The "argument list too long" error can occur when you try to use the rm, cp, or mv commands with a large number of files or directories. This error is typically caused by a limitation in the maximum length of the command line, which is usually determined by the system's shell.

To fix this error, you can use one of the following approaches:

  1. Use the find command to process the files and directories in smaller batches. For example, to delete a large number of files, you can use the following command:
find . -type f -delete
Sourc‮al.www:e‬utturi.com

This will find all files in the current directory and its subdirectories and delete them.

  1. Use the xargs command to process the files and directories in smaller batches. For example, to delete a large number of files, you can use the following command:
find . -type f -print0 | xargs -0 rm -f

This will find all files in the current directory and its subdirectories and delete them using the rm command.

  1. Increase the maximum length of the command line by modifying the system's shell configuration. For example, in the Bash shell, you can increase the maximum length of the command line by modifying the ARG_MAX value in the /etc/bashrc file.

By using one of these approaches, you should be able to fix the "argument list too long" error when using the rm, cp, or mv commands in a shell. It's always a good idea to carefully review the documentation and use the appropriate commands to manage files and directories on your system. This will help ensure that your system is properly configured and that you can perform the desired tasks efficiently.

Created Time:2017-10-30 10:17:48  Author:lautturi