Why my find return not expected?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Why my find return not expected?
# 1  
Old 11-29-2013
Why my find return not expected?

Code:
root@intel_5500_server:~# find / -name bin -o -name sbin                          
/usr/bin
/usr/lib64/pm-utils/bin
/usr/lib64/rpm/bin
/usr/sbin
/bin
/sbin


root@intel_5500_server:~# which ovs-pki 
/usr/bin/ovs-pki

why below command return nothing 

root@intel_5500_server:~# find / -name bin -o -name sbin -exec ls {} \; |grep ovs-pki

# 2  
Old 11-29-2013
You asked it to find something called "bin" or "sbin", not something containing "bin" or "shin". If the latter was the case it would return everything with "bin" or "sbin" in it, not just "ovs-pki".
# 3  
Old 11-29-2013
You would be better putting the file you wanted in the find command, something like:-
Code:
find / -name "*ovs-pki*"



I hope that this helps. It will find any file that matches the pattern with anything either side. The directory structure is not part of the pattern though, so if you want bin or sbin as part of the path, you may need to:-
Code:
find / -name "*ovs-pki*" | egrep "\/s*bin\/"

The egrep expression "\/s*bin\/" will (I hope) match the string of / followed by zero or more s then bin and finally another /. Of course this will match /sssssssssbin/ too if you have one, but it's close.

Perhaps someone can tweak my expression to say "zero or one letter s"



I hope that this helps,
Robin
# 4  
Old 11-29-2013
Quote:
Originally Posted by Scott
You asked it to find something called "bin" or "sbin", not something containing "bin" or "shin". If the latter was the case it would return everything with "bin" or "sbin" in it, not just "ovs-pki".
ovs-pki is located in /usr/bin/, {} contains /usr/bin/, why ls {} doesn't ouput it ?

---------- Post updated at 10:29 AM ---------- Previous update was at 10:27 AM ----------

Quote:
Originally Posted by rbatte1
You would be better putting the file you wanted in the find command, something like:-
Code:
find / -name "*ovs-pki*"



I hope that this helps. It will find any file that matches the pattern with anything either side. The directory structure is not part of the pattern though, so if you want bin or sbin as part of the path, you may need to:-
Code:
find / -name "*ovs-pki*" | egrep "\/s*bin\/"

The egrep expression "\/s*bin\/" will (I hope) match the string of / followed by zero or more s then bin and finally another /. Of course this will match /sssssssssbin/ too if you have one, but it's close.

Perhaps someone can tweak my expression to say "zero or one letter s"



I hope that this helps,
Robin
my case actually want to output all the cmds in bin/ or sbin/, the really question is why it doesn't output ovs-pki, though it's located in /usr/bin
# 5  
Old 11-29-2013
As I said, {} contains "bin", but it isn't called "bin". If "ovs-pki" was a directory and its contents included a file or directory called "bin", then it "ovs-pki" would show up in the search. That's because it's looking for things you asked it to. It would only report "ovs-pki" if it contained something called "bin" ("bin" being the thing you asked it to find).
# 6  
Old 11-29-2013
Quote:
Originally Posted by Scott
As I said, {} contains "bin", but it isn't called "bin". If "ovs-pki" was a directory and its contents included a file or directory called "bin", then it "ovs-pki" would show up in the search. That's because when it finds what you asked it to it stops. It doesn't find "bin" and then think to itself "Hmmm. I'll just keep going for a minute" Smilie

no,no,no can you run below command, it actually output the cmds, which in bin or sbin

Code:
root@intel_5500_server:~# find / -name bin -o -name sbin -exec ls {} \;
agetty	       blkid.util-linux     dnsmasq	      fixfiles	       hdparm.hdparm	   ip		       klogd		   mii-tool.net-tools	  mkswap.util-linux  pivot_root.util-linux  rmmod	       shutdown		   syslogd	     xfs_repair
arp	       blockdev		    dumpe2fs	      fsck.ext2        hwclock		   ip.iproute2	       klogd.sysklogd	   mingetty		  modinfo	     plipconfig		    rmmod.26	       shutdown.sysvinit   syslogd.sysklogd  xfsdump
arp.net-tools  blockdev.util-linux  e2freefrag	      fsck.ext3        hwclock.util-linux  ipmaddr	       ldconfig		   mke2fs		  modinfo.26	     plipconfig.net-tools   route	       slattach		   tc		     xfsrestore
audisp-remote  bootlogd		    e2fsck	      fsck.ext4        ifcfg		   ipmaddr.net-tools   load_policy	   mkfs.ext2		  modprobe	     poweroff		    route.net-tools    slattach.net-tools  telinit
audispd        bridge		    e2image	      fsck.ext4dev     ifconfig		   iptunnel	       logsave		   mkfs.ext3		  modprobe.26	     poweroff.sysvinit	    routef	       start-stop-daemon   udevadm
auditctl       cfdisk		    e2undo	      fsck.xfs	       ifconfig.net-tools  iptunnel.net-tools  losetup		   mkfs.ext4		  mount.fuse	     rarp		    routel	       sulogin		   udevd
auditd	       ctrlaltdel	    e4defrag	      fstab-decode     ifdown		   iwconfig	       losetup.util-linux  mkfs.ext4dev		  mount.glusterfs    rarp.net-tools	    rtmon	       swapoff		   umount.nfs
aureport       debugfs		    ebtables	      getty	       ifup		   iwgetid	       lsmod		   mkfs.minix		  mount.nfs	     readprofile	    rtpr	       swapoff.util-linux  umount.nfs4
ausearch       depmod		    ebtables-restore  getty.tinylogin  init		   iwlist	       mcstransd	   mkfs.minix.util-linux  mount.nfs4	     reboot		    runlevel	       swapon		   vigr
autrace        depmod.26	    fdisk	      halt	       init.sysvinit	   iwpriv	       mdadm		   mkfs.xfs		  nameif	     reboot.sysvinit	    runlevel.sysvinit  swapon.util-linux   vigr.shadow
badblocks      dhclient		    fdisk.util-linux  halt.sysvinit    insmod		   iwspy

# 7  
Old 11-29-2013
Yes, because you used the "ls" option, something peculiarly missing from your original post.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Manipulate files with find and fuser not working as expected on SunOs

Greetings, For housekeeping, I use the following command: find /some/path -type f -name "*log*" ! -exec fuser -s "{}" 2>/dev/null \; -exec ls -lh {} \; It finds all log files not currently in use by a process and manipulates them. This command always works on linux and redhat machines,... (2 Replies)
Discussion started by: dampio
2 Replies

2. Shell Programming and Scripting

Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected

Main_script.sh #! /bin/sh ./Sub_script.sh rc=$? echo "Return code from Sub_script.sh : $rc" if ; then echo "$rc = 991" echo "" exit 1 elif ; then echo "$rc = 992" echo "" exit 1 elif ; then echo "$rc = 0" echo "" exit 1 fi (2 Replies)
Discussion started by: duddukuri
2 Replies

3. Shell Programming and Scripting

basename not working as expected from find -exec

I have the following files in a directory > ls -1 /tmp/test/dir/ file with spaces 1.ogg file with spaces 2.oggI am running the following to echo the filenames but alter the file extension on the files to .mp3 instead of .ogg ( I am going to run ffmpeg against the files ultimately, but keeping... (2 Replies)
Discussion started by: jelloir
2 Replies

4. Shell Programming and Scripting

return value not coming as expected

Hi, We are using a shell script which is called from COBOL program. Here the program works fine till we are using MicroFocus(MF) COBOL 4 and UNIX AIX 5.3. Recently we have upgraded to MicroFocus(MF) COBOL 5.1 but same AIX version. now the shell script not working as expected. The shell... (5 Replies)
Discussion started by: vensk27
5 Replies

5. UNIX for Dummies Questions & Answers

Why do these 2 find commands return different results?

Hi, I am using the korn shell on Solaris box. Why does the following 2 commands return different results? This command returns no results (I already used this command to create a list of files which I moved to an archive directory) find ????10??_*.dat -type f -mtime +91 However this... (15 Replies)
Discussion started by: stumpy1
15 Replies

6. Shell Programming and Scripting

Find: return code check

Hi, I've a find command like, find /abcd/efgh -name "xxxx" 2> /dev/null > file1 what would be the condition to check if this returns none(means if the file "xxxx" is not present) ???? I tried checking with $? and it returns 72 to me but even the file is present also it returns... (6 Replies)
Discussion started by: skcvasanth
6 Replies

7. Shell Programming and Scripting

Find command return type

Hi all does find command return anything if the file to be searched is not found? Like if I search from a file in a dir does it return false or null if the file is not found? Please suggests. (3 Replies)
Discussion started by: Veenak15
3 Replies

8. Shell Programming and Scripting

Find cmd not working as expected

Hi, i wan to search the file starting with Admin into the directory Output. I am running below command: find /appl/Output -name "Admin*" -prune but this command is going into the sub directories present under output. I do not want to search under sub directories. Any help will be highly... (6 Replies)
Discussion started by: Vishal123
6 Replies

9. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies
Login or Register to Ask a Question