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-15-2024, 10:57 AM   #1
kancla
LQ Newbie
 
Registered: Apr 2024
Posts: 3

Rep: Reputation: 0
find: unknown predicate `- filesdpx/2024-01-28/dtx_2024-04-10_reference.txt


I want to find all files in a directory called 'project' inside this directory there is a lot of different directory with the criteria */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan'. After finding the files with the mentioned criteria, I want those files to be moved to the 'files.txt' file. However, while running this script: find */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*' > files.txt
I am getting the error 'unknown predicate for find command,' which indicates that certain files have a hyphen at the beginning and a space between the hyphen and the filename. How can I fix that? I ran this line in a bash script.
 
Old 04-15-2024, 02:24 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,523

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
I'd try running the command with quotes/double quotes around the entire path.
 
Old 04-15-2024, 05:16 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Is there a hyphen followed by a space in the command itself? That’s what the error you describe seems to indicate.

Use code tags to show us exactly what you ran, please. Also what, exactly, the message you got said.
 
Old 04-16-2024, 05:21 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
you can add an echo:
Code:
echo find */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*'
to see what will be really executed. And probably you can catch that invalid predicate.
 
Old 04-16-2024, 01:33 PM   #5
kancla
LQ Newbie
 
Registered: Apr 2024
Posts: 3

Original Poster
Rep: Reputation: 0
hey @yancek i added the quotation but nothing changed , still have the same error .
 
Old 04-16-2024, 01:37 PM   #6
kancla
LQ Newbie
 
Registered: Apr 2024
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by scasey View Post
Is there a hyphen followed by a space in the command itself? That’s what the error you describe seems to indicate.

Use code tags to show us exactly what you ran, please. Also what, exactly, the message you got said.


no there is no any hyphen in the command , i was looking for files older than 180 days with the name convention 20 into specific directory , but there is an error with one directory that has a hyphen at the beginning and space in between the hyphen and the directory name , the find command is not able to go into that directory and look for files complaining about the - i am not sure how to make the find command deal with hyphen or special character to find for the files into that directory .
 
Old 04-16-2024, 10:49 PM   #7
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 46

Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
you can add an echo:
Code:
echo find */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*'
to see what will be really executed. And probably you can catch that invalid predicate.
We need the output of above command(echo find... 2>&1 | more ) for us to reproduce the same at our environment.
 
Old 04-17-2024, 12:22 AM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by kancla View Post
no there is no any hyphen in the command , i was looking for files older than 180 days with the name convention 20 into specific directory , but there is an error with one directory that has a hyphen at the beginning and space in between the hyphen and the directory name , the find command is not able to go into that directory and look for files complaining about the - i am not sure how to make the find command deal with hyphen or special character to find for the files into that directory .
Actually, there are several hyphens in the command
Code:
find */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*' > files.txt
If any have an accidental space between the hyphen and its parameter, that would cause the error you describe, which appears to be a complaint about the construct of the command itself. As you’ve noted, the command is not working, so it can’t be complaining about the files it might have found.

So, again. Please copy/paste the command that’s erroring into code tags (see the link in my sig), and include the error you’re getting. Don’t tell us what’s happening, show us. Please.
 
Old 04-17-2024, 09:26 AM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by kancla View Post
... However, while running this script: find */*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*' > files.txt
I am getting the error 'unknown predicate for find command,' which indicates that certain files have a hyphen at the beginning and a space between the hyphen and the filename. How can I fix that? I ran this line in a bash script.
The problem is similar to what happens with many commands when you have file or directory names that look like options. Usually, one solution is precede the name with "./" so that the string does not look like an option.

Try:
Code:
find ./*/*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path 'Archive/*' -not -path 'orphan/*' > files.txt
     ^^
 
1 members found this post helpful.
Old 04-17-2024, 12:24 PM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
and the -path names must adapt:
Code:
find ./*/*/*20* -maxdepth 1 -type f -mmin +$((730 * 1440)) -not -path './Archive/*' -not -path './orphan/*' > files.txt
Certainly -prune is more efficient:
Code:
find ./*/*/*20* -maxdepth 1 \( -path './Archive' -type d -or -path './orphan' -type d \) -prune -or -type f -mmin +$((730 * 1440)) > files.txt
Global option -maxdepth 1 should be valid for both -or branches.
Both -or branches have a default -print action.
An explicit -print only prints that branch:
Code:
find ./*/*/*20* -maxdepth 1 \( -path './Archive' -type d -or -path './orphan' -type d \) -prune -or -type f -mmin +$((730 * 1440)) -print > files.txt
Finally a complex variant, cannot overflow with "too many arguments":
Code:
find . -maxdepth 1 \( -path './Archive' -type d -or -path './orphan' -type d \) -prune -or -path './*/*/*20*' -type f -mmin +$((730 * 1440)) -print > files.txt

Last edited by MadeInGermany; 04-17-2024 at 12:42 PM.
 
  


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: unknown predicate" with folder names smartdba Linux - Newbie 2 10-11-2019 10:00 AM
cut first 10 lines of file master.txt and paste in ab1.txt and so on yogeshkumkar Programming 4 08-31-2011 07:23 AM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

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

All times are GMT -5. The time now is 04:50 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
Open Source Consulting | Domain Registration