Linux development foundation (medium)
Disk
The peripheral hardware devices of Linux are all stored in the form of files, such as sad, sad1, etc. in the dev directory.
Classification of disk partitions
Two commonly used disk partition types:
- mbr
1. The operating system should be installed on the primary partition
2. 3. The extended partition occupies a primary partition只支持4个主分区
- gpt (win7 64 bit or later)
1. 2. Supports large hard drives over 3T
无限主分区
Our common one is windows gpt, where multiple systems can be installed, while Linux is mbr which only supports 4 partitions at most
Mount
Command to view the mounting status of all devices:
Isblk
orIsblk -f
! [Insert the picture description here](https://img-blog.csdnimg.cn/20200721233432289.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9NLmWN0GU=RubmN0ZGU4 ,size_16,color_FFFFFF,t_70
- Partition command
fdisk /dev/sdb 分区命令
开始对/sda分区
m显示命令列表p
显示磁盘n 新增分区
删除分区
w写入并退出分区同fdisk -l
- Format command
格式化磁盘
分区命令:mkfs -t ext4 /dev/sdb1
其中ext4是分区类型
- Mount
Mount: Associate a partition with a directory,
mount [device name] [mount directory]
For example: umount [device name] or [mount directory] For example: mount with the command line, so there is a permanent mount Realize mounting by modifying /etc/fstab . Execute after adding ** ** Effective immediatelymount /dev/sdb1 /newdisk
umount /dev/sdb1或者umount /newdisk
**重启后会失效**
mount - -a
Add new hard drive
We operate on a virtual machine. Actually, it is the same on a physical machine. If the hard disk space is insufficient in the future, the operation will be the same.
- First (external) add the hard drive, then restart
- View newly added hard drives
- Enter the dev directory, perform the partition operation and
start the partition and enter n, "Add partition, then select p, the partition type is the primary partition. Return to the year twice to default all the remaining space. Finally, enter w to write to the partition and exit. If you do not save, exit Enter q.
At this time, check the newly added disk, and the result is that the partition is successful
- Format the disk, type in the command
mkfs -t ext4 sdc1
, and display multiple completions- Create a new file as shown below and mount the partition, the new hard disk can be used
- But when the machine is restarted or shut down, there is no partition, so use permanent mount
- Enter /etc/fstab, add the record corresponding to the new partition and directory, and type
mount -a
- Detect
Network & Process
Network talk
ifconfig
View network information
Necessity of modifying ip (dhcp automatically assigned to static) : static ip is convenient for remote operation.
Use vim editor to view the /etc/sysconfig/network-scripts/ifcfg-ens33 file. Finally, service network restart can restart the network card service.
process
Basic command:
field information displayed by ps shell
PID---------------------- Process identification number
PPID--------------------父进程
TTY pointed to ---------------------Terminal number
TIME--------------------CPU eliminated by this process Time
CMD--------------------Command or process name being executed
- ps-aux
ps -a
: Display the所有
process information of the current terminal
ps -u
: to用户的格式
display the process information
ps -x
: display后台
the parameters of the process running,
ps -ef
display the parent process of the process
Under normal circumstances, the process and the pipeline | 还有 grep
do fuzzy query together
kill pid
Kill processkaill -9
Force kill process- **
killall
**Kill a series of processes
service
- Service (centos6)
standardized procedures registered in the system
have a convenient and unified management method (common methods)
service 服务名 start
service 服务名 stop
service 服务名 restart
service 服务名 reload
service 服务名 status
- How to view service **
/etc/init.d/服务名
** - Set self-starting
view service through chkconfig commandchkconfig -listlgrep xxx
chkconfig --level 5 服务名 on
- Run level under Linux'
Boot==》BIOS==>/boot==>init==>Runlevel==》Services corresponding to the runlevel
运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动
运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登
运行级别2:多用户状态(没有NFS (Network File System,网络文件系统) ),不支持网络
运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式
运行级别4:系统未使用,保留
运行级别5: X11控制台,登陆后进入图形GUI模式
运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动
netstat
View the network status of the system
netstat -an
Arrange the output in a certain order to
netstat -p
show which process is calling
netstat -anplgrep 8080
View the process occupying port 8080
Service changes in Centos7
- Systemqtl (centos7)
standardized procedures registered in the system
have convenient and unified management methods (common methods)
systemctl start服务名xxxx.service)
systemctl restart 服务名(xxxx.service)
systemctl stop服务名(xxxx.service)
systemctl reload服务名(xxxx.service)
systemctl status服务名(xxxx.service)
View service method /usr/lib/systemd/system
View service command
systemctl list-unit-files
systemctl --type service
Set auto-start through systemctl command
自启动
systemctl enable service_ name
不自启动
systemctl disable service_ name
disables the firewall
User and authority management
Users and groups
- User
Linux system is a multi-user and multi-task operating system. Any
user who wants to use system resources must first apply for an account from the system administrator, and then
enter the system as this account.
New user: set password: whether the user exists: switch user: check current user/login user: delete user: (incomplete), you also need to delete the files in the /home directory and the users in /etc/passwd are in /etc The mailbox file under the user group var/spool/mail under /group completely delete the user:
useradd 新用户名
passwd 用户名
id 用户名
su 切换用户名
whoami 和 who am |
userdel username
userdel -rf username
- If the new user is not grouped, he will create a group under his own name, so delete the user name under /etc/group
- User groups are
similar to roles, and the system can uniformly manage multiple users with common features.
New group: delete group: modify user's group: directly add _up group when adding user:
groupadd 组名
groupdel 组名
usermod - -g 用户组 用户名
useradd -g 用户组 用户名
- System related files users and groups of
users profiles: / etc / passwd
meaning of each line:用户名
:口令
:用户标识号
:组标识号
:注释性描述
:主目录
:登录Shell
password configuration file: / etc / shadow
the meaning of each line:登录名:加密口令:最后一-次修改时间:最小时间间隔:
maximum time interval: Warning time: no Activity time: Expiration time: flags
Group configuration file: /etc/group
Meaning of each line:组名:口令:组标识号:组内用户列表
Authority
- Affect the file
[r] stands for readable (read): can be read, view
[w] stands for writable (write): it can be modified, but it does not mean that the file can be deleted,删除一个文件的前提条件是对该文件所在的目录有写权限,才能删除该文件.
(emphasis)
[x] stands for executable (exequte) ): Can be executed by the system.
Act on the directory
[r] stands for readable (read): can be read, Is to view the contents of the directory
[w] stands for writable (write): can be modified, [x] stands for executable (execute): you can enter the directory,目录内创建+删除+重命名目录
没有执行权力,一切等于白讲
Bit 1: Represents **
文档类型
, common values are "d for folder", "- for file", "l for soft connection", "s for socket", etc.;
bit 2-4: indicates所有者
The permission status of the
document , the second digit indicates the read permission, and the values are r, -; the third digit indicates the write permission, w is writable,-is not writable, and the fourth digit indicates the execution permission. The values are x, -. Bits 5-7: indicates所有者同在一个组的用户
the permission status of and, the fifth bit indicates the status of the read permission, and the values are r, -; the sixth bit represents the status of the write permission, w represents writable,-represents unwritable, the seventh bit Indicates the execution authority, and the values are x and -.
Bit 8-10: indicates除了上面的前2部分的用户之外的其他用户的权限情况
**, bit 8 indicates read permission, and the values are r, -; bit 9 indicates write permission, w indicates writable,-indicates not writable, and 10 indicates execute In the case of permissions, the values are x and -.
In the distribution of permissions, all three parameters of rwx are combined, and the position order will not change. No corresponding permissions就用 – 代替
- . chmod
The first way: +,, = change permissions
u: owner g: all groups o: others a: everyone (the sum of u, g, o)
chmod u=wx,g=rx,o=x 文件目录名
chmod O+W 文件目录名
chmod a-X 文件目录名
The second method: change the authority through the number
r=4w=2 x=1 rwx=4+2+1=7
chmod u=rwx,g=rx,o=x 文件目录名
相当于chmod 751 文件目录名
- chown
chown newowner file 改变文件的所有者
chown newowner:newgroup file 改变用户的所有者和所有组
-R 如果是目录则使其下所有子文件或目录递归生效
- chgrp
chgrp newgroup file changes all groups of the file