How to know a specific launchd.plist file location?

后端 未结 7 1013
天涯浪人
天涯浪人 2021-01-31 10:25

Is it possible to know the .plist file location which is loaded into the launchctl command?

The label name is listed with \"launchctl list\" and its contents can be view

7条回答
  •  萌比男神i
    2021-01-31 10:36

    Here is the command to list all loaded .plist files and their corresponding files:

    find /System/Library/Launch* /Library/Launch* ~/Library/Launch* -name '*.plist' -exec sh -c '/usr/libexec/PlistBuddy -c "Print Label" {} && echo {}' ';' | grep -wf <(launchctl list | grep -o "\S\+\..*$") -A1 | strings

    or another version:

    find /System/Library/Launch* /Library/Launch* ~/Library/Launch* -name '*.plist' -exec /usr/libexec/PlistBuddy -c "Print Label" {} ';' -print | grep -wf <(launchctl list | grep -o "\S\+\..*$") -A1 | strings

    Explanation:

    • find all .plist files in the following locations: /System/Library/Launch* /Library/Launch* ~/Library/Launch*
    • Use PlistBuddy command to print Label of all found .plist files.
    • Use -print parameter of find to print the path to that file.
    • Fetch another list of all the jobs loaded into launchd and use as pattern file for grep -f.
    • Filter both lists and find the common elements and print its label along with its path (-A1).
    • Filter via strings to avoid printing binary files.

提交回复
热议问题