LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-14-2015, 05:39 PM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint v21.3 & v22.x with Cinnamon
Posts: 1,792
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
using 'find' to list "files" or "folders" named with any of three patterns


I'm trying to use find to make a list of "folders" or "files".
Code:
prompt$ sudo find / -type d -or -type f \
     {options} -print
password: **********

... output from find command ....
prompt$
Since I start my scan in the root folder, I want to avoid "devices", "special" file systems like /proc or /sys, and such. I want to see all folders (directories) or regular files.

PROBLEM: I get more items listed than expected.
Specifically, if I make a list of "-type d" folders as one collection, and then make a list of "-type f" regular files as a second collection, there are fewer total items (using 'wc -l') than using "-type d -or -type f".

Once I'm able to locate all "folders" and "files"
Code:
prompt$ sudo find / {locate folders and files} \
     -iname "pattern1" -or iname "pattern2"    \
     {options} -print
password: **********

... output from find command ....
prompt$
For example, I might want to locate any "tmp" or "temp" folders and any files "*.tmp" or "temp*" regardless of where they are.

PROBLEM: I can't get find to match on any of multiple patterns. The man-page says "expr expr" is ANDed by default.
As I understand find, "-iname "*.tmp" -or -iname "temp*" should (1)ignore case in names (2)report any with a dot-tmp file type, and (2) report any that begin with "temp". I don't get results as I describe.
 
Old 04-14-2015, 06:07 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,190

Rep: Reputation: 867Reputation: 867Reputation: 867Reputation: 867Reputation: 867Reputation: 867Reputation: 867
try using '-o' for or instead of '-or' as '-or' is not posix complient
 
Old 04-15-2015, 09:42 AM   #3
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint v21.3 & v22.x with Cinnamon
Posts: 1,792

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by Keith Hedger View Post
try using '-o' for or instead of '-or' as '-or' is not posix complient
So I have the following:
Code:
prompt$  ls -l
total 128
drwxrwxr-x 2 user group  4096 May 23  2013 dopples
-rw-r--r-- 1 user group     0 Oct 21  2013 hp-doctor.err
-rw-rw-r-- 1 user group 30671 Sep 20  2013 Kids-Lacrosse-Drills.html
lrwxrwxrwx 1 user group    20 Apr 14 13:37 myAuth.log -> /home/some/auth.log
-rw-r--r-- 1 user group 27614 Jun 23  2014 Other-Card.html
-rw-r--r-- 1 user group 52529 Apr  8 16:31 today_USR.log
-rw-r--r-- 1 user group  8676 Apr  8 16:32 today_VAR.log
prompt$
I get the following
Code:
prompt$ find . -type d -o -type f  -iname '*log'
.
./dopples
./dopples/junk.log
./today_USR.log
./today_VAR.log
prompt$
However, I also get the following
Code:
prompt$ find . -type d -o -type f -o -type l  -iname '*log'
.
./myAuth.log
./dopples
./dopples/junk.log
./dopples/rem-duplicates.sh
./hp-doctor.err
./Kids-Lacrosse-Drills.html
./Other-Card.html
./today_USR.log
./today_VAR.log
prompt$
The man-page for find explains (my words) that given "expr1 -o expr2", expr2 is not evaluated if expr1 is true. Also, given "expr1 expr2", expr2 is not evaluated if expr1 is false. I expect that -iname will look at any files that meet any one of the -type tests and report files of any requested type that have the requested name pattern.

I also get the following
Code:
prompt$  find . -type d -o -type f -o -type l  -iname '*log' -print

./myAuth.log
prompt$
Again, the find man-page says that -print is the default action. However, I only get the log file that is a symlink and not the others.

What am I missing? What am I doing wrong?
~~~ 8d;-/ Dan

Last edited by SaintDanBert; 04-15-2015 at 09:47 AM. Reason: clarification
 
Old 04-15-2015, 10:00 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,744

Rep: Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560Reputation: 7560
I would say it is a problem with precedence. Using explicit -print will remove the implied -prints, but I think the implied -print belongs to each condition (one by one), while the written one belongs to the whole.
I mean something like this:
find . -type d -print -o -type f -print -o -type l -iname '*log' -print
Obviously this is a guess only. If you need unambiguous result use \( and \) to group and rule the order of evaluation.
 
1 members found this post helpful.
  


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
[SOLVED] "net rpc" "failed to connect to ipc$ share on" or "unable to find a suitable server" larieu Linux - General 0 11-09-2014 12:45 AM
Want to change how pasted files are named "(copy)," "(another copy)," "(3rd copy)" L a r r y Linux - Desktop 3 08-24-2013 03:39 PM
How to add the "More Apps" and "Find Files" buttons to the 11.10 Launcher Larry James Ubuntu 0 10-19-2011 12:42 AM
"Multicolumn" or "tiles", or even "list" icon view on desktop, in any DE? the dsc Linux - Desktop 3 02-20-2010 09:25 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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