content
Compression and decompression classes
gzip compression/gunzip decompression instructions
zip compression/unzip decompression instructions
tar compression and decompression instructions
Group management and authority management (practice)
Basic introduction to linux groups
ls -ahl to view the group where the file/directory is located
chgrp modifies the group where the file is located
Compression and decompression classes
gzip compression/gunzip decompression instructions
gzip is used to compress files, gunzip is used to decompress files
Basic syntax:
gzip files (compressed files, can only compress files as *.gz files)
gunzip file.gz (unzip file command)
Example : Compress and decompress the hello.txt file
[root@kongchao02 /]# ls /home
hello.txt kc kongchao kongchao1 kongchao2
[root@kongchao02 /]# gzip /home/hello.txt
[root@kongchao02 /]# ls /home
hello.txt.gz kc kongchao kongchao1 kongchao2
[root@kongchao02 /]# gunzip /home/hello.txt.gz
[root@kongchao02 /]# ls /home
hello.txt kc kongchao kongchao1 kongchao2
[root@kongchao02 /]#
zip compression/unzip decompression instructions
zip is used for compressing files, and unzip is used for decompression, which plays a great role in project packaging and distribution
Basic syntax:
zip [options] xxx.zip (command to compress files and directories)
unzip [options] xxx.zip (command to unzip files)
zip common options -r : recursive compression, that is, compress a directory
Common options for unzip -d <directory>: specify the storage directory of the compressed file
Example 1 : Compress all files/folders under /home into myhome.zip (/home/ includes home)
[root@kongchao02 /]# cd /home
[root@kongchao02 home]# zip -r myhome.zip /home/
(上面这句表示将/home/下的文件压缩为名叫myhome.zip的文件)
Example 2 : Unzip myhome.zip to ? /opt/tmp directory
mkdir /opt/tmp
unzip -d /opt/tmp /home/myhome.zip
tar compression and decompression instructions
The tar command is a packaging command, and the final packaged file is the .tar.gz file,
Basic syntax: tar [options] xxx.tar.gz Package content (package directory, compressed file format. tar.gz)
Option Description:
Options | Function |
-c | Generate .tar package file |
-v | show details |
-f | Specify the compressed file name |
-with | Pack and compress |
-x | Unpack the .tar file |
Example 1 : Compress multiple files, compress /home/kong.txt and /home/chao.txt into kc.tar.gz
tar -zcvf kc.tar.gz /home/kong.txt /home/chao.txt
[root@kongchao02 home]# ls
hello.txt kc kongchao kongchao1 kongchao2 myhome.zip
[root@kongchao02 home]# touch kong.txt
[root@kongchao02 home]# touch chao.txt
[root@kongchao02 home]# ls
chao.txt hello.txt kc kongchao kongchao1 kongchao2 kong.txt myhome.zip
[root@kongchao02 home]# tar -zcvf kc1.tar.gz kong.txt chao.txt
bash: tar : 未找到命令...
[root@kongchao02 home]# tar -zcvf kc.tar.gz /home/kong.txt /home/chao.txt
tar: 从成员名中删除开头的“/”
/home/kong.txt
/home/chao.txt
[root@kongchao02 home]# ls
chao.txt kc kongchao kongchao2 myhome.zip
hello.txt kc.tar.gz kongchao1 kong.txt
Example 2: Compress the /home folder into myhome.tar.gz
tar -zcvf myhome.tar.gz /home/
Example 3: Extract kc.tar.gz to the current directory
tar -zxvf kc.tar.gz
[root@kongchao02 home]# ls
chao.txt kc kongchao kongchao2 myhome.tar.gz
hello.txt kc.tar.gz kongchao1 kong.txt myhome.zip
[root@kongchao02 home]# rm chao.txt kong.txt
rm:是否删除普通空文件 "chao.txt"?y
rm:是否删除普通空文件 "kong.txt"?y
[root@kongchao02 home]# tar -zxvf kc.tar.gz
home/kong.txt
home/chao.txt
[root@kongchao02 home]# ls
hello.txt kc kongchao kongchao2 myhome.zip
home kc.tar.gz kongchao1 myhome.tar.gz
[root@kongchao02 home]# ls home/
chao.txt kong.txt
[root@kongchao02 home]#
Example 4 : Extract myhome.tar.gz to the /opt/tmp2 directory
mkdir /opt/tmp2
tar -zxvf /home/myhome.tar.gz -C /opt/tmp2
[root@kongchao02 home]# ls /opt
rh tmp VMwareTools-10.3.22-15902021.tar.gz
[root@kongchao02 home]# mkdir /opt/tmp2
[root@kongchao02 home]# tar -zxvf /home/myhome.tar.gz -C /opt/tmp2
.....
....
[root@kongchao02 home]# ls /opt/
rh tmp tmp2 VMwareTools-10.3.22-15902021.tar.gz
[root@kongchao02 home]# ls /opt/tmp2
home
[root@kongchao02 home]# ls /opt/tmp2/home
chao.txt kc kongchao kongchao2 myhome.zip
hello.txt kc.tar.gz kongchao1 kong.txt
[root@kongchao02 home]#
Group management and authority management (practice)
Basic introduction to linux groups
Every user in linux must belong to a group and cannot be independent of the group. In linux, each file has the concept of owner, group, and other groups
1. The owner
2. The group
3. Other groups
4. Change the group the user is in
Icon:
Whoever created a file belongs to whoever created it. The owner of the file can be changed. The group that the creator belongs to is all groups. Members of this group have certain permissions to the file. Other groups are called all groups. Members of the group also have certain permissions on this file.
Generally, the creator of the file, who created the file, is the owner of the file.
ls -ahl to check file owner
Command: ls -ahl
Example : view /home
[root@kongchao02 ~]# cd /home
[root@kongchao02 home]# ls -ahl
总用量 36K
drwxr-xr-x. 7 root root 4.0K 3月 4 22:29 .
dr-xr-xr-x. 18 root root 4.0K 3月 1 09:24 ..
-rw-r--r--. 1 root root 115 3月 4 22:33 hello.java
drwx------. 15 kongchao kongchao 4.0K 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4.0K 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4.0K 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4.0K 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4.0K 3月 3 21:27 text4
-rw-r--r--. 1 root root 115 3月 4 22:37 text.txt
[root@kongchao02 home]#
The blue ones are directories, and the green ones are common files (I set it to green here, it was originally
chown change file owner
Command: chown username filename (change the file owner to the secondary user)
Example: use root to create apple.txt, and then change the owner to kongchao
[root@kongchao02 ~]# cd /home
[root@kongchao02 home]# touch apple.txt
[root@kongchao02 home]# ll
总用量 28
-rw-r--r--. 1 root root 0 3月 5 21:19 apple.txt
-rw-r--r--. 1 root root 115 3月 4 22:33 hello.java
drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4
-rw-r--r--. 1 root root 115 3月 4 22:37 text.txt
[root@kongchao02 home]# chown kongchao apple.txt
[root@kongchao02 home]# ll
总用量 28
-rw-r--r--. 1 kongchao root 0 3月 5 21:19 apple.txt
-rw-r--r--. 1 root root 115 3月 4 22:33 hello.java
drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao
drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1
drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2
drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3
drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4
-rw-r--r--. 1 root root 115 3月 4 22:37 text.txt
[root@kongchao02 home]#
groupadd create group
Basic syntax: groupadd group name
Example: Create a group Animal, then create a user pig and put it in Animal
groupadd Animal
useradd -g Animal pig
[root@kongchao02 /]# groupadd Animal
[root@kongchao02 /]# useradd -g Animal pig
[root@kongchao02 /]# id pig
uid=1003(pig) gid=1003(Animal) 组=1003(Animal)
[root@kongchao02 /]#
ls -ahl to view the group where the file/directory is located
Basic command: ls -ahl
When a user creates a file, the group where the file belongs is the group the user belongs to
chgrp modifies the group where the file is located
Basic instructions: chgrp groupname filename
Example : first use the root user to create the file banana.txt to see which group the file belongs to, and then change the group where the file is located to the fruit group
groupadd fruit
touch banana.txt
chgrp fruit banana.txt
other groups
Except for the owner and the user of the file, other users of the system are other groups of the file
usermod change user's group
basic grammar
usermod -g new group name username
usermod -d directory name username Change the initial directory for user login
Special Note: Users need to have permission to enter the new directory before they can modify
Example : Modify the group of the apple user to friut
usermod -g friut apple