LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2012, 09:28 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
find mtime exec still gets too many arguments


I thought the trick when you couldn't do a straight up rm on a large number of files was to do a
find /path/* -mtime +7 -exec rm -rf {} \;
but is there a trick for when even that kicks back a too many warning? or do i just need to use it multiple times with a more specific wildcard?
 
Old 02-17-2012, 09:37 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Hm, really? How many files are you trying to delete? What is the specific text of the error message? I've not encountered such a problem before, but would be curious to see.

Anyway, you could of course split up the problem size.

If there's not another more direct solution with find.
 
Old 02-17-2012, 09:40 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
think it's like over 480,000 or so? and i'm getting the too many arguments error.
 
Old 02-17-2012, 09:49 AM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Ah, maybe this, that glob is probably the issue:

Code:
find /path/* -mtime +7 -exec rm -rf {} \
Try this:

Code:
find /path -mtime +7 | xargs rm
Again, please report your full error, with [ code ] tags.
 
1 members found this post helpful.
Old 02-17-2012, 09:54 AM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
so no wildcard in that new one you want me to try? won't be able to try it till next week now unfortunately.
 
Old 02-17-2012, 09:56 AM   #6
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Right, I think the wildcard is the problem, not the find command itself.
 
Old 02-20-2012, 10:16 AM   #7
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
That worked! Thanks. But can you explain again why this worked?
 
Old 02-20-2012, 10:32 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Unless quoted or escaped, globbing patterns such as "*" are expanded by the shell before the command is executed. So when you ran the above command, the shell was really trying to run this:

Code:
find /path/file1 /path/file2 /path/file3 /path/file4 (...etc) -mtime +7 -exec rm -rf {} \;
find only needs to be given the top-level director(y/ies) to start searching from, so it's not generally necessary to use globbing patterns there.

But note also that find has it's own built-in globbing ability, for use in options like -name. This is separate from the shell's globbing feature, and so these patterns must be quoted so that the shell passes them to the command as-is. e.g.:

Code:
find /path -type f -name "*.txt" -print
Edit: Speaking of which, you'd probably want to add at least a -type f to your command, to keep it from deleting directories as well. You have to be careful not to match more than you intend it to, especially when deleting things.

Last edited by David the H.; 02-20-2012 at 10:43 AM. Reason: fixxet tppyo + small addition
 
1 members found this post helpful.
Old 02-20-2012, 10:36 AM   #9
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Ah, so that's why find was choking, it expands it right there. and now i know what a glob is too. thanks.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find command using -exec -fprintf -prune -mtime crimso Linux - General 15 05-17-2011 12:02 PM
[SOLVED] Command to find only mtime ddenton Linux - General 3 08-12-2010 02:57 PM
using find to compare file mtime with another file's mtime TheFueley Linux - Newbie 1 12-23-2008 08:06 PM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 10:32 AM
mtime in find vs ls lslade Linux - Software 0 11-17-2005 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration