如果我做
augtool --noautoload --transform "sshd incl /etc/ssh/sshd_config" ls "/files/etc/ssh/sshd_config/"
然后我得到了 的树形结构/etc/ssh/sshd_config
,但是这里我已经写了两次文件路径,最后一次以 . 为前缀/files
。
问题
是否可以这样做,但只指定文件路径?
默认情况下,Augeas 会加载它知道的所有文件,这可能会很慢。
为了防止这种情况,您的命令使用--noautoload
which 绕过从镜头自动加载文件。虽然这使 Augeas 更快,但这也意味着它不再知道/etc/ssh/sshd_config
,因此您需要再次手动将此文件映射到Sshd.lns
镜头,这通过--transform Sshd.lns incl /etc/ssh/sshd_config
.
这是加载 Augeas 已知的任何文件并绕过其他镜头的另一种可能性(来自augeas-sandbox ):
#!/bin/sh
FILE=$1
if [ -z "$FILE" ]; then
echo "Usage: $0 <FILE>"
exit 1
fi
augtool -L -i <<EOF
rm /augeas/load/*["$FILE"!~glob(incl) or "$FILE"=~glob(excl)]
load
set /augeas/context /files$FILE
EOF
This script will use autoload statements so you don't have to specify which lens to use, but it will only load the lens you want for your file, making Augeas faster. Additionally, it sets /augeas/context
, so you can use relative paths:
$ augloadone /etc/ssh/sshd_config
rm : /augeas/load/*["/etc/ssh/sshd_config"!~glob(incl) or "/etc/ssh/sshd_config"=~glob(excl)] 1158
augtool> ls .