Linux目录操作

特殊目录符号:

  • . 代表此层目录
  • .. 代表上一层目录
  • -代表前一个工作目录
  • ~ 代表『目前使用者身份』所在的家目录,~account 代表account 这个使用者的家目(account是个帐号名称)

需要特别注意的是:在所有目录底下都会存在的两个目录,分别是『.』与『..』 分别代表此层与上层目录的意思。

指令:

  • cd(Change Directory):变换目录
  • pwd(Print Working Directory):显示目前的目录
  • mkdir(Make Directory):建立一个新的目录
  • rmdir(Remove Directory):删除一个空的目录
  • ls(List Segment):列出文件

  • 查看linux文件的权限:ls -l 文件名称
  • 查看linux文件夹的权限:ls -ld 文件夹名称(所在目录)

  • chmod(Change Mode):更改文件权限
  • chown(Change Owner):改变拥有者与所属组群
  • chgrp(Change Group):改变所属群组

例题:

在/tmp 底下建立一个目录,这个目录名称为chapter6_1 ,并且这个目录拥有者为dmtsai(另一用户名称), 群组为dmtsai,此外,任何人都可以进入该目录浏览档案,不过除了dmtsai 之外,其他人都不能修改该目录下的档案。(可将答案写在评论处,遇到不了解的可以使用man,info,help来查询指令。)

目录权限区别:
rwx(7):

[xin@192 tmp]$ ls chapter6_1/
one  two

r-x(5):

[xin@192 tmp]$ ls chapter6_1/
one  two

r- -(4):

[xin@192 tmp]$ ls chapter6_1/
ls: cannot access chapter6_1/one: Permission denied
ls: cannot access chapter6_1/two: Permission denied
one  two

-wx(3):

[xin@192 tmp]$ ls chapter6_1/
ls: cannot open directory chapter6_1/: Permission denied

-w-(2):

[xin@192 tmp]$ ls chapter6_1/
ls: cannot open directory chapter6_1/: Permission denied

–x(1):

[xin@192 tmp]$ ls chapter6_1/
ls: cannot open directory chapter6_1/: Permission denied

综上所述,有x可以cd目录,有r可以ls目录。

猜你喜欢

转载自blog.csdn.net/qq_36751365/article/details/79180345