LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-13-2018, 10:37 AM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 112

Rep: Reputation: Disabled
find: paths must precede expression: iname


I'm attempting to search a folder for files named sample.avi, sample.mp4 & sample.mkv that are under 40Meg in size and delete them.

I have trued the bit of code below but it results in an "find: paths must precede expression: iname" error.

Code:
find /home/Videos/ -type f \( -iname \sample.avi -o iname \sample.mp4 -o iname \sample.mkv\) -size -40M -delete
Where am I going wrong?

Cheers
 
Old 03-13-2018, 11:30 AM   #2
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 112

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Entropy1024 View Post
I'm attempting to search a folder for files named sample.avi, sample.mp4 & sample.mkv that are under 40Meg in size and delete them.

I have trued the bit of code below but it results in an "find: paths must precede expression: iname" error.

Code:
find /home/Videos/ -type f \( -iname \sample.avi -o iname \sample.mp4 -o iname \sample.mkv\) -size -40M -delete
Where am I going wrong?

Cheers
Sorry I just figured it out. Was missing a - before the inames
 
Old 03-13-2018, 11:31 AM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 578

Rep: Reputation: 266Reputation: 266Reputation: 266
Quote:
Originally Posted by Entropy1024 View Post
I'm attempting to search a folder for files named sample.avi, sample.mp4 & sample.mkv that are under 40Meg in size and delete them.

I have trued the bit of code below but it results in an "find: paths must precede expression: iname" error.

Code:
find /home/Videos/ -type f \( -iname \sample.avi -o iname \sample.mp4 -o iname \sample.mkv\) -size -40M -delete
Where am I going wrong?

Cheers
I've bolded and then bracketed the changes I made.
The second one is invalid (because of the brackets)
Essentially, when using -o, it means or. So you still need to include the - before iname (-o -iname, not -o iname)
Also, \sample.avi doesn't mean much. It's typically used with \*sample.avi to wildcard match everything before sample.avi. If you're not using something the shell will expand, the \ is not needed

Once you've validated that it is working, then put the -delete back in. Never use -delete until you're positive you're going to get the results you want (which is not true until you get your command working)

Code:
find /home/Videos/ -type f \( -iname \*sample.avi -o -iname \*sample.mp4 -o -iname \*sample.mkv \) -size -40M
Code:
find /home/Videos/ -type f \( -iname \[*]sample.avi -o [-]iname \[*]sample.mp4 -o [-]iname \[*]sample.mkv[ ]\) -size -40M

Last edited by Sefyir; 03-13-2018 at 11:32 AM.
 
Old 03-13-2018, 01:35 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro
Posts: 6,397

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
I don't even use the escapes,

Code:
find /path -type f -iname "*dh.jpg" -o -iname "*.jpg"
 
Old 03-13-2018, 05:05 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,931

Rep: Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710
Quote:
Originally Posted by BW-userx View Post
I don't even use the escapes,

Code:
find /path -type f -iname "*dh.jpg" -o -iname "*.jpg"
That has the implied binding
Code:
find /path \( -type f -iname "*dh.jpg" \) -o -iname "*.jpg"
A name matching that final '-iname "*.jpg"' does not have to pass the '-type f' test. It "works" for you since you probably don't have anything but ordinary files with that extension.
 
1 members found this post helpful.
Old 03-13-2018, 05:33 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro
Posts: 6,397

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
well I'm not one to name my directories like files with an extension if that is what you mean.

that what I used was just a quick example,
here off one of my scripts, depending on my needs at the moment.
Code:
done <<<"$(find "$working_dir"   -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
#done <<<"$(find "$working_dir"  "$working_dir2"  -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
#done <<<"$(find "$working_dir" -not \( -path /media/data/deluge-download -prune \) -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"

Last edited by BW-userx; 03-13-2018 at 05:47 PM.
 
Old 03-13-2018, 08:12 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,931

Rep: Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710Reputation: 1710
Quote:
Originally Posted by BW-userx View Post
Code:
done <<<"$(find "$working_dir"   -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
#done <<<"$(find "$working_dir"  "$working_dir2"  -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
#done <<<"$(find "$working_dir" -not \( -path /media/data/deluge-download -prune \) -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
Those all share the same problem. You might as well leave out the "-type f" test since the result is not being used for any of the matches following that first "-o". If you don't believe that, try changing it to "-type s" (socket) and see the result. The "*.mp3" names will be excluded since they are not sockets, but all of the other "or" terms in that expression will still be found.
 
Old 03-13-2018, 08:14 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro
Posts: 6,397

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
Quote:
Originally Posted by rknichols View Post
Those all share the same problem. You might as well leave out the "-type f" test since the result is not being used for any of the matches following that first "-o". If you don't believe that, try changing it to "-type s" (socket) and see the result. The "*.mp3" names will be excluded since they are not sockets, but all of the other "or" terms in that expression will still be found.
yeah you're prob right, its never caused me an issue. probably because I know my files.

but if you need to point fingers. then point fingers at the post I found showing me what I posted. that is where I learned it, by googling how to's.

Last edited by BW-userx; 03-13-2018 at 08:29 PM.
 
  


Reply


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
find: paths must precede expression lead2gold Linux - General 11 02-27-2014 07:06 AM
[SOLVED] Bash Issue with Find Script: find paths must precede expression: *.txt JockVSJock Programming 4 01-06-2014 09:03 PM
find: paths must precede expression: ls HELP! wdtunstall Linux - General 2 07-24-2013 11:22 AM
[GNU find version 4.2.27] find: paths must precede expression mechagojira Linux - Newbie 3 07-06-2011 05:34 AM
Problem with find: paths must precede expression troelskn Programming 11 07-29-2009 02:48 AM

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

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