Linux learning record

Open opportunities to start many programs.

  • Windows is called "service".
  • It's called a "daemon" in Linux.
sync # 将数据由内存同步到硬盘中。
shutdown # 关机指令

shutdown -r#重启
shutdown -h#延时关机

Directory Structure

[root@iZ2zebcqegh8n2n17381wpZ ~]# ls /
bin  		#bin是Binary的缩写, 这个目录存放着最经常使用的命令
dev  		#dev是Device(设备)的缩写, 存放的是Linux的外部设备
home  		#用户的主目录,在Linux中,每个用户都有一个自己的目录   
media  		#linux系统会自动识别一些设备,例如U盘、光驱等等
opt   		#这是给主机额外安装软件所摆放的目录
root  		#该目录为系统管理员,也称作超级权限者的用户主目录
sbin  		#系统管理员使用的系统管理程序
sys  		#这是linux2.6内核的一个很大的变化。该目录下安装了2.6内核中新出现的一个文件系统sysfs 
usr  		#用户的很多应用程序和文件都放在这个目录下
boot  		#这里存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件
etc   		#这个目录用来存放所有的系统管理所需要的配置文件和子目录
lib   		#这个目录里存放着系统最基本的动态连接共享库
lost+found  #这个目录一般情况下是空的,当系统非法关机后,这里就存放了一些文件 
mnt    		#系统提供该目录是为了让用户临时挂载别的文件系统的
proc  		#这个目录是一个虚拟的目录,它是系统内存的映射
run   		#是一个临时文件系统,存储系统启动以来的信息。
srv   		#该目录存放一些服务启动之后需要提取的数据
tmp  		#这个目录是用来存放一些临时文件的。用完即丢的文件,可以放在这个目录下,安装包
var  		#这个目录中存放着在不断扩充着的东西,我们习惯将那些经常被修改的目录放在这个目录下。包括各种日志				文件。

Commonly used basic commands

1. Catalog management

  • Absolute path: start from the root directory to the specified path

  • Relative path: start from the current directory to the specified path

  1. ls command
ls		#列出当前路径的文件
ls -a	#所有文件,包括隐藏文件
ls -l	#显示文件属性,不包括隐藏文件
ls -al	#参数可组合使用
  1. cd command
cd /usr/bin/ 	#绝对路径跳转
cd bin/ 		#相对路径跳转
cd ..     		#返回上一层路径
  1. pwd command
pwd  #显示当前路径
  1. mkdir create directory
  2. rmdir delete directories: only empty directories can be deleted, the -p parameter deletes recursively
  3. cp copy command: cp [file] [directory path] —If the file is duplicated, choose to overwrite (y) or give up (n)
  4. rm remove command
rm -f		#强制删除
rm -r		#递归删除目录
rm -i		#互动删除,询问是否删除
=================================
rm -rf /*	#删库跑路
=================================
  1. mv move command or rename file
mv 文件 目录
mv 文件名 文件新名字
mv -f	#强制移动
mv -u	#替换更新

2. Basic attributes

Linux system is a typical multi-user system. Different users are in different positions and have different permissions. In order to protect the security of the system, the Linux system makes different provisions for different users' access to the same file (including directory files).

ls -l  或  ll
-   rwx   r-x   r-x 1 root root 964600 Aug 8 2019 bash
  1. The first character indicates the file type

    • [D] is the directory
    • 【-】For file
    • 【L】Connect the document
    • [B] Interface devices available for storage in the device file
    • [C] The serial port device in the device file
  2. The second, third, and fourth characters are the owner authority [file owner]

    • [R] Readable
    • 【W】Writable
    • [X] executable
    • 【-】Inoperable
  3. The fifth and sixth characters are group permissions [users in the same group as the owner]

  4. The eighty and ninetieth characters are [other users]

chgrp [-R] 属组名 文件名			#更改文件的属组属性,-R为递归操作
=============================================================
chown [–R] 属主名 文件名			#更改文件属主属性
chown [-R] 属主名:属组名 文件名	  #同时更改
=============================================================
chmod #更改文件9个属性
r:4   w:2   x:1
rwx  7
rw-  6
-------------------------------
chmod 777 文件

3. File content view

  1. cat: the first line starts to display the contents of the file
  2. tac: the last line starts to display
  3. nl: When displaying, output the line number along the way
  4. more: display the content of the file page by page, with the rest of the content [Space means page turning, enter means looking down one line]
  5. less: Display file content page by page [page down by space, pageDown, pageUp keys represent page turning! 】【Quit the q command】【Search string/character to be queried for downward query, upward query use? The string to be queried, n continues to search for the next one, and N is for search!
  6. head: head just look at the first few lines and use the -n parameter to control the display of a few lines
  7. tail: just look at a few lines of the tail -n parameter to look at a few lines
  8. touch: Create file
  9. echo: input a string, or input into a file
  10. ln: Create a hard link [file modification, hard link is not modified, equivalent to backup]
  11. ln -s: Create a soft link [consistent with the file, equivalent to a shortcut]

vim

  1. Command mode:

    • 【I】Switch to input mode to input characters
    • [X] Delete the character at the current cursor
    • 【:】Switch to bottom line command mode
  2. Input mode:

    • [Character and SHIFT] Input characters
    • 【Enter】New line
    • [Backsace] Delete the character before the cursor
    • 【Delete】Delete a character after the cursor
    • 【Direction keys】Move the cursor in the text
    • [Home/End] Move the cursor to the beginning/end of the line
    • 【PageDown/Up】Page up/down
    • [Insert] Switch the cursor to input/replace mode, the cursor will become a vertical line/underline
    • 【Esc】Exit input mode and switch to command mode
  3. Bottom line command:

    • 【W】Save file
    • [Q] Exit the program
  4. Other buttons

    • 【+/-】Move the cursor to the next/previous line of non-space characters
    • 【Number <space>】Move the cursor horizontally
    • 【Number<Enter>】Move the cursor down
    • [0/Home] Move to the front character of this line
    • [$/End] Move to the last character of this line
    • [G] Move to the last line of this file
    • 【NG】n is a number. Move to the nth line of this file
    • [Gg] Move to the first line of this file, equivalent to 1G

    • [/Word] Look for a character string named word under the cursor
    • 【? word] Look for a character string named word above the cursor
    • [N] This n is an English button. Represents the action of repeating the previous search
    • [N] This N is the English button. Contrary to n, perform the previous search action for "reverse"

    • [U] Restore the previous action

    • [Set nu] Display the line number, after setting, the line number of the line will be displayed in the prefix of each line
    • [Set nonu] Contrary to set nu, it is the cancel line number

4. Account Management

  1. User Management
1.useradd 参数  用户名
-m  # 自动创建这个用户的主目录 /home/wdd
-G  # 给用户分配组 		
2. userdel -r wdd #	删除用户的时候将他的目录页一并删掉!
3. usermod -d	  #修改用户
4. 【root----username】su sername  	  #切换用户
   【username--- root】sudo su
5.【root】 passwd username:#修改密码
		  new password:
		  re password:
  【username】passwd
			(current) UNIX password: 
			new password: # 密码不能太过于简单!
			re password:
6. 	passwd -l wdd # 锁定之后这个用户就不能登录了!
	passwd -d wdd # 没有密码也不能登录!
  1. User group management
1. groupadd wdd -g 345		#创建组wdd,id为345,没指定自加一
2. groupdel wdd 			#删除组
3. groupmod -g 666 -n wer wdd#修改wdd组的名字和id
4. 	# 登录当前用户 
	$ newgrp root 	#切换用户组
5. /etc/passwd
	#用户名:口令(登录密码,我们不可见):用户标识号:组标识号:注释性描述:主目录:登录Shell=
	#这个文件中的每一行都代表这一个用户,我们可以从这里看出这个用户的主目录在那里,可以看到属于哪一个组!
6. /etc/shadow #真正的加密后的用户口令字
7. /etc/group #	用户组的所有信息

5. Disk Management

1. df -h		#列出文件系统整体的磁盘使用量
2. du -a	
   du -sm /*	#检查磁盘空间使用量
3. mount /dev/wdd /mnt/wdd		#外部设备/dev的wdd挂载到/mnt的wdd
4. umount -f [挂载位置] 		  #强制卸载

6. Process Management

Everything in Linux is a file

  • File: read and write execution------------view, create, delete, move, copy, edit
  • Permission ---------------User, user group
  • System--------------disk, process
  1. Each program has its own process, and each process has an id number
  2. Every process has a parent process
  3. Process has two ways of existence: foreground running and background running
  4. Services run in the background, and basic programs run in the foreground
1. ps -aux|grep mysql #查看所有的进程
	#【-a】 显示当前终端运行的所有的进程信息(当前的进程一个)
	#【-u】 以用户的信息显示进程
	#【-x】 显示后台运行进程的参数!
	#【|】 管道符
	#【grep】查找文件中符合条件的字符串
2. ps -ef|grep mysql #查看父进程
3. pstree -pu	#显示进程树
	#【-p】父id
	#【-u】用户组
4. kill -9 进程的id  #结束进程 
5. nohup  #后台执行程序

Installation Environment

  • rpm
  • unzip
  • Yum online installation

1. JDK

#检测当前系统是否存在java环境
java -version
-------------------------------
#检测JDK版本信息
rpm -qa|grep jdk 
-------------------------------
#卸载JDK
rpm -e --nodeps jdk_
-------------------------------
#安装jdk
rpm -ivh rpm包
-------------------------------
#配置环境变量
vim /etc/profile
JAVA_HOME=/usr/java/jdk1.8.0_221-amd64
CLASSPATH=%JAVA_HOME%/lib;%JAVA_HOME%/jre/lib
PATH=$PATH:$JAVA_HOME
export PATH CLASSPATH JAVA_HOME
-------------------------------
#让这个配置文件生效
source /etc/profile
# 开启防火墙端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
#重启防火墙
systemctl restart firewalld.service
#查看端口开启
firewall-cmd --list-ports

2. Tomcat

#解压文件
tar -zxvf apache-tomcat-9.0.22.tar.gz
#运行测试
./startup.sh
./shotdown.sh
# 查看firewall服务状态
systemctl status firewalld
# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop
# 查看防火墙规则
firewall-cmd --list-all   # 查看全部信息
firewall-cmd --list-ports  # 只看端口信息
# 开启端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
	#【--zone】作用域
	#【--add-port=80/tcp】添加端口,格式为:端口/通讯协议
	#【--permanent】永久生效,没有此参数重启后失效
# 重启
systemctl restart firewalld.service

3. Docker

#检测ContOS版本
cat /etc/redhat-release
#安装环境
yum -y install gcc 
yum -y install gcc-c++ 
	#【-y】所有的提示都为 y
#安装Docker
yum -y docker

4. Rides

1. sudo yum install redis#安装Redis
2. cp /etc/redis.conf /usr/bin/myconf #将配置文件复制到自己配置文件地方
3. vim redis.conf 	#编辑配置文件
	bind 0.0.0.0	#允许远程连接
	daemonize yes	#默认后台运行
4. redis-server myconf/redis.conf#以自己的配置文件启动
5.	redis-cli 	#redis 客户端
	shutdown	#关闭redis进程
	exit	#退出cli
6. ps -ef|grep redis	#查看关于redis的进程

Guess you like

Origin blog.csdn.net/qq_38473355/article/details/108684916