0

So I have this bit:

systemctl list-unit-files | grep --ignore-case networkmanager | grep --ignore-case service | cut --fields=1 --delimiter=" "

Which gives as output:

NetworkManager-dispatcher.service
NetworkManager-wait-online.service
NetworkManager.service

And I have this bit:

find / -name NetworkManager-dispatcher.service 2>/dev/null

with the following output:

/usr/lib/systemd/system/NetworkManager-dispatcher.service

However,

find / -name $(systemctl list-unit-files | grep --ignore-case networkmanager | grep --ignore-case service | cut --fields=1 --delimiter=" ") -print 2>/dev/null

gives nothing whereas:

locate $(systemctl list-unit-files | grep --ignore-case networkmanager | grep --ignore-case service | cut --fields=1 --delimiter=" ")

shows:

/etc/systemd/system/multi-user.target.wants/NetworkManager.service
/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service
/usr/lib/systemd/system/NetworkManager-dispatcher.service
/usr/lib/systemd/system/NetworkManager-wait-online.service
/usr/lib/systemd/system/NetworkManager.service
/usr/lib/systemd/system/NetworkManager.service.d
/usr/lib/systemd/system/NetworkManager.service.d/NetworkManager-ovs.conf

Why oh why doesn't find find anything??? ;-)

Before you ask "Why don't you use locate then?", the answer to that is: I'm on Manjaro and locate is not standard whereas find is...

1
  • 2
    You might be interested in exploring systemctl usage: systemctl -t service -p FragmentPath show 'Network*' or systemctl -t service cat 'Network*'
    – guest
    Feb 24, 2020 at 13:20

1 Answer 1

6

Why oh why doesn't find find anything???

Drop 2>/dev/null and see the error. It will be:

find: paths must precede expression: NetworkManager-wait-online.service

-name needs exactly one argument, you're providing three. The first one is accepted. The second one is not recognized as a valid part of an expression, so find assumes it's a path, (like / you provided); but "paths must precede expression".

The invocation is syntactically wrong and it simply fails rather than "doesn't find anything".

On the other hand locate can take more than one pattern easily. This doesn't mean it's flawless. Unquoted $() is often wrong. Here you want the output to be split, still other issues may occur.

1
  • 1
    Urgh! I'm an idiot! I should have thought about dropping the 2> /dev/null myself!!! Dziękuję!
    – Fabby
    Feb 24, 2020 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .