当前位置: 首页 > news >正文

Linux基本指令(下)

文章目录

      • 2.22 tar 指令
      • 2.23 bc 指令
      • 2.24 uname 指令
      • 2.25 重要的几个热键
      • 2.26 关机
    • 3. shell命令以及运行原理
    • 4. Linux权限的概念
    • 5. Linux权限管理

2.22 tar 指令

参数:

  • -c :建立一个压缩文件的参数指令(create 的意思)
  • -x :解开一个压缩文件的参数指令
  • -z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
  • -v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
  • -f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
  • -C : 解压到指定目录
[root@VM-4-3-centos 112]# ll
total 16
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# tar czf lesson4.tgz lesson4
[root@VM-4-3-centos 112]# ll
total 20
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# tar cvzf lesson4.tgz lesson4
lesson4/
lesson4/dir/
lesson4/dir/dir1/
lesson4/dir/dir1/dir2/
lesson4/dir/dir1/dir2/dir3/
lesson4/file.txt
lesson4/new.txt
lesson4/bigfile.txt
[root@VM-4-3-centos 112]# ll
total 20
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# rm lesson4 -rf
[root@VM-4-3-centos 112]# ll
total 16
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# tar xvzf lesson4.tgz 
lesson4/
lesson4/dir/
lesson4/dir/dir1/
lesson4/dir/dir1/dir2/
lesson4/dir/dir1/dir2/dir3/
lesson4/file.txt
lesson4/new.txt
lesson4/bigfile.txt
[root@VM-4-3-centos 112]# ll
total 20
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# tree lesson4
lesson4
|-- bigfile.txt
|-- dir
|   `-- dir1
|       `-- dir2
|           `-- dir3
|-- file.txt
`-- new.txt4 directories, 3 files
[root@VM-4-3-centos 112]# cat lesson4/bigfile.txt 
aaaaaaaaa
bbbbb
cccccc
ddddddddd
eeeeeeeeeee
ffffffffff
[root@VM-4-3-centos 112]# sz lesson4.tgz 
[root@VM-4-3-centos 112]# 
rz -E
rz waiting to receive.
[root@VM-4-3-centos 112]# ll
total 24
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz.0
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# rm lesson4.tgz.0 
rm: remove regular file ‘lesson4.tgz.0? y
[root@VM-4-3-centos 112]# ll
total 20
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 2 root root 4096 Oct  6 17:46 otherdir
[root@VM-4-3-centos 112]# tar xvzf lesson4.tgz -C otherdir/
lesson4/
lesson4/dir/
lesson4/dir/dir1/
lesson4/dir/dir1/dir2/
lesson4/dir/dir1/dir2/dir3/
lesson4/file.txt
lesson4/new.txt
lesson4/bigfile.txt
[root@VM-4-3-centos 112]# ll
total 20
drwxr-xr-x 3 root root 4096 Jan 30  2025 lesson2
drwxr-xr-x 3 root root 4096 Oct  5 15:45 lesson3
drwxr-xr-x 3 root root 4096 Oct  6 16:55 lesson4
-rw-r--r-- 1 root root  284 Oct  7 13:04 lesson4.tgz
drwxr-xr-x 3 root root 4096 Oct  7 13:10 otherdir
[root@VM-4-3-centos 112]# tree otherdir/
otherdir/
`-- lesson4|-- bigfile.txt|-- dir|   `-- dir1|       `-- dir2|           `-- dir3|-- file.txt`-- new.txt5 directories, 3 files
[root@VM-4-3-centos 112]# cat otherdir/lesson4/bigfile.txt 
aaaaaaaaa
bbbbb
cccccc
ddddddddd
eeeeeeeeeee
ffffffffff

zip和tar

2.23 bc 指令

bc命令可以很方便的进行浮点运算

[root@VM-4-3-centos 112]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1+1
2
13*100
1300
10/0
Runtime error (func=(main), adr=6): Divide by zero
quit
[root@VM-4-3-centos 112]# echo "1+2+3+4+5+6" | bc
21

2.24 uname 指令

体系结构

功能: uname用来获取电脑和操作系统的相关信息。
补充说明:uname可显示linux主机所用的操作系统的版本、硬件的名称等基本信息。
常用选项:

  • -a 详细输出所有信息,依次为内核名称,主机名,内核版本号,内核版本,硬件名,处理器类型,硬件平台类型,操作系统名称
[root@VM-4-3-centos 112]# uname
Linux
[root@VM-4-3-centos 112]# hostname
VM-4-3-centos
[root@VM-4-3-centos 112]# uname -a
Linux VM-4-3-centos 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-3-centos 112]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@VM-4-3-centos 112]# uname -r
3.10.0-1160.119.1.el7.x86_64

2.25 重要的几个热键

  • [Tab]按键—具有『命令补全』和『档案补齐』的功能
  • [Ctrl]-r按键—搜索历史命令
  • [Ctrl]-c按键—让当前的程序『停掉』
  • [Ctrl]-d按键—通常代表着:『键盘输入结束(End Of File, EOF 戒 End OfInput)』的意思;另外,他也可以用来取代exit

2.26 关机

语法:shutdown [选项]
常见选项:

  • -h:将系统的服务停掉后,立即关机
  • -r:在将系统的服务停掉之后就重新启动
  • -t sec:-t 后面加秒数,亦即『过几秒后关机』的意思

3. shell命令以及运行原理

Linux严格意义上说的是一个操作系统,我们称之为”核心(kernel)“ ,但我们一般用户,不能直接使用kernel。而是通过kernel的“外壳”程序,也就是所谓的shell,来与kernel沟通。如何理解?为什么不能直接使用kernel?

shell命令以及运行原理

4. Linux权限的概念

Linux下有两种用户:超级用户(root)、普通用户。

  • 超级用户:可以再linux系统下做任何事情,不受限制
  • 普通用户:在linux下做有限的事情
  • 超级用户的命令提示符是“#”,普通用户的命令提示符是“$”

命令:su [用户名]

功能:切换用户

[gsm@VM-4-3-centos ~]$ whoami
gsm
[gsm@VM-4-3-centos ~]$ su -
Password: 
Last login: Thu Oct  9 15:40:56 CST 2025 on pts/0
[root@VM-4-3-centos ~]# whoami
root
[root@VM-4-3-centos ~]# logout
[gsm@VM-4-3-centos ~]$ whoami
gsm
[gsm@VM-4-3-centos ~]$ ls /home
gsm  lighthouse
[gsm@VM-4-3-centos ~]$ su lighthouse
Password: 
[gsm@VM-4-3-centos ~]$ su -
Password: 
Last login: Thu Oct  9 15:42:48 CST 2025 on pts/0
[root@VM-4-3-centos ~]# whoami
root
[root@VM-4-3-centos ~]# su lighthouse
[lighthouse@VM-4-3-centos root]$ whoami
lighthouse
[lighthouse@VM-4-3-centos root]$ exit

5. Linux权限管理

Linux权限管理(1)

Linux权限管理(2)

[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u+x file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxrw-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u-w file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-r-xrw-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u-rx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
----rw-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u+rwx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxrw-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod g-w file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxr--r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod g+x file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxr-xr-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod g+w,g-rx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwx-w-r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod o-rwx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwx-w---- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod o+rwx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwx-w-rwx 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u-rwx,g-rwx,o-rwx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
---------- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod a+rwx file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxrwxrwx 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod a-x file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-rw-rw- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-rw-rw- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod 000 file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
---------- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod 777 file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rwxrwxrwx 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod 444 file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-r--r--r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod 644 file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-r--r-- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod 640 file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-r----- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ ll
total 4
-rw-r----- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ chmod u-rwx,g+rw file-gsm 
[gsm@VM-4-3-centos lesson4]$ ll
total 4
----rw---- 1 gsm gsm 8 Oct  9 16:48 file-gsm
[gsm@VM-4-3-centos lesson4]$ echo "hello world" > file-gsm 
-bash: file-gsm: Permission denied
[root@VM-4-3-centos lesson5]# ll
total 4
---------- 1 root root 9 Oct  9 18:12 testfile.txt
[root@VM-4-3-centos lesson5]# chmod 644 testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--r-- 1 root root 9 Oct  9 18:12 testfile.txt
[root@VM-4-3-centos lesson5]# su gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-r--r-- 1 root root 9 Oct  9 18:12 testfile.txt
[gsm@VM-4-3-centos lesson5]$ whoami
gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-r--r-- 1 root root 9 Oct  9 18:12 testfile.txt
[gsm@VM-4-3-centos lesson5]$ cat testfile.txt 
bbbbbbbb
[gsm@VM-4-3-centos lesson5]$ echo "aaaaa" >> testfile.txt 
bash: testfile.txt: Permission denied
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-r--r-- 1 root root 9 Oct  9 18:12 testfile.txt
[gsm@VM-4-3-centos lesson5]$ exit
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--r-- 1 root root 9 Oct  9 18:12 testfile.txt
[root@VM-4-3-centos lesson5]# chown gsm testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--r-- 1 gsm root 9 Oct  9 18:12 testfile.txt
[root@VM-4-3-centos lesson5]# su gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-r--r-- 1 gsm root 9 Oct  9 18:12 testfile.txt
[gsm@VM-4-3-centos lesson5]$ cat testfile.txt 
bbbbbbbb
[gsm@VM-4-3-centos lesson5]$ echo "aaaaaaa" >> testfile.txt 
[gsm@VM-4-3-centos lesson5]$ cat testfile.txt 
bbbbbbbb
aaaaaaa
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-r--r-- 1 gsm root 17 Oct  9 18:28 testfile.txt
[gsm@VM-4-3-centos lesson5]$ exit
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--r-- 1 gsm root 17 Oct  9 18:28 testfile.txt
[root@VM-4-3-centos lesson5]# chown root testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--r-- 1 root root 17 Oct  9 18:28 testfile.txt
[root@VM-4-3-centos lesson5]# chmod g+w testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-rw-r-- 1 root root 17 Oct  9 18:28 testfile.txt
[root@VM-4-3-centos lesson5]# chmod u-w testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-r--rw-r-- 1 root root 17 Oct  9 18:28 testfile.txt
[root@VM-4-3-centos lesson5]# chgrp gsm testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
-r--rw-r-- 1 root gsm 17 Oct  9 18:28 testfile.txt
[root@VM-4-3-centos lesson5]# su gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-r--rw-r-- 1 root gsm 17 Oct  9 18:28 testfile.txt
[gsm@VM-4-3-centos lesson5]$ whoami
gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-r--rw-r-- 1 root gsm 17 Oct  9 18:28 testfile.txt
[gsm@VM-4-3-centos lesson5]$ cat testfile.txt 
bbbbbbbb
aaaaaaa
[gsm@VM-4-3-centos lesson5]$ echo "cccccccccc" >> testfile.txt 
[gsm@VM-4-3-centos lesson5]$ cat testfile.txt 
bbbbbbbb
aaaaaaa
cccccccccc
[gsm@VM-4-3-centos lesson5]$ pwd
/home/gsm/112/lesson5
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ cd dir
[gsm@VM-4-3-centos dir]$ pwd
/home/gsm/112/lesson5/dir
[gsm@VM-4-3-centos dir]$ cd ..
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ chmod u-r dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
d-wxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ cd dir
[gsm@VM-4-3-centos dir]$ pwd
/home/gsm/112/lesson5/dir
[gsm@VM-4-3-centos dir]$ ls
ls: cannot open directory .: Permission denied
[gsm@VM-4-3-centos dir]$ touch hello.txt
[gsm@VM-4-3-centos dir]$ ll
ls: cannot open directory .: Permission denied
[gsm@VM-4-3-centos dir]$ cd ..
[gsm@VM-4-3-centos lesson5]$ pwd
/home/gsm/112/lesson5
[gsm@VM-4-3-centos lesson5]$ ll
total 8
d-wxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ chmod u+r dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ chmod u-w dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
dr-xrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ cd dir
[gsm@VM-4-3-centos dir]$ pwd
/home/gsm/112/lesson5/dir
[gsm@VM-4-3-centos dir]$ ll
total 0
-rw-rw-r-- 1 gsm gsm 0 Oct  9 20:04 hello.txt
[gsm@VM-4-3-centos dir]$ touch world.txt
touch: cannot touch ‘world.txt’: Permission denied
[gsm@VM-4-3-centos dir]$ rm hello.txt 
rm: cannot remove ‘hello.txt’: Permission denied
[gsm@VM-4-3-centos dir]$ ll
total 0
-rw-rw-r-- 1 gsm gsm 0 Oct  9 20:04 hello.txt
[gsm@VM-4-3-centos dir]$ mv hello.txt world.txt
mv: cannot move ‘hello.txt’ to ‘world.txt’: Permission denied
[gsm@VM-4-3-centos dir]$ ll
total 0
-rw-rw-r-- 1 gsm gsm 0 Oct  9 20:04 hello.txt
[gsm@VM-4-3-centos dir]$ cat hello.txt 
[gsm@VM-4-3-centos dir]$ echo "aaaaaaa" > hello.txt 
[gsm@VM-4-3-centos dir]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 8 Oct  9 20:10 hello.txt
[gsm@VM-4-3-centos dir]$ cat hello.txt 
aaaaaaa
[gsm@VM-4-3-centos dir]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 8 Oct  9 20:10 hello.txt
[gsm@VM-4-3-centos dir]$ pwd
/home/gsm/112/lesson5/dir
[gsm@VM-4-3-centos dir]$ cd ..
[gsm@VM-4-3-centos lesson5]$ ll
total 8
dr-xrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ chmod u+w dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ chmod u-x dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drw-rwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ cd dir
-bash: cd: dir: Permission denied
[gsm@VM-4-3-centos lesson5]$ chmod u+x dir
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ cd dir
[gsm@VM-4-3-centos dir]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 8 Oct  9 20:10 hello.txt
[gsm@VM-4-3-centos dir]$ cd ..
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file.txt
[gsm@VM-4-3-centos lesson5]$ pwd
/home/gsm/112/lesson5
[gsm@VM-4-3-centos lesson5]$ rm file.txt 
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:04 dir
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:01 dir1
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:00 file1.txt
[gsm@VM-4-3-centos lesson5]$ pwd
/home/gsm/112/lesson5
[gsm@VM-4-3-centos lesson5]$ ll -d /home/gsm/112/lesson5
drwxrwxr-x 4 gsm gsm 4096 Oct  9 20:15 /home/gsm/112/lesson5
[gsm@VM-4-3-centos lesson5]$ mkdir dir
[gsm@VM-4-3-centos lesson5]$ ll
total 4
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
[gsm@VM-4-3-centos lesson5]$ touch file.txt
[gsm@VM-4-3-centos lesson5]$ ll
total 4
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ umask
0002
[gsm@VM-4-3-centos lesson5]$ umask 000
[gsm@VM-4-3-centos lesson5]$ umask
0000
[gsm@VM-4-3-centos lesson5]$ ll
total 4
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ touch file1.txt
[gsm@VM-4-3-centos lesson5]$ ll
total 4
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
-rw-rw-rw- 1 gsm gsm    0 Oct  9 20:56 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ umask
0000
[gsm@VM-4-3-centos lesson5]$ mkdir dir1
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
drwxrwxrwx 2 gsm gsm 4096 Oct  9 20:56 dir1
-rw-rw-rw- 1 gsm gsm    0 Oct  9 20:56 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ umask 777
[gsm@VM-4-3-centos lesson5]$ umask
0777
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
drwxrwxrwx 2 gsm gsm 4096 Oct  9 20:56 dir1
-rw-rw-rw- 1 gsm gsm    0 Oct  9 20:56 file1.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ touch file2.txt
[gsm@VM-4-3-centos lesson5]$ ll
total 8
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
drwxrwxrwx 2 gsm gsm 4096 Oct  9 20:56 dir1
-rw-rw-rw- 1 gsm gsm    0 Oct  9 20:56 file1.txt
---------- 1 gsm gsm    0 Oct  9 20:58 file2.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ mkdir dir2
[gsm@VM-4-3-centos lesson5]$ ll
total 12
drwxrwxr-x 2 gsm gsm 4096 Oct  9 20:34 dir
drwxrwxrwx 2 gsm gsm 4096 Oct  9 20:56 dir1
d--------- 2 gsm gsm 4096 Oct  9 20:59 dir2
-rw-rw-rw- 1 gsm gsm    0 Oct  9 20:56 file1.txt
---------- 1 gsm gsm    0 Oct  9 20:58 file2.txt
-rw-rw-r-- 1 gsm gsm    0 Oct  9 20:34 file.txt
[gsm@VM-4-3-centos lesson5]$ umask 002
[gsm@VM-4-3-centos lesson5]$ umask
0002

注:

  1. root 不受权限约束
[root@VM-4-3-centos lesson5]# ll
total 4
-rw-r--rw- 1 root root 13 Oct  9 17:42 testfile.txt
[root@VM-4-3-centos lesson5]# whoami
root
[root@VM-4-3-centos lesson5]# chmod 000 testfile.txt 
[root@VM-4-3-centos lesson5]# ll
total 4
---------- 1 root root 13 Oct  9 17:42 testfile.txt
[root@VM-4-3-centos lesson5]# cat testfile.txt 
aaaaaaaaaaaa
[root@VM-4-3-centos lesson5]# echo "bbbbbbbb" > testfile.txt 
[root@VM-4-3-centos lesson5]# cat testfile.txt 
bbbbbbbb
[root@VM-4-3-centos lesson5]# ll
total 4
---------- 1 root root 9 Oct  9 18:12 testfile.txt
[root@VM-4-3-centos lesson5]# cd /home/gsm/112/lesson5
[root@VM-4-3-centos lesson5]# ll
total 0
-rw-rw---- 1 gsm gsm 0 Oct  9 18:15 file.txt
[root@VM-4-3-centos lesson5]# echo "aaaaa" > file.txt
[root@VM-4-3-centos lesson5]# cat file.txt 
aaaaa
  1. 可执行权限有点特殊,不是说有可执行权限就能执行,一个程序真正要跑起来需要同时满足:它是一个可执行文件且你具备可执行权限
  2. 如果想更改文件的拥有者和所属组,只能是超级用户或者用sudo
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-r--rw-r-- 1 root gsm 28 Oct  9 18:33 testfile.txt
[gsm@VM-4-3-centos lesson5]$ exit
[root@VM-4-3-centos lesson5]# chown gsm:gsm testfile.txt 
[root@VM-4-3-centos lesson5]# su gsm
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-r--rw-r-- 1 gsm gsm 28 Oct  9 18:33 testfile.txt
[gsm@VM-4-3-centos lesson5]$ pwd
/root/112/lesson5
[gsm@VM-4-3-centos lesson5]$ chmod 666 testfile.txt 
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-rw-rw- 1 gsm gsm 28 Oct  9 18:33 testfile.txt
[gsm@VM-4-3-centos lesson5]$ chown root testfile.txt 
chown: changing ownership of ‘testfile.txt’: Operation not permitted
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-rw-rw- 1 gsm gsm 28 Oct  9 18:33 testfile.txt
[gsm@VM-4-3-centos lesson5]$ chown lighthouse testfile.txt 
chown: changing ownership of ‘testfile.txt’: Operation not permitted
[gsm@VM-4-3-centos lesson5]$ ll
total 4
-rw-rw-rw- 1 gsm gsm 28 Oct  9 18:33 testfile.txt
[gsm@VM-4-3-centos lesson5]$ chgrp root testfile.txt 
chgrp: changing group of ‘testfile.txt’: Operation not permitted
[gsm@VM-4-3-centos lesson5]$ chgrp lighthouse testfile.txt 
chgrp: changing group of ‘testfile.txt’: Operation not permitted

粘滞位

如果很多人共享一个目录时,他们都具有rwx权限,但是不想让一个人删除该目录下其他人的文件和目录,就需要用到粘滞位。

[root@VM-4-3-centos /]# chmod o+t /share_112
[root@VM-4-3-centos /]# ls /share_112/ -ld
drwxr-xrwt 2 root root 4096 Oct  9 22:05 /share_112/

当一个目录被设置为"粘滞位",则该目录下的文件只能由

  1. 超级管理员删除
  2. 该目录的所有者删除
  3. 该文件的所有者删除
http://www.dtcms.com/a/462763.html

相关文章:

  • 手机网站用什么软件开发html5 企业网站
  • IDEA在plugins里搜不到mybatisx插件的解决方法
  • 广州网站建设多少钱深圳网上申请个人营业执照
  • 高端响应式网站建设wordpress动态插件
  • fastadmin列表头部加按钮,点击弹出窗口提交数据保存
  • 网站进行中英文转换怎么做新手销售怎么和客户交流
  • MySQL索引调优之索引顺序是否应该“匹配查询书写顺序”?
  • 安阳网站建设开发用五百丁做名字的简历网站
  • 企业做网站的注意事项沈阳商城网站开发
  • 堆:数组中的第K个最大数
  • 如何添加网站 ico图标小游戏开发需要多少钱
  • printf输出乱码的解决办法
  • 汕头做网站优化的公司两个wordpress
  • 网站域名在哪里如何建立一个免费的网站
  • 重庆交通建设监理协会网站建设银行招标网站
  • 温州企业自助建站系统虚拟主机怎么设计网站吗
  • 网站备案表是什么纪检监察网站建设背景
  • FDC1004学习笔记二:读写数据
  • 双剑合璧:Microsoft Agent Framework——Python与.NET的AI智能体协奏曲
  • 行动比空想更有力量。哪怕只是一小步,也是通向目标的开始。
  • 学习笔记--分页查询 条件分页查询
  • 东莞网络推广网站部门网站建设管理
  • 流式推理 vs 训练模式详细对比
  • 一个酷炫的烟花网站
  • 【AES加密专题】2.AES头文件详解
  • 腾讯员工月薪多少郴州网站seo
  • 网站建设培训个人网络服务器
  • STM32H743-ARM例程14-FATFS
  • 具有营销型网站的公司有哪些网页设计个人简介代码
  • 网站的交互体验网站备案单位的联系方式