LinuxQuestions.org
Help answer threads with 0 replies.
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, 10:28 AM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Rep: Reputation: 48
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, 10:37 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
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, 10:40 AM   #3
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

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

Rep: Reputation: 210Reputation: 210Reputation: 210
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, 10:54 AM   #5
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Original Poster
Rep: Reputation: 48
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, 10:56 AM   #6
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Right, I think the wildcard is the problem, not the find command itself.
 
Old 02-20-2012, 11:16 AM   #7
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Original Poster
Rep: Reputation: 48
That worked! Thanks. But can you explain again why this worked?
 
Old 02-20-2012, 11:32 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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 11:43 AM. Reason: fixxet tppyo + small addition
 
1 members found this post helpful.
Old 02-20-2012, 11:36 AM   #9
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:02 PM
[SOLVED] Command to find only mtime ddenton Linux - General 3 08-12-2010 03:57 PM
using find to compare file mtime with another file's mtime TheFueley Linux - Newbie 1 12-23-2008 09:06 PM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 11:32 AM
mtime in find vs ls lslade Linux - Software 0 11-17-2005 02:06 PM

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

All times are GMT -5. The time now is 08:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration