Fanly

Fanly

一个摸爬打滚于 IT 互联网的追梦人!

How to solve the "Argument list too long" prompt when deleting files in CentOS

When deleting files in CentOS, you may encounter the error "-bash: /usr/bin/rm: Argument list too long". This is because there is a limit on the number of arguments that can be passed to the rm command in Linux command line. To solve this problem, you can use the find command to locate and delete the files. Here is the command you can use:

find . -name "tmp_*" -type f -exec rm -f {} +

This command will search for all files starting with "tmp_" in the current directory and its subdirectories, and delete them using the rm command. The option -type f specifies that only files (not directories) should be matched. The option -exec rm -f {} + passes the found files as arguments to the rm command, avoiding the issue of having too many arguments.

Please note that the deletion operation is irreversible, so make sure you really want to delete these files. Before executing any deletion operation, it is recommended to confirm that the find command correctly lists the files you want to delete. You can use the following command to view the list:

find . -name "tmp_*" -type f

This will only display the file list without performing any deletion operation. If the list is correct, you can then execute the deletion command mentioned above.

Unless otherwise stated, all articles on this blog are original and prohibited from being reproduced in any form.

Article link: https://zhangzifan.com/argument-list-too-long.html

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.