LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-22-2013, 07:25 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Rep: Reputation: 0
Unhappy what does paths must precede expression means?


Code:
find . -type f -mmin +10 -print -not "crapfiles*" |grep SS
gives me an error

Code:
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]
What the heck is that !!!?

Well this stuff does works without any problem,
Code:
find . -type f -mmin +60 -print |grep SS
So Unix Gurus please tell me what is causing me the grief !!!
 
Old 04-22-2013, 07:35 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
"crapfiles*" will be globbed by bash before execution. so the command will look somethign like:

find . -type f -mmin +10 -print -not crapfile1 crapfile2 crapfile3 |grep SS

so those file names get taken to be the path. change " to ' there.
 
Old 04-22-2013, 07:44 AM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@acid_kewpie

sorry mate still it doesn't work. It still gives the same error. I know if I use grep it would certainly work but I do want to use -not clause only. I believe in innovation rather than repetition.
 
Old 04-22-2013, 07:49 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Did you check manual of find (see here)? As per this manual:
Code:
! expr 
True if expr is false. This character will also usually need protection from interpretation by the shell. 

-not expr 
Same as ! expr, but not POSIX compliant.
So either try:
Code:
~$ find . -type f -mmin +10 -print | grep SS
OR
Code:
~$ find . -type f -mmin +10 -not "crapfiles*" | grep SS
 
Old 04-22-2013, 07:56 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@shiva

The code you gave in "Or" is the exactly I am trying and having issues did I missed something ?
 
Old 04-22-2013, 08:06 AM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
"crapfiles*" is not preceded by "-name" as I think you intended. Because of this find is interpreting it as a pathname (to be considered along with ".") and should have come at the beginning of the arguments.
 
1 members found this post helpful.
Old 04-22-2013, 08:16 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I suppose you're getting error like:
Code:
find: path must procede expression:
The option -not is used to inverting the match, so there should come some expression after -not option like -name, -mtime etc. For example try:
Code:
~$ find . -type f -mmin +10 -not -name "crapfiles*" | grep SS
Which means find file/directories whose name doesn't contain "crapfiles".
 
1 members found this post helpful.
Old 04-22-2013, 04:29 PM   #8
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@shivaa

Thanks you ! I understood now. I gather my mistake was not having "-name" after "-not". AM i right?
 
Old 04-22-2013, 04:33 PM   #9
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@shivaa

A quick question if I just want to print name of file without its full name any trick there?

say h1/h2/h3/abcd.txt I just want it to print abcd.txt -print is better but it print the whole path
 
Old 04-22-2013, 08:32 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
AFAIK, 'find' doesn't have a built-in option for that, so pipe the results through basename http://linux.die.net/man/1/basename
 
1 members found this post helpful.
Old 04-22-2013, 09:32 PM   #11
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@chrism01

I could get that by using -printf "%f\n"
 
Old 04-22-2013, 10:04 PM   #12
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by sysmicuser View Post
I could get that by using -printf "%f\n"
As Chris said, basename is the command you need to truncate the file name only from it's absolute path. For example:
Code:
~$ basename /dirA/dirB/file1
file1
For more details, check it's manual page: http://linux.die.net/man/1/basename
 
1 members found this post helpful.
Old 04-22-2013, 10:42 PM   #13
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
Angry

@shivaa basename can only work for a single file? i am having here multiple files but more than anything else if find has an inbuilt function why not to harness that?

Guys,

I am very close but still not that close

I have got all what I want except file's full path

I am doing a "cd" to a particular directory and then running a particular "find" command which is as follows:
Code:
find . -path \*/output/* -type f -not -name "A1*" -not -name "A2*" -not -name "A3*" -mmin +60 -print
Here i am getting the desired output but not getting the base directory where I did "cd" is there any quick and easy way to get that? else I am thinking of a for loop.

Please advise.

Last edited by sysmicuser; 04-22-2013 at 10:43 PM. Reason: Update
 
Old 04-22-2013, 10:54 PM   #14
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by sysmicuser View Post
I have got all what I want except file's full path

I am doing a "cd" to a particular directory and then running a particular "find" command which is as follows:
Code:
find . -path \*/output/* -type f -not -name "A1*" -not -name "A2*" -not -name "A3*" -mmin +60 -print
Here i am getting the desired output but not getting the base directory where I did "cd"


Code:
find  /full/pathname/of/starting/directory  /or/multiple/directories  -path \*/output/* -type f -not -name "A1*" -not -name "A2*" -not -name "A3*" -mmin +60 -print
 
1 members found this post helpful.
Old 04-22-2013, 11:20 PM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
It appears you're right... I did a quick(!) look through the man page, but missed that
In my defence, its a long page.
Mind you, I can't remember the last time I tried to get that anyway
 
  


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
find: paths must precede expression lead2gold Linux - General 11 02-27-2014 07:06 AM
[GNU find version 4.2.27] find: paths must precede expression mechagojira Linux - Newbie 3 07-06-2011 05:34 AM
find: paths must precede expression -- already checked google/man/faqs escalf Programming 5 03-02-2010 10:12 AM
Problem with find: paths must precede expression troelskn Programming 11 07-29-2009 02:48 AM
this regular expression means? bwreath Linux - General 2 03-15-2005 03:14 PM

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

All times are GMT -5. The time now is 03:26 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