Bash: /usr/bin/rm: Argument list too long - Solution

Originally published at: bash: /usr/bin/rm: Argument list too long - Solution

Over time, the storage used on Linux systems you manage will grow. As a result, you will, at some point, try to delete, move, search, or otherwise manipulate thousands of files using commands such as rm, ls, mv, cp, and so on, which are all subject to this limitation. As such, you will eventually come across…

1 Like

Another solution: Get the list of targets and redirect the output to a text file.

$ ls *.tmp > script.sh

Edit the file to do a chunk of commands per iteration:
rm -f file1 file2 file3 … file50
rm -f file51 file52 file53… file100
rm -f file101 …

Then chmod +x and run the script. This effectively removes the limitation altogether.

1 Like

thanks for sharing this. :handshake: