LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-25-2012, 08:16 AM   #1
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Rep: Reputation: 31
why did find delete everything?


So I was trying to delete all the files I have with this in the filename: AdboeJPEG

So first I did a find without delete to make sure I was going to get teh right stuff.

find . -name *ADOBEJPEG*

And I got a long list of all the files. So it looked like it only got the files I needed. Perfect. So I ran

find . -delete -name *ADOBEJPEG*

and it deleted everything in that directory whether or not it matched the search. What did I do wrong?
 
Old 07-25-2012, 08:53 AM   #2
tizzef
Member
 
Registered: Jan 2005
Location: Nice, France
Distribution: Ubuntu,RHES, Mandriva, RHAS, AIX 4.3.3, 5.2 & 5.3, Debian,Solaris8/10
Posts: 119

Rep: Reputation: 20
Hi there,

In the man page of find you will find the following sentence :
"The -delete action also implies -depth."
I think it was the problem that you had encounter...

Cheers.
 
Old 07-25-2012, 09:15 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
The order of the options are important (as mentioned in the man page):
Quote:
Warnings: Don't forget that the find command line is evaluated
as an expression, so putting -delete first will make find try to
delete everything below the starting points you specified.
This would probably have done what you expected (although errors might be shown):
Code:
find . -name *ADOBEJPEG* -delete
I personally try to zoom in as much as possible (add -type f if you are after files or -type d for directories) and use the -exec rm {} \; option instead of -delete.

This is what i would have used instead:
Code:
find . -type f -name "*ADOBEJPEG*" -exec rm {} \;
Test it without the blue part.
 
3 members found this post helpful.
Old 07-25-2012, 09:23 AM   #4
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Original Poster
Rep: Reputation: 31
ah, I had a feeling order of operations had something to do with it.

Thand druuna. I'll have to give that a shot today. (Luckily I keep backups so I am able to restore all the lost data)
 
Old 07-25-2012, 09:26 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Also, you need to _always_ put arguments with wild cards inside of quotes. Otherwise it expands before find runs.
 
Old 07-25-2012, 09:29 AM   #6
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by jschiwal View Post
Also, you need to _always_ put arguments with wild cards inside of quotes. Otherwise it expands before find runs.
Can you elaborate on what that means?
 
Old 07-25-2012, 11:15 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,582
Blog Entries: 2

Rep: Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037Reputation: 4037
Quote:
Originally Posted by DJOtaku View Post
Can you elaborate on what that means?
If you don't put the name with the *-wildcards into quotes they will be expanded by the shell first instead of being used directly by find. If you use for example the option -name abc*.txt and you have a file abcd.text in your current directory the shell will expand the wildcards to that name, so that find runs with the option -name abcd.txt. This doesn't happen if you quote the wildcards, like -name "abc*.txt".
 
Old 07-25-2012, 11:42 AM   #8
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Original Poster
Rep: Reputation: 31
Hmm....that didn't appear to be the case last night. It appeared to catch all files that had AdobeJPEG in the filename.
 
  


Reply

Tags
commandline, find


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find with -prune and -delete sseeg Linux - General 8 01-10-2013 04:06 AM
find folders in a folder and delete ibbofez Linux - Newbie 3 10-26-2011 04:20 PM
Package to find and delete duplicates maury0324 Linux - Software 8 08-03-2010 05:47 AM
find and delete old files RAFAL Linux - General 4 03-30-2010 03:59 AM
find -delete folders Meson Linux - General 7 04-16-2008 01:30 PM


All times are GMT -5. The time now is 09:54 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration