nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

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

This is a discussion on -bash: /bin/rm: Argument list too long within the Shell scripting forums, part of the Development/Scripting category; Okay I have a folder on my Red Hat server that I want to clean up 2 times a week ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-02-2009, 09:07 PM
Member
User
 
Join Date: Feb 2009
OS: Debian / Red Hat
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cjredding is on a distinguished road
Default -bash: /bin/rm: Argument list too long

Okay I have a folder on my Red Hat server that I want to clean up 2 times a week I know how to add it to the crontab, but I am having an issue removing all these files because when I try to do a rm -rf * I get:
[root@server1 PDF for Output]# rm -rf *
-bash: /bin/rm: Argument list too long
So I was thinking maybe I need to make a script to clean it out, but i don't know how to get around the Argument list too long problem.

Any help with this issue would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 23-02-2009, 10:31 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Use find command along with xargs to get rid of the files
Code:
find /path/to/dir/delete -print0 -iname '*.txt' | xargs -0 /bin/rm -f
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 23-02-2009, 11:11 PM
Member
User
 
Join Date: Feb 2009
OS: Debian / Red Hat
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cjredding is on a distinguished road
Default

This unfortunately also removed the folder that all the files where located in.
Reply With Quote
  #4 (permalink)  
Old 23-02-2009, 11:30 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

No rm command should not delete any folder. To select only files add -type f to find command:
Code:
 find /path/to/dir/delete -type f -print0 -iname '*.txt' | xargs -0 /bin/rm -f
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
find , finding file , rm command , xargs


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Bash script Murray Shell scripting 0 23-02-2009 08:38 AM
arg list too long - tar command ali560045 Shell scripting 1 19-12-2008 03:56 PM
Argument list too long raj Shell scripting 1 04-11-2008 10:04 AM
Bash not working! Mwalimugini Getting started tutorials 4 24-03-2008 09:52 PM
How long the sys was running? jithendra Linux software 2 16-10-2006 05:31 PM


All times are GMT +5.5. The time now is 10:38 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38