Исключить с помощью команды find [duplicate]

Мне нужна помощь, чтобы команда find работала прямо в работающем скрипте. Мне нужно иметь возможность исключить некоторые каталоги. Ниже у меня есть то, что я делаю в качестве обходного пути.

sudo find / ( -name firefox -o -name thunderbird -o -name seamonkey \) -type f 2>/dev/null|grep -v '(10_Recommended|repo)'

Я хотел бы исключить некоторые каталоги, чтобы сценарий или команда find не занимали так много времени.

В приведенном выше примере я хочу исключить / export / repo , который является монтированием NFS и / 10_Recommended * , который является началом набора исправлений, используемого на сервере Solaris. Текущий пример, например: / 10_Recommended_CPU_2014-01 .

Я пробовал использовать операторы -prune и ! , но они просто не работают. Может кто-нибудь помочь мне с этим?

Я настраиваю эту команду на Solaris 10, RHEL 5, SLES 11 SP2.

0
задан 13 March 2014 в 20:00
3 ответа

Thanks for everyone's help. Below I have posted the answer to my question, or at least what worked for me. I test the below find command on Solaris 10, RHEL 5 and SLES 11.2 servers.

So below I have displayed the final find commands.

Searching for Java

# find / \( -name 10_Recommended* -o -name share \) -prune -o -type f -name java -print 2>/dev/null

Searching for Mozilla applications

# find / \( -name 10_Recommended* -o -name share \) -prune -o -type f \( -name firefox -0 -name thunderbird -0 -name seamonkey \) -print 2>/dev/null

I hope someone fins this useful.

0
ответ дан 4 December 2019 в 17:48

Try to add:

-not -path "/10_Recommended*" -not -path "/export/repo/*"

But be careful, The path of those repositories depends on where and how you execute the find command.

If you are at / and you do a find -name whatever, you must add a . in the not wanted path.

For you it would be:

find -name whatever -not -path "./10_Recommended*" -not -path "./export/repo/*"

But if you have add a / like you after your find command, you must remove those dots :

find / -name whatever -not -path "/10_Recommended*" -not -path "/export/repo/*"

1
ответ дан 4 December 2019 в 17:48

Try this:

find / \( -path /export -o -path "/*Recommended*" \) -prune -o \
  \( -name iceweasel -o -name thunderbird -type f \) -print 2>/dev/null

The reasoning here is that the -prune is a sort of postfix "action", best combined with -path. List the paths you want ignored first, then the files you're looking for. This seems unnatural in comparison with the prefix nature of other find operations.

In this manner, the paths are seen first to be pruned, and if not, the 'other side' of the -o switch executes. The other way around, it will depth search first and the prune never gets reached, or at least that's my understanding.

Portability is going to be a problem no matter what, especially between Solaris and *nix flavors. Maybe you'd have some luck with the version of find in OpenCSW but no guarantees there. Whip up a small shell script and check for the OS type from uname, a time-honored sysadmin tradition.

Here's an example from my machine, using GNU find:

[fuzzed@ops ~]$ find / -path /usr -prune -o \( -name rsync -o -name bash \) -print 2>/dev/null
[fuzzed@ops ~]$ find / -path /usr/share -prune -o \( -name rsync -o -name bash \) -print 2>/dev/null
/usr/bin/bash
/usr/bin/rsync

My find version:

[fuzzed@ops ~]$ find --version
find (GNU findutils) 4.5.11

Also, some predicates support globbing or regex, so check that out too.

0
ответ дан 4 December 2019 в 17:48

Теги

Похожие вопросы