linux: rm command gives Argument list too long error

In Linux, all the files are stored into directory or folder and sometimes these directory fills with a huge amount of files and we want to delete everything with “rm-rf” command.

However, if there are too many files in the folder for this command to handle, we will get an error like this:

/bin/rm: Argument list too long

To get around this, there are a couple of commands we can use:

$ ls | xargs rm

$find . -name ‘*deltasyslog*’ -print0 | xargs -0 rm

The 2nd command will delete all the files containing ‘deltasyslog’ keywords.

If we don’t want to delete everything, except all php files the use “*.php” will delete all php files.

$ find . -name *.php’ -print0 | xargs -0 rm

###With Path

Search in different directory path and delete file after match

$find /root -type f -name ‘text.php*’ -print0 | xargs -0 rm

Please follow and like us:
0

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.