LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 10-02-2015, 10:11 AM   #1
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Rep: Reputation: 4
find with -print or -exec does not print found file


I created a normal user in linux, then created a emptyfile in /tmp directory. delted user
and using find command, locate it. then I found this.

Code:
root@garlicbread:[/]# find tmp -nouser -o -nogroup
tmp/ownedbytest
root@garlicbread:[/]# find tmp -nouser -o -nogroup -print
root@garlicbread:[/]# find tmp -nouser -o -nogroup -exec ls -l '{}' \;
root@garlicbread:[/]#
as you can see if I use -print or -exec option, find does not locate the target file

Code:
root@garlicbread:[/]# find tmp -nouser -o -nogroup | xargs ls -l
-rw------- 1 1001 users 0 10월  2 10:44 tmp/ownedbytest
I can use xargs to list as long option, but I noticed that if find does not find any file it execute with empty arguments thus listing current directory.

Code:
root@garlicbread:[/]# find tmp -nogroup | xargs ls -l
total 97
drwxr-xr-x   2 root root  4096 Sep 28 06:54 bin
drwxr-xr-x   4 root root  1024 Sep 28 06:28 boot
drwxr-xr-x  17 root root  5940 Oct  1 07:51 dev
drwxr-xr-x 101 root root 12288 Oct  2 10:45 etc
drwxr-xr-x   5 root root  4096 Oct  2 10:45 home
drwxr-xr-x   7 root root  4096 Aug 20 03:02 lib
drwxr-xr-x   2 root root 12288 Sep 28 08:22 lib64
...
Does anyone know why find does not execute as expected?

I'm using slackware64 14.1
 
Old 10-02-2015, 10:31 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Code:
find tmp -nouser -o -nogroup -print
From man page:

Code:
       expr1 expr2
              Two expressions in a row are taken to be joined with an implied "and"; expr2 is not
              evaluated if expr1 is false.
The file has a valid group. -nogroup is FALSE so -print is never evaluated. Try grouping your conditions.
Code:
find tmp \( -nouser -o -nogroup \) -print
 
Old 10-02-2015, 10:38 AM   #3
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
I see. the problem was that -nogroup and -print is joined with -and

Thank you for your answer. I appreciate it
 
  


Reply

Tags
find command



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/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
[SOLVED] find /common -name lost+found -prune -or -name fileTofind -print kaz2100 Linux - General 2 11-05-2012 04:36 AM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 10:32 AM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
Setting up a print to file print driver Bill Fox Linux - General 0 02-26-2005 01:22 PM

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

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