查找程序对应的配置文件

Published: Tags: SHELL

之前在《杭州Linux用户组》上看到有人问如何知道一个程序的配置文件在什么地方,链接点「这里」,其实这是一个很普遍的,一般折腾系统的同学都会遇到的情况,就像Windows下可以对注册表进行拍照然后看看被修改了什么地方一样。

在Linux下可能有其他方法,但我不知道,只知道最好的方法是阅读源码(THE FUCKING CODE),但这会吓倒很多人,也包括我,因为我就是想知道程序改了什么地方而已。。。

或者你也可以Google之,不过下面给出一个相对简单的Shell脚本,有句话叫『能用就是好的』,所以下面的脚本写得很弱智,不过对于我来说确实好用,同时这也是一个思路,源码分享如下:

#!/bin/bash
#project gmeld.sh by icyomik
#depends: meld or diff, cksum or md5sum and so on, zenity

#sumalg:"cksum" "md5sum" "sha1sum" "sha224sum" "sha256sum" "sha384sum" "sha512sum"
sumalg=md5sum
#compare:"diff" "meld"
compare=meld

dirselect=`zenity --file-selection --directory --title="Choose a DIR to sum (Gmeld)"`
sumtmp1=`mktemp`
sumtmp2=`mktemp`

if [ -n "$dirselect" ];then
    cd $dirselect
    echo -e "\n\t$dirselect\n" >$sumtmp1
    find . -not -type d -size -32M -exec $sumalg {} \; |awk '{print $2" --- "$1}' |sort >>$sumtmp1
    echo "tmp file $sumtmp1 is ok."

    zenity --question --text="Do you want to use previous dir to compare ?\n( Choose \"yes\" or \"no\" when you finished jobs ! )"
    [ $? -eq "1" ] && dirselect=`zenity --file-selection --directory --title="Choose a DIR to sum (Gmeld)"`

    cd $dirselect
    echo -e "\n\t$dirselect\n" >$sumtmp2
    find . -not -type d -size -32M -exec $sumalg {} \; |awk '{print $2" --- "$1}' |sort >>$sumtmp2
    echo "tmp file $sumtmp2 is ok, too !"

    echo "using \"$compare\" program to compare..."
    $compare $sumtmp1 $sumtmp2
else
    echo "you haven't chosen the path to snap !"
fi

echo "removing $sumtmp1 and $sumtmp2"
rm -f $sumtmp1 $sumtmp2