Question
What is the best way to remove files when you receive the following error?
/bin/rm: Argument list too long
Answer
Some commands, such as rm, can only process so much data. If you have a directory with several hundred thousand files or more, rm will likely be unable to remove this properly. To perform that work, you would need to turn to the "find" command, which can make use of the "delete" flag to search for files and remove them.
Please Note: This should only be performed by a qualified System Administrator. The find command paired with the delete flag does not verify the removal of files before doing so, and using the command improperly can damage your system or otherwise result in data loss.
The below examples are provided as illustrative examples of using the find command and, as presented, they will not remove any data from your server:
- List all files and folders in a user's account with full details:
find /home/$username/ -ls
- List only the files (not folders) in a user's document root folder:
find /home/$username/public_html -type f
- Search for all htaccess files in a user's document root:
find /home/$username/public_html -type f -name ".htaccess"
If you require more detailed assistance in removing large amounts of files using the "find" command, please reach out to your System Administrator to minimize the risk of data loss. If you do not have such an administrator, you may search for one in our listings here:
System Administration Services
Please note, however, that cPanel, LLC does not endorse or recommend any particular provider on that list, nor can we be held liable for any services performed by third-party providers, including those on the list.
Comments
0 comments
Article is closed for comments.