Linux basic operation and user and user group management

View system configuration and use

View CPU

lscpu   #显示cpu架构信息

cat /proc/cpuinfo   #查看CPU详细信息

View memory
View /proc/meminfo or use the free command. The free command is the information obtained from meminfo. In general, use free to get the information we want to know:

free -m

View hard drive

lsblk  #blk是block的缩写。列出块设备

df -h  #查看硬盘使用情况

Extension: mount the cloud disk to mount the
cloud server to mount the /dev/vdb1 disk
(the mount operation in this mounting tutorial requires the specified mount:)

mount /dev/vdb1  /mnt 	#挂载

umount  /mnt  			#卸载

View the running process of the system:

top   #可以持续的监视进程的信息
top -d 1 -n 100 #延迟1秒,打印100次

ps -aux|grep work #
ps -ef 

netstat -anp |grep 3306 #查看端口使用情况 

Under the top command, enter u, and then enter the corresponding user name, you can view the corresponding user process.

Reference:
https://www.cnblogs.com/alwu007/p/6024631.html
https://blog.csdn.net/timchen525/article/details/76364706

Find files

Find by name find -name

find -name php.ini

Search by name ignore case find -iname

find -iname php.ini

Fuzzy search

find -iname "*.log"

Find -type according to the type of file:
type parameter: f ordinary file l symbolic connection d directory c character device b block device s socket p Fifo

find -type f -name "*.log"

Find -user according to the user

find -user root

Query find -perm according to permissions

find -perm 755 -name "*.log"

Query by file time:
access time (-atime/day, -amin/minute): user's last access time.
Modification time (-mtime/day, -mmin/minute): the last modification time of the file.
Change time (-ctime/day, -cmin/minute): the last modification time of file data elements (such as permissions, etc.)

//查询近两天访问的文件
find  -atime -2 

View file status stat (including access, add, and modify time)
details

stat php.ini

Basic Linux operation

1. Basic operation
ls---------------View files in the directory
cd------------- Switch directories (for example: cd-return to the previous directory)
pwd------------View the current directory
mkdir --------- Create an empty directory
touch ----------Generate an empty file or change the time of the file
cp -------------- copy files or directories
mv ------------- move files or directories, rename files or directories
rm ------- -------Delete files or directories (the legendary "delete library and run away" rm -f force deletion, without any prompt meaning) (rm -r deletes the directory and the files below one by one)
cat - ----------- View file content
file/stat--------- View file type or file attribute information
. ---------------- Indicates the current directory
... --------------Indicates the upper level directory (parent directory) of the current directory
~ ---------------Indicates the user's home directory Absolute pathname

2. Write files

    > 是覆盖模式,>> 是追加模式
例如:
echo "hello world" >> log.txt    //把左边的输出放到右边文件的尾部

3. VI Editor

(vi 是 “Visual interface” 的简称,它可以执行输出、删除、查找、替换、块操作等众多文本操作,vi可以看做Windows下的记事本)
1.普通模式
	G用于直接跳转到文件尾
	ZZ用于存盘退出Vi
	ZQ用于不存盘退出Vi
	/和?用于查找字符串
	n继续查找下一个
	yy复制一行
	p粘帖在下一行,P粘贴在前一行
	dd删除一行文本
	x删除光标所在的字符
	u取消上一次编辑操作(undo)
2.插入模式
	在 Normal 模式下输入插入命令 i、 a 、 o进入insert模式。用户输入的任何字符都被vim当做文件内容保存起来,并将其显示在屏幕上。
	在文本输入过程中,若想回到Normal模式下,按 Esc 键即可。
3.命令行模式
	Normal 模式下,用户按冒号 :即可进入 Command 模式,此时 vim 会在显示窗口的最后一行 (屏幕的最后一行) 显示一个 “:” 作为 Command 模式的提示符,等待输入命令。
	:w 保存当前编辑文件,但并不退出
	:w newfile 存为另外一个名为 “newfile” 的文件
	:wq 用于存盘退出Vi
	:q! 用于不存盘退出Vi
	:q用于直接退出Vi (未做修改)

 4.修改文件内容例子:   	
    打开:    vi index.html
        编辑文件:i 、a、o(进入insert)
        退出,保存:Esc, :+w+q, 回车保存

4. Pipeline command |: send the previous result to the next command

例如:  ls -lh | cat  (查看当前目录下的文件及属性, move可以查看多页)

[root@VM_0_10_centos www]# ls -lh | move
total 1.1G
drwxr-xr-x 4 root root 4.0K Jul 5 09:42 backup

-rwxr-xr-x 1 www www 195 Oct 23 09:04 index.html

-rw-r–r-- 1 root root 8 Oct 23 09:33 qingshu.txt

drwxr-xr-x 2 root root 4.0K Jul 5 10:39 Recycle_bin

drwxr-xr-x 13 root root 4.0K Oct 8 14:31 server

-rw-r–r-- 1 root root 1.1G Jul 5 09:40 swap

drwxr-xr-x 2 root root 4.0K Aug 1 11:05 webSocket

drwxrwxrwx 3 root root 4.0K Oct 23 08:52 wwwlogs

drwxr-xr-x 5 root root 4.0K Oct 8 11:48 wwwroot

6. Linux basic directory explanation:

bin stores binary executable files (ls, cat, mkdir, etc.)
boot stores various files
used when the system is booted dev is used to store device files
etc. stores system configuration files
home stores all user files in the root directory
lib store and file system The shared libraries and kernel modules required by the program to run in
mnt The installation point of the system administrator to install the temporary file system
opt The location where additional optional application packages are placed
proc virtual file system, which stores the current memory mapping
root super user directory
sbin stores binary executable files, only root can access
tmp used to store various temporary files
usr used to store system applications, the more important directory /usr/local local administrator software installation directory
var is used to store data that needs to be changed during operation document

User Management

Linux users can perform daily management and maintenance on the operating system. The related configuration files are as follows:

/etc/passwd Save user information
/etc/shdaow Save user password (save in encrypted form)
/etc/group Save group information
/etc/login.defs User attribute restrictions, password expiration time, maximum password length, etc.
/etc/default /useradd Display or change the default useradd configuration file

If you need to create a new user, you can use the command useradd, execute the command useradd test1 to create the test1 user, and a group test1 with the same name will be created at the same time. By default, the user belongs to the main group test1.

View all users:
Method 1:
Use any file operation command like cat, more, less, etc. to print the list of users created on the Linux system.
/etc/passwd is a text file that contains the information of each user necessary to log in to the Linux system. It saves the useful information of the user, such as user name, password, user ID, group ID, user ID information, user's home directory and Shell.

Method 2:
Execute the command

getent passwd  //getent 命令显示 Name Service Switch 库支持的数据库中的条目。这些库的配置文件为 /etc/nsswitch.conf

compgen -u   //compgen 是 bash 的内置命令,它将显示所有可用的命令,别名和函数

authority management

Linux user and authority management

Others
do not command all over the world search for linux, and I'll give you a piece to finish

Guess you like

Origin blog.csdn.net/qq_39004843/article/details/105071011