欢迎光临
我们一直在努力

Linux 文件基本属性56868

Linux 文件基本属性

Linux 系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限。

为了保护系统的安全性,Linux 系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定。

在 Linux 中我们通常使用以下两个命令来修改文件或目录的所属用户与权限:

  • chown (change owner) : 修改所属用户与组。
  • chmod (change mode) : 修改用户的权限。

下图中通过 chown 来授权用户,通过 chmod 为用户设置可以开门的权限。

在 Linux 中我们可以使用 ll 或者 ls –l 命令来显示一个文件的属性以及文件所属的用户和组,如:

[root@www /]# ls -l
total 64
dr-xr-xr-x 2 root root 4096 Dec 14 2012 bin
dr-xr-xr-x 4 root root 4096 Apr 19 2012 boot
……

实例中,bin 文件的第一个属性用 d 表示。d 在 Linux 中代表该文件是一个目录文件。

在 Linux 中第一个字符代表这个文件是目录、文件或链接文件等等。

  • 当为 d 则是目录
  • 当为 – 则是文件;
  • https://avg.163.com/topic/detail/10905643
    https://avg.163.com/topic/detail/10905644
    https://avg.163.com/topic/detail/10905645
    https://avg.163.com/topic/detail/10905646
    https://avg.163.com/topic/detail/10905647
    https://avg.163.com/topic/detail/10905255
    https://avg.163.com/topic/detail/10905264
    https://avg.163.com/topic/detail/10905279
    https://avg.163.com/topic/detail/10905298
    https://avg.163.com/topic/detail/10905310
    https://avg.163.com/topic/detail/10905324
    https://avg.163.com/topic/detail/10905335
    https://avg.163.com/topic/detail/10905348
    https://avg.163.com/topic/detail/10905362
    https://avg.163.com/topic/detail/10905373
    https://avg.163.com/topic/detail/10905386
    https://avg.163.com/topic/detail/10905400
    https://avg.163.com/topic/detail/10905416
    https://avg.163.com/topic/detail/10905444
    https://avg.163.com/topic/detail/10905459
    https://avg.163.com/topic/detail/10905477
    https://avg.163.com/topic/detail/10905494
    https://avg.163.com/topic/detail/10905510
    https://avg.163.com/topic/detail/10905524
    https://avg.163.com/topic/detail/10905538
    https://avg.163.com/topic/detail/10905554
    https://avg.163.com/topic/detail/10905564
    https://avg.163.com/topic/detail/10905581
    https://avg.163.com/topic/detail/10905247
    https://avg.163.com/topic/detail/10905257
    https://avg.163.com/topic/detail/10905272
    https://avg.163.com/topic/detail/10905287
    https://avg.163.com/topic/detail/10905304
    https://avg.163.com/topic/detail/10905316
    https://avg.163.com/topic/detail/10905327
    https://avg.163.com/topic/detail/10905338
    https://avg.163.com/topic/detail/10905349
    https://avg.163.com/topic/detail/10905364
    https://avg.163.com/topic/detail/10905377
    https://avg.163.com/topic/detail/10905392
    https://avg.163.com/topic/detail/10905410
    https://avg.163.com/topic/detail/10905422
    https://avg.163.com/topic/detail/10905439
    https://avg.163.com/topic/detail/10905452
    https://avg.163.com/topic/detail/10905470
    https://avg.163.com/topic/detail/10905500
    https://avg.163.com/topic/detail/10905514
    https://avg.163.com/topic/detail/10905532
    https://avg.163.com/topic/detail/10905545
    https://avg.163.com/topic/detail/10905558
    https://avg.163.com/topic/detail/10905572
    https://avg.163.com/topic/detail/10905587
    https://avg.163.com/topic/detail/10905599
    https://avg.163.com/topic/detail/10905611
    https://avg.163.com/topic/detail/10905619
    https://avg.163.com/topic/detail/10905628
    https://avg.163.com/topic/detail/10905636
    https://avg.163.com/topic/detail/10905250
    https://avg.163.com/topic/detail/10905261
    https://avg.163.com/topic/detail/10905278
    https://avg.163.com/topic/detail/10905249
    https://avg.163.com/topic/detail/10905291
    https://avg.163.com/topic/detail/10905263
    https://avg.163.com/topic/detail/10905311
    https://avg.163.com/topic/detail/10905274
    https://avg.163.com/topic/detail/10905323
    https://avg.163.com/topic/detail/10905288
    https://avg.163.com/topic/detail/10905336
    https://avg.163.com/topic/detail/10905300
    https://avg.163.com/topic/detail/10905353
    https://avg.163.com/topic/detail/10905313
    https://avg.163.com/topic/detail/10905367
    https://avg.163.com/topic/detail/10905326
    https://avg.163.com/topic/detail/10905382
    https://avg.163.com/topic/detail/10905340
    https://avg.163.com/topic/detail/10905393
    https://avg.163.com/topic/detail/10905350
    https://avg.163.com/topic/detail/10905409
    https://avg.163.com/topic/detail/10905363
    https://avg.163.com/topic/detail/10905421
    https://avg.163.com/topic/detail/10905375
    https://avg.163.com/topic/detail/10905436
    https://avg.163.com/topic/detail/10905390
    https://avg.163.com/topic/detail/10905448
    https://avg.163.com/topic/detail/10905404
    https://avg.163.com/topic/detail/10905468
    https://avg.163.com/topic/detail/10905420
    https://avg.163.com/topic/detail/10905483
    https://avg.163.com/topic/detail/10905437
    https://avg.163.com/topic/detail/10905498
    https://avg.163.com/topic/detail/10905449
    https://avg.163.com/topic/detail/10905513
    https://avg.163.com/topic/detail/10905471
    https://avg.163.com/topic/detail/10905528
    https://avg.163.com/topic/detail/10905486
    https://avg.163.com/topic/detail/10905547
    https://avg.163.com/topic/detail/10905501
    https://avg.163.com/topic/detail/10905561
    https://avg.163.com/topic/detail/10905520
    https://avg.163.com/topic/detail/10905576
    https://avg.163.com/topic/detail/10905533
    https://avg.163.com/topic/detail/10905590
    https://avg.163.com/topic/detail/10905546
    https://avg.163.com/topic/detail/10905602
    https://avg.163.com/topic/detail/10905560
    https://avg.163.com/topic/detail/10905614
    https://avg.163.com/topic/detail/10905573
    https://avg.163.com/topic/detail/10905625
    https://avg.163.com/topic/detail/10905589
    https://avg.163.com/topic/detail/10905632
    https://avg.163.com/topic/detail/10905601
    https://avg.163.com/topic/detail/10905639
    https://avg.163.com/topic/detail/10905612
    https://avg.163.com/topic/detail/10905621
    https://avg.163.com/topic/detail/10905629
    https://avg.163.com/topic/detail/10905637
    https://avg.163.com/topic/detail/10905254
    https://avg.163.com/topic/detail/10905259
    https://avg.163.com/topic/detail/10905276
    https://avg.163.com/topic/detail/10905289
    https://avg.163.com/topic/detail/10905305
    https://avg.163.com/topic/detail/10905318
    https://avg.163.com/topic/detail/10905330
    https://avg.163.com/topic/detail/10905345
    https://avg.163.com/topic/detail/10905371
    https://avg.163.com/topic/detail/10905384
    https://avg.163.com/topic/detail/10905394
    https://avg.163.com/topic/detail/10905411
    https://avg.163.com/topic/detail/10905425
    https://avg.163.com/topic/detail/10905440
    https://avg.163.com/topic/detail/10905454
    https://avg.163.com/topic/detail/10905248
    https://avg.163.com/topic/detail/10905472
    https://avg.163.com/topic/detail/10905258
    https://avg.163.com/topic/detail/10905489
    https://avg.163.com/topic/detail/10905277
    https://avg.163.com/topic/detail/10905506
    https://avg.163.com/topic/detail/10905293
    https://avg.163.com/topic/detail/10905521
    https://avg.163.com/topic/detail/10905301
    https://avg.163.com/topic/detail/10905534
    https://avg.163.com/topic/detail/10905312
    https://avg.163.com/topic/detail/10905548
    https://avg.163.com/topic/detail/10905325
    https://avg.163.com/topic/detail/10905559
    https://avg.163.com/topic/detail/10905337
    https://avg.163.com/topic/detail/10905574
    https://avg.163.com/topic/detail/10905351
    https://avg.163.com/topic/detail/10905588
    https://avg.163.com/topic/detail/10905365
    https://avg.163.com/topic/detail/10905598
    https://avg.163.com/topic/detail/10905378
    https://avg.163.com/topic/detail/10905610
    https://avg.163.com/topic/detail/10905389
    https://avg.163.com/topic/detail/10905618
    https://avg.163.com/topic/detail/10905402
    https://avg.163.com/topic/detail/10905627
    https://avg.163.com/topic/detail/10905417
    https://avg.163.com/topic/detail/10905635
    https://avg.163.com/topic/detail/10905252
    https://avg.163.com/topic/detail/10905266
    https://avg.163.com/topic/detail/10905275
    https://avg.163.com/topic/detail/10905294
    https://avg.163.com/topic/detail/10905432
    https://avg.163.com/topic/detail/10905302
    https://avg.163.com/topic/detail/10905447
    https://avg.163.com/topic/detail/10905317
    https://avg.163.com/topic/detail/10905465
    https://avg.163.com/topic/detail/10905329
    https://avg.163.com/topic/detail/10905475
    https://avg.163.com/topic/detail/10905341
    https://avg.163.com/topic/detail/10905492
    https://avg.163.com/topic/detail/10905359
    https://avg.163.com/topic/detail/10905505
    https://avg.163.com/topic/detail/10905374
    https://avg.163.com/topic/detail/10905531
    https://avg.163.com/topic/detail/10905387
    https://avg.163.com/topic/detail/10905549
    https://avg.163.com/topic/detail/10905399
    https://avg.163.com/topic/detail/10905562
    https://avg.163.com/topic/detail/10905414
    https://avg.163.com/topic/detail/10905578
    https://avg.163.com/topic/detail/10905430
    https://avg.163.com/topic/detail/10905591
    https://avg.163.com/topic/detail/10905445
    https://avg.163.com/topic/detail/10905606
    https://avg.163.com/topic/detail/10905463
    https://avg.163.com/topic/detail/10905613
    https://avg.163.com/topic/detail/10905476
    https://avg.163.com/topic/detail/10905622
    https://avg.163.com/topic/detail/10905493
    https://avg.163.com/topic/detail/10905630
    https://avg.163.com/topic/detail/10905509
    https://avg.163.com/topic/detail/10905523
    https://avg.163.com/topic/detail/10905536
    https://avg.163.com/topic/detail/10905552
    https://avg.163.com/topic/detail/10905565
    https://avg.163.com/topic/detail/10905582
    https://avg.163.com/topic/detail/10905597
    https://avg.163.com/topic/detail/10905608
    https://avg.163.com/topic/detail/10905616
    https://avg.163.com/topic/detail/10905623
    https://avg.163.com/topic/detail/10905633
    https://avg.163.com/topic/detail/10905640
    https://avg.163.com/topic/detail/10905246
    https://avg.163.com/topic/detail/10905262
    https://avg.163.com/topic/detail/10905271
    https://avg.163.com/topic/detail/10905286
    https://avg.163.com/topic/detail/10905299
    https://avg.163.com/topic/detail/10905319
    https://avg.163.com/topic/detail/10905333
    https://avg.163.com/topic/detail/10905354
    https://avg.163.com/topic/detail/10905385
    https://avg.163.com/topic/detail/10905396
    https://avg.163.com/topic/detail/10905413
    https://avg.163.com/topic/detail/10905427
    https://avg.163.com/topic/detail/10905442
    https://avg.163.com/topic/detail/10905455
    https://avg.163.com/topic/detail/10905473
    https://avg.163.com/topic/detail/10905253
    https://avg.163.com/topic/detail/10905491
    https://avg.163.com/topic/detail/10905260
    https://avg.163.com/topic/detail/10905507
    https://avg.163.com/topic/detail/10905273
    https://avg.163.com/topic/detail/10905522
    https://avg.163.com/topic/detail/10905290
    https://avg.163.com/topic/detail/10905535
    https://avg.163.com/topic/detail/10905306
    https://avg.163.com/topic/detail/10905550
    https://avg.163.com/topic/detail/10905322
    https://avg.163.com/topic/detail/10905563
    https://avg.163.com/topic/detail/10905334
    https://avg.163.com/topic/detail/10905580
    https://avg.163.com/topic/detail/10905347
    https://avg.163.com/topic/detail/10905251
    https://avg.163.com/topic/detail/10905361
    https://avg.163.com/topic/detail/10905265
    https://avg.163.com/topic/detail/10905372
    https://avg.163.com/topic/detail/10905292
    https://avg.163.com/topic/detail/10905383
    https://avg.163.com/topic/detail/10905303
    https://avg.163.com/topic/detail/10905397
    https://avg.163.com/topic/detail/10905314
    https://avg.163.com/topic/detail/10905412
    https://avg.163.com/topic/detail/10905328
    https://avg.163.com/topic/detail/10905424
    https://avg.163.com/topic/detail/10905339
    https://avg.163.com/topic/detail/10905438
    https://avg.163.com/topic/detail/10905352
    https://avg.163.com/topic/detail/10905451
    https://avg.163.com/topic/detail/10905366
    https://avg.163.com/topic/detail/10905467
    https://avg.163.com/topic/detail/10905391
    https://avg.163.com/topic/detail/10905479
    https://avg.163.com/topic/detail/10905408
    https://avg.163.com/topic/detail/10905496
    https://avg.163.com/topic/detail/10905423
    https://avg.163.com/topic/detail/10905512
    https://avg.163.com/topic/detail/10905435
    https://avg.163.com/topic/detail/10905527
    https://avg.163.com/topic/detail/10905450
    https://avg.163.com/topic/detail/10905540
    https://avg.163.com/topic/detail/10905464
    https://avg.163.com/topic/detail/10905556
    https://avg.163.com/topic/detail/10905478
    https://avg.163.com/topic/detail/10905571
    https://avg.163.com/topic/detail/10905495
    https://avg.163.com/topic/detail/10905586
    https://avg.163.com/topic/detail/10905511
    https://avg.163.com/topic/detail/10905595
    https://avg.163.com/topic/detail/10905526
    https://avg.163.com/topic/detail/10905607
    https://avg.163.com/topic/detail/10905539
    https://avg.163.com/topic/detail/10905615
    https://avg.163.com/topic/detail/10905553
    https://avg.163.com/topic/detail/10905626
    https://avg.163.com/topic/detail/10905566
    https://avg.163.com/topic/detail/10905585
    https://avg.163.com/topic/detail/10905594
    https://avg.163.com/topic/detail/10905609
    https://avg.163.com/topic/detail/10905617
    https://avg.163.com/topic/detail/10905624
    https://avg.163.com/topic/detail/10905631
    https://avg.163.com/topic/detail/10905638
    https://avg.163.com/topic/detail/10905641
     
  • 若是 l 则表示为链接文档(link file);
  • 若是 b 则表示为装置文件里面的可供储存的接口设备(可随机存取装置);
  • 若是 c 则表示为装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)。

接下来的字符中,以三个为一组,且均为 rwx 的三个参数的组合。其中, r 代表可读(read)、 w 代表可写(write)、 x 代表可执行(execute)。 要注意的是,这三个权限的位置不会改变,如果没有权限,就会出现减号 – 而已。

每个文件的属性由左边第一部分的 10 个字符来确定(如下图)。

363003_1227493859FdXT

从左至右用 0-9 这些数字来表示。

第 0 位确定文件类型,第 1-3 位确定属主(该文件的所有者)拥有该文件的权限。

第4-6位确定属组(所有者的同组用户)拥有该文件的权限,第7-9位确定其他用户拥有该文件的权限。

其中,第 1、4、7 位表示读权限,如果用 r 字符表示,则有读权限,如果用 – 字符表示,则没有读权限;

第 2、5、8 位表示写权限,如果用 w 字符表示,则有写权限,如果用 – 字符表示没有写权限;第 3、6、9 位表示可执行权限,如果用 x 字符表示,则有执行权限,如果用 – 字符表示,则没有执行权限。


Linux文件属主和属组

[root@www /]# ls -l
total 64
drwxr-xr-x 2 root root 4096 Feb 15 14:46 cron
drwxr-xr-x 3 mysql mysql 4096 Apr 21 2014 mysql
……

对于文件来说,它都有一个特定的所有者,也就是对该文件具有所有权的用户。

同时,在Linux系统中,用户是按组分类的,一个用户属于一个或多个组。

文件所有者以外的用户又可以分为文件所属组的同组用户和其他用户。

因此,Linux系统按文件所有者、文件所有者同组用户和其他用户来规定了不同的文件访问权限。

在以上实例中,mysql 文件是一个目录文件,属主和属组都为 mysql,属主有可读、可写、可执行的权限;与属主同组的其他用户有可读和可执行的权限;其他用户也有可读和可执行的权限。

对于 root 用户来说,一般情况下,文件的权限对其不起作用。


更改文件属性

1、chgrp:更改文件属组

语法:

chgrp [-R] 属组名 文件名

参数选项

  • -R:递归更改文件属组,就是在更改某个目录文件的属组时,如果加上 -R 的参数,那么该目录下的所有文件的属组都会更改。

2、chown:更改文件所有者(owner),也可以同时更改文件所属组。

语法:

chown [–R] 所有者 文件名
chown [-R] 所有者:属组名 文件名

进入 /root 目录(~)将install.log的拥有者改为bin这个账号:

[root@www ~] cd ~
[root@www ~]# chown bin install.log
[root@www ~]# ls -l

赞(0)
未经允许不得转载:171主机测评 » Linux 文件基本属性56868
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址