Fanly

Fanly

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

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

When deleting files under CentOS system, you may encounter the prompt: -bash: /usr/bin/rm: Argument list too long. This is because in the Linux command line, when too many files are passed to the rm command at once, the error "Argument list too long" will occur. This is because there is a limit on the command line that prevents passing too many arguments.

To solve this problem, I specifically asked ChatGPT, and it suggested using the find command to search for and delete these files, which can avoid passing too many arguments at once.

Here is the command that can be executed:

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 use the rm command to delete them. -type f indicates that only files (excluding directories) will be matched, and -exec rm -f {} + will pass the found files as arguments to the rm command, avoiding the problem of a long argument list.

Please note that the deletion operation is irreversible, so please make sure you really want to delete these files. Before performing any deletion operation, it is best to confirm whether 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 the deletion operation. If the list is displayed correctly, you can then execute the deletion command mentioned earlier.

Unless otherwise stated, all articles are original works of Tearsnow Blog and any form of reproduction is prohibited.

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.