Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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 .
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
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.
... 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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.