2012-02-09 6 views
1

2つのディレクトリのどのファイルが異なる権限を持っているかを調べるには、Linuxにbashスクリプトを書き込むにはどうすればよいですか?2つのディレクトリのファイルの特権の違いを取得するためのBashスクリプト

1- file1 (-rwxrwxr-x) 
2- file2 (-rw-rw-r--) 

私はへのスクリプトが必要になります異なるアクセス許可と同じ名前のファイルを持つ

1- file1 (-rw-rw-r--) 
2- file2 (-rw-rw-r--) 

fold2

fold1は、2つのファイルを持つ:

例えば

、私は2つのディレクトリを持っています異なるアクセス許可を持つファイル名を に出力するように、スクリプトはfile1のみを出力します私は現在のファイルを表示することによって、アクセス権を手動でチェックしています

for i in $(find .)はスペース、改行、または他の完全に通常の文字を持つ任意のファイル名のあなたに迷惑を与えるために起こっている:

for i in `find .`; do ls -l $i ls -l ../file2/$i; done 

答えて

3

がでfind .出力の解析:権限がは、所有者やグループによって異なる場合があります

$ touch "one file" 
$ for i in `find .` ; do ls -l $i ; done 
total 0 
-rw-r--r-- 1 sarnold sarnold 0 2012-02-08 17:30 one file 
ls: cannot access ./one: No such file or directory 
ls: cannot access file: No such file or directory 
$ 

ので、私はあなたが同様にそれらを含めるべきだと思います。

for f in * ; do stat -c "%a%g%u" "$f" "../scatman/${f}" | 
    sort | uniq -c | grep -q '^\s*1' && echo "$f" is different ; done 

(あなたがechoコマンドのためにやりたい...)

例:あなたはSELinuxのセキュリティラベルを含める必要がある場合は、stat(1)プログラムは簡単には%Cディレクティブ経由だけでなく取得することになります:

$ ls -l sarnold/ scatman/ 
sarnold/: 
total 0 
-r--r--r-- 1 sarnold sarnold 0 2012-02-08 18:00 funky file 
-rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:01 second file 
-rw-r--r-- 1 root root 0 2012-02-08 18:05 third file 

scatman/: 
total 0 
-rw-r--r-- 1 sarnold sarnold 0 2012-02-08 17:30 funky file 
-rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:01 second file 
-rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:05 third file 
$ cd sarnold/ 
$ for f in * ; do stat -c "%a%g%u" "$f" "../scatman/${f}" | sort | uniq -c | grep -q '^\s*1' && echo "$f" is different ; done 
funky file is different 
third file is different 
$ 
+0

本当に素敵な説明。 +1 –

関連する問題