LoginSignup
2
2

More than 5 years have passed since last update.

chown と chmod の少し便利な技

Last updated at Posted at 2012-10-05

chown で hoge:hoge. のようにグループを空にするとユーザのプライマリグループが設定される。

# ll
-rw-r--r-- 1 root root 0 10月  5 12:41 2012 file1
-rw-r--r-- 1 root root 0 10月  5 12:41 2012 file2
-rw-r--r-- 1 root root 0 10月  5 12:41 2012 file3

# chown hoge file1
# chown hoge. file2
# chown hoge.hoge file3

# ll
-rw-r--r-- 1 hoge root 0 10月  5 12:41 2012 file1
-rw-r--r-- 1 hoge hoge 0 10月  5 12:41 2012 file2
-rw-r--r-- 1 hoge hoge 0 10月  5 12:41 2012 file3

chmod で X を指定すると、ディレクトリまたは既にユーザーに実行アクセス権がある場合のみ実行アクセス権が付与される。
-R や グロブ で一括設定する場合に便利!

$ ll
合計 4
drwx------ 2 hoge hoge 4096 10月  5 12:45 2012 dir
-rwx------ 1 hoge hoge    0 10月  5 12:45 2012 file.sh
-rw------- 1 hoge hoge    0 10月  5 12:45 2012 file.txt

$ chmod g+rX *
drwxr-x--- 2 hoge hoge 4096 10月  5 12:45 2012 dir
-rwxr-x--- 1 hoge hoge    0 10月  5 12:45 2012 file.sh
-rw-r----- 1 hoge hoge    0 10月  5 12:45 2012 file.txt
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2