bash: /bin/rm: Argument list too long

When Anydisk or mount point is full in linux, you need to delete files. You can get ” -bash: /bin/rm: Argument list too long ” error during remove files.

 

 

bash: /bin/rm: Argument list too long

 

You want to delete all audit files which are .aud extension like following.

[root@MehmetSalih audit]# rm -rf *aud 

-bash: /bin/rm: Argument list too long

 

 

Argument list too long

But you got ” -bash: /bin/rm: Argument list too long ” error, to solve this problem you can use following command.

 

[root@MehmetSalih audit]#  find . -name "*aud" -print | xargs rm -rf

 

 

 

You can change *aud extension to the *trc or *trm. You can delete all trc extension files like following if their argument list too long.

[root@MehmetSalih audit]#  find . -name "*trc" -print | xargs rm -rf

 

[root@MehmetSalih audit]#  find . -name "*trm" -print | xargs rm -rf

[root@MehmetSalih audit]#  find . -name "*.log" -print | xargs rm -rf

 

 

 

You can also use Following solutions to solve this problem.

find . -name "*aud" -delete 

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \; 

find . -name "*aud" -print | xargs rm -rf

for file in *; do rm -f $file;done

or (if you want to delete also directories)

for file in *; do rm -rf $file;done

 

 

Do you want to learn Linux System Administration for Beginners, then Click this Link and read the articles.

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

10 comments

  1. You say you are trying to remove “files” but the -r option will also remove the ./not_aud/ directory and all its contents. That might not be what some users want.

    Also note that if you have a file:

    ./somedir/somefile.aud

    And you run:

    % rm -rf *aud

    the file will NOT be removed, but if you run:

    % find . -name “*aud” -print | xargs rm -rf

    the file WILL be removed!

  2. I used to have to run this command — or one like it — fairly frequently for one group that I worked with who would contact me when they noticed these files and the dreaded “Argument list too long” error was being returned. The questions that nobody in the group seemed to be able to answer were: 1.) Why are all these “.aud” files being created if nobody’s using them for anything and 2.) Is there a way to prevent them from being created in the first place, again, if they’re not being used. Nobody ever had an answer to those questions. I’d clean them out for the people who complained all the files and they’d never be thought again until the next time someone noticed that there were 60K-100K of them littering the filesystem (and slowing down the nightly backups when that directory was encountered).

  3. Or simply:

    find . -name “FILE-TO-FIND” -exec rm -rf {} \;

    OR

    find . -type f -name “FILE-TO-FIND” -exec rm -f {} \;

  4. even simpler:
    find . -name “*aud” -delete

  5. Other Method:

    for file in *; do rm -f $file;done

    or (if you want to delete also directories):

    for file in *; do rm -rf $file;done

  6. You can avoid find recursive search and do delete batch using xargs:

    echo *aud | xargs -n 10 rm -rf

    echo does not have the too much arguments because it’s a builtin command.

  7. When that happens, I’ve resorted to a while loop to read the output of `find’ or `ls’ a la:

    ls -1 | while read FN
    do
    rm -f “${FN}”
    done

    Not a one-liner or pretty but if you have to deal with spaces in filenames…

Leave a Reply

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