1

I need to search all files whose name contain string 'bind' through a mounted usb key (the search should exclude a directory called 'prog/'

Here is the mounted volume:

lsblk /dev/sda 
sda      8:0    1 58.6G  0 disk 
└─sda1   8:1    1 58.6G  0 part /run/media/achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1

Here is the search root directory in the usb key:

ls /run/media/achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/
linux/
new_order/
prog/

it looks like the find command does not work the same way depending on where you are in the path:

pwd
/run/media

find ./achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/ \
-path ./achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/prog -prune \
-o -type f -iname *bind* -print 2>/dev/null

./achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/new_order/bash/scripts/kubernetes-vagrant-centos-cluster-master/addon/rook/rook-agent-clusterrolebinding.yaml

-> it works but,

cd ..;pwd
/run

I recall the same working command (see above), and add 'media' between './' and 'achille':

find ./media/achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/ \
-path ./media/achille/1af1ba16-5f9a-44af-a481-9e8c63d278e1/it0/prog -prune \
-o -type f -iname *bind* -print 2>/dev/null

-> it outputs nothing !! why?? I just recall the same command one directory further.If I specify the full path it outputs nothing either.

many thanx folks!

6
  • Try adding -L to follow symbolic links. Commented Jun 1, 2020 at 13:00
  • @ Jack: pb remains; not sure to understand why this switch '-L'; the founded file in the first attempt is not hard/soft linked but thanx indeed. Commented Jun 1, 2020 at 13:26
  • make sure $folder is type d because find does not work on symlinks find $folder -type f -not -ipath '*/prog/*' -iname '*bind*' Commented Jun 1, 2020 at 13:51
  • I finally found the issue: *bind* wont work, '*bind*' will. Why would it work in the first attempt then ? I dont know. I have been tricked by the fact that usually * works without quoting. Commented Jun 1, 2020 at 17:25
  • @ alecxs: thank you indeed. Commented Jun 1, 2020 at 17:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.