Results 1 to 4 of 4
Hi,
I've got a directory with thousands of files and I want to delete those that contain specific text.
When I try:
Code:
ls | grep -l "specific text" * ...
- 01-28-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 2
"Argument list too long" - help with deleting files based on grep
Hi,
I've got a directory with thousands of files and I want to delete those that contain specific text.
When I try:
I get the error:Code:ls | grep -l "specific text" * | xargs rm
Is there an easy way to get around this without having to move files into seperate folders and processing them in batches? I found an article on getting around this problem, but I'm kind of new to Linux and don't know how to apply this to my specific problem.Code:/bin/grep: Argument list too long
Thanks
- 01-28-2011 #2Just Joined!
- Join Date
- Dec 2010
- Location
- India
- Posts
- 45
i dont think there is need of ls command in the front grep will search all the files in that directory .
try without ls or you can try
this might work . cant check as i dont have system ryt nowfind . -maxdepth 1 -type f | xargs grep -l "specific text" | xargs rm -rf
- 01-28-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 2
Thanks Piyu, that worked perfectly
!
- 01-28-2011 #4Just Joined!
- Join Date
- Dec 2010
- Location
- India
- Posts
- 45
welcome rob but let me know have you tried ur command without ls
it worked or not


Reply With Quote