1.linux -ls 查看文件方法
- ls -查看当前目录下文件
yuyandeMacBook-Air:学习 yuyan$ l
hello.txt node test test.sh
- ls -al 查看当前目录下文件属性
yuyandeMacBook-Air:学习 yuyan$ ls -al
total 32
drwxr-xr-x 7 yuyan wheel 224 3 19 15:21 .
drwxr-xr-x 30 root wheel 960 9 27 10:42 ..
-rw-r--r--@ 1 yuyan wheel 6148 3 19 16:00 .DS_Store
-rw-r--r--@ 1 yuyan staff 64 3 16 11:43 hello.txt
drwxr-xr-x 4 yuyan wheel 128 9 28 10:29 node
drwxr-xr-x 4 yuyan wheel 128 3 19 15:35 test
-rw-r--r-- 1 yuyan wheel 46 3 16 17:18 test.sh
2.Liunx 文件基本属性
■chmod : 改变文件的权限, SUID, SGID, SBIT等等的特性。
yuyandeMacBook-Air:学习 yuyan$ ls -al hello_linux.txt
-rw-r--r--@ 1 yuyan wheel 66 3 25 15:21 hello_linux.txt
yuyandeMacBook-Air:学习 yuyan$ chmod 777 hello_linux.txt
yuyandeMacBook-Air:学习 yuyan$ ls -al hello_linux.txt
-rwxrwxrwx@ 1 yuyan wheel 66 3 25 15:21 hello_linux.txt
操作的基本说明:
在 Linux 中我们可以使用 ll 或者 ls –l 命令来显示一个文件的属性以及文件所属的用户和组。
文件第一个属性用d 表示,****d 在liunx 中代表该文件是一个目录文件。
当为 d 则是目录
当为 - 则是文件
-
属性的第一个是文件类型,后面9位以三个为一组,且均为 rwx 的三个参数的组合。
- 其中, r 代表可读(read)、 w 代表可写(write)、 x 代表可执行(execute)。 要注意的是,这三个权限的位置不会改变。
- 如果没有权限,就会出现减号 - 而已。
第一组为“文件拥有者可具备的权限”,文件的拥有者可以读写, 但不可执行。
第二组为“加入此群组之帐号的权限”。
第三组为“非本人且没有加入本群组之其他帐号的权限。
-
九个权限三个为一组,其中我们用数字来代表各个权限,各个权限的分数对照表如下:
- r :4
- w:2
- x:1
-
每种身份(owner/group/others) 各自的三个权限(r/w/x)分数是需要累加的,例如
[-rw-r--r-- ]分数则是:
owner =rw-=4+2= 6
group =r--=4
others=r--=4
综上所述计算规则:设置的权限数字就是644啦
yuyandeMacBook-Air:学习 yuyan$ ls -al hello_linux.txt
rw-r--r--@ 1 yuyan wheel 66 3 25 15:21 hello_linux.txt
修改为全部权限:777
yuyandeMacBook-Air:学习 yuyan$ chmod 777 hello_linux.txt
yuyandeMacBook-Air:学习 yuyan$ ls -al hello_linux.txt
-rwxrwxrwx@ 1 yuyan wheel 66 3 25 15:21 hello_linux.txt
😁愿所有的初心都不会被时间给消磨掉😁