Score:0

Find to exclude the snapthost directory in SLES 15

us flag

I am searching for the executable file name pxe using the command

find / -type f -executable -print | grep pxe$

and this works fine in RHEL, but in SLES the snapshot directory messses up the search. How to exclude the snapshot directory in my search.

I have tried these combination but did work.

localhost:~ # find / -type f -executable -print | grep pxe$
find: File system loop detected; ‘/.snapshots/1/snapshot’ is part of the same file system loop as ‘/’.
/root/pxe
/root/xyx/pxe
/pxe
localhost:~ # find / -type f -executable -print -not -path "*/.snapshots/*" | grep pxe$
find: File system loop detected; ‘/.snapshots/1/snapshot’ is part of the same file system loop as ‘/’.
/root/pxe
/root/xyx/pxe
/pxe
localhost:~ #
localhost:~ #
localhost:~ # find / -type f -executable -print -not -path "/.snapshots/*" | grep pxe$
find: File system loop detected; ‘/.snapshots/1/snapshot’ is part of the same file system loop as ‘/’.
/root/pxe
/root/xyx/pxe
/pxe

I do not want the /.snapshots/ to show up when find is run. Any suggestion?

snapshot dir is under /

test:~ # cd /
test:/ # ls -la
total 52588
drwxr-xr-x    1 root root      224 Apr  6 16:28 .
drwxr-xr-x    1 root root      224 Apr  6 16:28 ..
-rw-r--r--    1 root root        0 Mar 30 15:03 .acce
drwxr-x---    1 root root       38 Mar 20 12:25 .snapshots
-rwxrwxrwx    1 root root 26559432 Oct 14 12:23 pxe
Score:0
gu flag

As with all things Linux, man should be your first stop, it's usually just a matter of finding the term that matches what you're looking for. man find and /skip yields:

-prune

True; if the file is a directory, do not descend into it. If -depth is given, then -prune has no effect. Because -delete implies -depth, you cannot usefully use -prune and -delete together. For example, to skip the directory src/emacs and all files and directories under it, and print the names of the other files found, do something like this:

find . -path ./src/emacs -prune -o -print

redpy avatar
us flag
thanks! Had a followup: find bar -path /foo/bar/myfile -print Find compares the -path argument with the concatenation of a directory name and the base name of the file it's examining. Since the concatenation will never end with a slash, -path arguments ending in a slash will match nothing (except perhaps a start point specified on the command line). compares -> /foo/bar/myfile with Concatenation of -> /foo/bar/myfile/ + myfile = /foo/bar/myfile/myflile "since... ends .. slash" -> When I try to concatenate as above I do not see an ending slash?
Ginnungagap avatar
gu flag
Are you wondering why the underlying logic of the `-path` filter isn't shown in the resulting output? Or am I misunderstanding? If not I'd suggest asking a new question with good examples of what you're running, what you're getting, what you're expecting and why.
redpy avatar
us flag
edited my question to original state. Hope someone find the answer to a question similar to mine. Thanks for (find . -path /.snapshots -prune -o -print) This totally works and solves my issue. Will have a different post for my other question on (man find) makes it easier. Thanks again. MY Question is answered!!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.