LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-23-2017, 12:54 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,622

Rep: Reputation: 128Reputation: 128
Need help with find syntax


I have the following:
Code:
$ find /directory/ -type f \( -path /directory/NortonNSBUDownloader.exe -o -path /directory/pensionFiles.zip \) -prune -mtime +7 -exec ls -l \{\} \;

# I've also tried

$ find /directory -type f -mtime +7 \( -name NortonNSBUDownloader.exe -o -name pensionFiles.zip \) -prune -exec ls -l \{\} \;
The file NortonNSBUDownloader.exe is older than 7 days, but I want to exclude it from the list. Another file in this folder "joe" is also more than 7 days old. With the commands I'm trying the NortonNSBUDownloader.exe is being listed and the joe file is not, exactly the opposite of what I want.

What am I doing wrong?
 
Old 05-23-2017, 01:17 PM   #2
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 6,078

Rep: Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741
I'm by no means a find expert, in fact, I usually need to refer to the man page. However, in the first example, I don't think you should be specifying a path with a filename. Paths should be folders.

Otherwise, I think you just need an exclamation point in front of the expression you're not wanting to find. So, instead of -name NortonSBUDownloader.exe, it would be ! -name NortonSBUDownloader.exe

So, without being on a computer to test it (plus without the needed files to even test it), I think it can even be simplified a bit. Hopefully the following will work.

Code:
find /directory -type f -mtime +7 ! -name NortonNSBUDownloader.exe ! -name pensionFiles.zip -prune -exec ls -l \{\} \;
 
1 members found this post helpful.
Old 05-23-2017, 01:17 PM   #3
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 1,505

Rep: Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121
The "!" operator excludes things. So if you want to exclude NortonNSBUDownloader.exe and pensionFiles.zip, you should do this:

Code:
$ find /directory -type f -mtime +7 \( \! -name NortonNSBUDownloader.exe -a \! -name pensionFiles.zip \) -prune -exec ls -l \{\} \;
Also, in this case I don't think you need the parentheses; i.e., the command could be:

Code:
$ find /directory -type f -mtime +7 \! -name NortonNSBUDownloader.exe \! -name pensionFiles.zip -prune -exec ls -l \{\} \;
EDIT: beaten to the punch.
 
1 members found this post helpful.
Old 05-23-2017, 01:25 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,019
Blog Entries: 3

Rep: Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918
The options for find are connected by default with a logical AND unless something else is explicitly specified. Where an operator is missing, -a is assumed. So you're missing a logical OR in the right place.

Code:
find /directory -type f -mtime +7 \( -name NortonNSBUDownloader.exe -o -name pensionFiles.zip \) -prune -o -type f -mtime +7 -exec ls -l \{\} \;
Remember the precedence of logical operators.

Edit: oops. even slower here
 
1 members found this post helpful.
Old 05-23-2017, 02:44 PM   #5
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Don't use -prune like that, it doesn't do what you think it does (it excludes the contents of a directory). Use ! -name. Also, the backslashes in \{\} are not needed, they are not idiomatic and make an ugly convention even uglier.
 
2 members found this post helpful.
  


Reply

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Understanding find Syntax linux4evr5581 Linux - Newbie 9 12-28-2016 11:11 PM
Need syntax help on find command rhbegin Linux - General 2 05-04-2010 02:33 PM
find -exec syntax: bug in find? mfcarroll Programming 5 06-21-2007 07:13 PM
need help with find syntax stefaandk Linux - General 4 07-12-2006 05:48 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:07 PM.

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