GNU/Linux >> Linux の 問題 >  >> Linux

Linux で 1 つのディレクトリを除くすべてのファイルのアクセス許可を変更できますか?

"nameOfFolderToBeExcluded" という名前のフォルダーの内容とは別に、現在の作業ディレクトリ内のフォルダーの内容に対して許可ビット 755 を再帰的に設定するとします。 :

 chmod 755 -R $(ls | awk '{if($1 != "nameOfFolderToBeExcluded"){ print $1 }}')

find を使用できます 指定されたファイル名と exec に一致しないすべてのファイルを検索するには 次のようなすべてのファイルに対するコマンド:

ディレクトリ test を除外する必要があると仮定します 他のすべてのファイルとディレクトリにファイル許可 755 を与えます。これはツリーの一番上から実行されます。

find ! -name test -exec chmod 755 {} \;

テスト済み

[email protected]:$ touch a1.txt a2.txt a3.txt test
[email protected]:$ ls -lrt
total 0
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 test
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a3.txt
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a2.txt
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a1.txt
[email protected]:$ find ! -name test -exec chmod 777 {} \;
[email protected]:$ ls -lrt
total 0
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 test
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a3.txt*
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a2.txt*
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a1.txt*
[email protected]:$ 

ファイル test のファイル許可 変わらずでした。ディレクトリにも同じことが当てはまります。


何の殻?

bash を実行している場合 (おそらく Linux を使用している場合)、extglob を確認できます。これにより、「ネガティブ グロブ」!() など、グロビングのオプションが増えます。

shopt -s extglob
chmod 774 !(file-to-ignore)

Linux
  1. ディレクトリとファイルの権限を変更するには

  2. ディレクトリ内のすべてのファイルを削除する3つの方法(拡張子が付いた1つまたは少数のファイルを除く)

  3. Linuxですべてのファイルとディレクトリ名を小文字に変更

  1. Linuxですべてのディレクトリのファイルを再帰的に検索する方法

  2. すべてのファイル(非表示を含む)をあるディレクトリから別のディレクトリに移動するにはどうすればよいですか?

  3. 検索を使用して特定のディレクトリを検索し、1つのディレクトリを除くその中のすべてのファイルを削除しますか?

  1. Linuxで1つの特定のファイルを除いてフォルダ内のすべてのファイルを削除する方法

  2. バックアップする必要がある9つのLinuxディレクトリとバックアップしない1つのLinuxディレクトリ

  3. 1つのファイルを除くすべてのファイル/ディレクトリを削除しますか?