A total of 3215 characters, expected to take 9 minutes to complete reading.
Knowledge of Linux
Linux, full name GNU/Linux, is a free-to-use and free-to-spread UNIX-like operating system. Its kernel was first released on October 5, 1991 by Linus Bennard Torvalds. Inspired by Minix and Unix ideas, it is a POSIX-based multi-user, multi-tasking, multi-threaded and multi-CPU operating system. It runs the major Unix tools, software, applications, and network protocols. It supports both 32-bit and 64-bit hardware. Linux inherits the design idea of Unix taking network as the core, and it is a multi-user network operating system with stable performance. There are hundreds of different distributions of Linux, such as community-based debian, archlinux, and commercial-based Red Hat Enterprise Linux, SUSE, Oracle Linux, etc.
Main Catalogue
Linux system is a multi-user operating system, only a root directory/, no drive letter concept.
-
/
The root directory, generally only the directory is stored under the root directory. Entering/home in the terminal is actually telling the computer to start with/(I .e. the root directory) and then enter the home directory;
-
/bin,/user/bin
Directories of executable binary files, such as commonly used commands: ls,tar,mv,cat, etc;
-
/boot
Place some files used when the Linux system starts, such as Linux kernel file:/boot/vmlinuz, system boot manager:/boot/grub;
-
/dev
Store the device files under the Linux system and access a file under the directory, which is equivalent to accessing a device. The commonly used optical drive is mount /dev/cdrom /mnt;
-
/etc/
It is not recommended to store executable files in this directory. Important configuration files are:/etc/initab etc/fstab etc/init.d /etc/xll /etc/sysconfig/xinetd.d;
-
passwd
Store the user's information, consisting of 6 semicolon
用户名: 密码:UID:GID: 用户全名: 家目录: 登录命令 密码:x 表示加密的密码 密码存放在 /etc/shadow UID:用户标识 普通用户从 1000 开始 用户权限由 UID 决定 root 用户为 0 如果把某一用户的 UID 改成 0 那么他具有 root 权限 GID:组标识
-
shadow
存放密码信息 是 /etc/passwd 的影子文件
用户名: 加密密码: 最后一次更改密码时间: 天数
-
group
Store group information
组名: 密码:GID: 包含的用户
-
gshadow
is a shadow file of/etc/group
组名: 密码: 管理者: 组群成员
-
-
/home
The default user's home directory. When a user account is added, the user's home directory is stored in this directory: ~ indicates the home directory of the current directory, and ~ edu indicates the home directory used for edu;
-
/lib,/user/lib,/usr/local/lib
The directory of the function library used by the system. During the execution of the program, some additional parameters need to be called;
-
/lost fount
When a system exception generates an error, some missing fragments will be placed in this directory;
-
/mnt,/media
The default mount point of the disc. Usually, the disc is mounted under/mnt/cdrom, but not necessarily. You can select any location to mount the disc;
-
/opt
Directory for additional installation software;
-
/proc
The data in this directory are all in memory, such as the system core external equipment and network status. Since the data are all stored in memory, it does not occupy disk space. The more important files are:/proc/cpuinfo,/proc/interrupts,/proc/dma,/proc/ioports,/proc/net/*, etc;
-
/root
The home directory of the system administrator root.
-
/usr/share/doc
Contains a complete series of software documentation
Home Directory
-
~/.ssh/
Directory where ssh information is stored
-
config
Information for configuring ssh
Configure Alias
Host <别名> HostName
User <用户> Port <端口> -
known_hosts
Saves recorded server information
-
authorized_keys
Authenticated public key information
-
id_rsa
Generated private key information
Generating private and public keys on the connection side
Copy the public key to the server
You can log in to the server without confidentiality.
-
id_rsa.pub
Generated public key information
Give the public key to the server
You can log in to the server without confidentiality.
-
-
~/.bash
-
~/.bash_history
Command History File
All previously executed commands will be saved here
-
~/.bashrc
The bash command that is executed every time you log in
-
Environment Variables
-
Viewing Environment Variables: env
-
Setting System Environment Variables
export name="值" #(注意:这只是临时设置环境变量,在下次登录 shell 时就失效了)# 永久方法:# 在 /etc/profile.d 目录下创建 sh 文件 # 在每次登录 shell 时都会执行 /etc/profile.d 文件夹里面的所有 sh 文件
Command
Command format:
command [-options] parameter
command -lh
andcommand -l -h
The effect is the sameQuery Help:
command --help
man command
Shortcut Keys:
Tab auto-completion
↑ / ↓ Quick Switch History Command
Ctrl C to exit the selection and cancel the current command
Command | English | Role | Parameters |
---|---|---|---|
man | manual | Find Help for a Command | |
ls [Find Content] | list | View the contents of the current folder | -a View all files including hidden files -l List file details -h better display file size Wildcards: ls 1* ls 1?1.txt ls [A-Z]* |
tree [directory name] | tree | Tree view showing directory structure | -a Show all files (hide files) -d Show only directories |
pwd | Print Work Directory | View Current Folder | |
cd [directory name] | Change Directory | Switch Folder | cd Switch to user directory cd ~ Switch to user directory cd . Keep current directory cd .. Return to the previous directorycd - Returns the last directory |
touch | touch | Create File | Create a file or modify the file modification time information. |
mkdir | Make Directory | Create Folder | -p Create a recursive directorymkdir -p a/b/c/d |
cp [source file] [target file] | copy | Copy Files | -Prompt before overwriting files -f Force overwrite file -r copy the folder and its contents |
mv [original file] [target file] | move | Move File/Rename File | -Prompt before overwriting files -f Force overwrite file |
rm | remove | Delete the specified file | -f Force delete files -r Delete folders and contents -d delete empty directories -I prompt before deleting |
find [path] | Find | Find Files | -name "*.py" Specifies the file name of the lookup |
cat [file name] | concatenate | View File/Modify File/File Append | -B non-blank line number (equivalentnl )-n Number all rows cat > 1.txt Write to file 1.txtcat 1.txt > 2.txt Overwrite content from 1 to 2 cat 1.txt >> 2.txt Append the contents of 1 to 2 cat < 1.txt 2.txt The content in 2 will be printed |
nl [file name] | Number of Line | View File (Number of lines displayed with non-blank lines) | |
more [file name] | more | Split-screen display of file contents | Space bar Next Enter to scroll one line B scroll backward one screen f scroll forward one screen Q Exit |
less [file name] | less | Split-screen display of file contents | |
grep [content] [filename] | Globally search a Regular Expression and Print | Search text content | -n number of rows to display -v display does not contain rows -I Ignore case |
echo [content] | echo | Output specified text | echo xxx > 1.txt Output to file echo xxx >> 1.txt Append to file |
clear | clear | Clear | |
shutdown | shutdown | Shutdown | -r Restart the computer -c Cancel Shutdown shutdown now Shut down immediately or after 1 minute |
reboot | reboot | Restart | |
ifconfig | network interfaces configuring | View/Configure Network Cards | |
ping [IP address] | ping | Test network connectivity | -I use the specified network card -c Specified number of times |
ssh User Name> @<地址: [path] | Secure Shell | ssh remote connection | -p Use specified port (default 22) |
scp [original file] [target file] | Secure Copy | Remote Copy File | -P Use specified port -r Transports all the contents of the directory |
ssh-keygen | Secure Shell Key Generate | Generate SSH key | |
ssh-copy-id User Name> @<地址: [path] | Secure Shell Copy Idification | Copy the public key to the server | -p Use specified port (default 22) |
su [user name] | Substitute User | Switch User | -After switching to the default working directory Switch to root superuser by default |
sudo | Substitute User Do | Execute commands with superuser | No need to re-enter password for 5 minutes |
chmod [ugoa][ /-/=][rwx] [file/directory] | Change Mode | Change file permissions | -R recursively modifies everything under the folder chmod +x file Add executable permissions to a file |
chgrp | Change Group | Modify the group to which a file belongs | -R recursively modifies the contents of all folders inside |
chown [: group name] | Change Owner | Modify File User | -R recursively modifies the contents of all folders inside |
groups [user name] | Groups | Querying a User's Group | cat /etc/group Can query all user groups |
groupadd | Group Add | Add User Group | |
groupdel | Group Delete | Delete a user group | |
useradd | User Add | New User | -m automatically creates a home directory -g [group] Specifies the user group |
userdel | User Delete | Delete User | -r automatically delete home directory |
usermod | User Modify | Modify user information | -g [group] Set user primary group -G [Group] Set User Attached Group -s [/bin/shell] Modify the user's login command |
passwd [user name] | Password | Set User Password | cat /etc/passwd \| grep < 用户 > Can query users |
id [user name] | Idification | Querying the UID and GID of a User | |
who | Who | The user currently logged on to the current computer | |
whoami | Who Am I | Displays the currently logged-in user name | |
which | Which | View the file location of the command | |
exit | Exit | Exit Terminal | |
date | Date | View the current system time | |
cal | Calender | View Calendar | -y View a year's calendar |
df | Disk Free | View disk information | -a View all information -h humanized display file size |
du [catalog] | Disk Usage | View directory usage information | -s shows total size -h humanized display file size |
ps [aux] | Process Status | View the status of a process | a Show all processes u Show Details x shows processes without terminals |
top | Top | Dynamic display and sorting of processes | |
kill | Kill | Kill a process. | -9 Forced Termination Procedure |
ln | Link | Create Link | -s Establish soft link without this parameter establishes hard link by default |
tar | Tape Archive | Packing/Unpacking | -c Generate archive files -x Unlock file files -v list progress -f Specifies the file name -j compressed by bzip2 -z Compressed by gzip -C Specifies the unzip directory tar -cvf xxx.tar xxx Package File tar -xvf xxx.tar Unpack files |
zip | Zip | Compression | -v list progress -r recursively compresses all contents under the folder -n [1~9] compression level -u append file to zip |
unzip | Unzip | Decompression | -d specifies the unzip folder -P specify password -l list the contents of the compressed package |
apt | Advanced Packaging Tool | Manage software packages | |
chattr | Lock and unlock read-only permissions root can not modify | chattr I /etc/resolv.conf chattr -i /etc/resolv.conf |
|
alias | alias | Define an alias for a command | alias rm ='rm -i' |
unalias | unalias | Unalias | unalias rm |
diff | Show files in different places | diff file.txt file1.txt You can also display folders in different places: diff -r / /home |
Users and Permissions
Super User
-
root
The account is a super user account. -
For system maintenance and management
-
Directly using Super User is not recommended
User Symbol
User | English | abbreviation |
---|---|---|
Owner | owner | u |
User Group | group | g |
Other Users | other | o |
All Users | all | a |
permission symbol
Permissions | English | Abbreviations | Digital code |
---|---|---|---|
Read | read | r | 4 |
Write | write | w | 2 |
Execution | excute | x | 1 |
No permission | – | 0 |
octal syntax | Permissions | Abbreviations |
---|---|---|
7 | Read and write execution | rwx |
6 | Read and write | rw- |
5 | Read Execution | r-x |
4 | Read Only | r- |
3 | Write Execution | -wx |
2 | Write Only | -w- |
1 | Execute only | -x |
0 | No permission | — |
File Type | File/Directory | Owner permissions | Group Permissions | Other User Permissions |
---|---|---|---|---|
General Documents | – | rw- | rw- | r- |
Catalog File | d | rwx | rwx | r-x |
Manage files | p | |||
Connection file | l | |||
Block Device File | B | |||
Character Device File | c | |||
socket file | s |
Commonly used software packages
Name | Role | |
---|---|---|
Samba | nas server remote hard disk | |
Transmission | Remote File Downloader | |
OpenStack | Cloud Platform | |
KVM | Virtual Machine | |
WebVirtMgr WebVirtCloud | Virtual machine management WEB | |
Rclone | It can mount the shared folder of the webdav protocol to the local hard disk of the computer. In addition, Rclone supports up to 40 common network sharing protocols such as HTTP, WebDav, FTP, SFTP, dlna, Amazon S3, Alibaba Cloud OSS, etc. | |
About Shell
Wildcard
Asterisk *
Use to match any character, including numbers, letters, and symbols. You can use an asterisk to specify any character that the application needs to find in the corresponding position of the character.
# 删除所有文件后缀为.bak 的文件
rm *.bak
Question mark?
Used to match a single arbitrary character.
# 列出所有任意一个字符开头,后面为 bc.txt 的文件
# 例如:abc.txt bbc.txt 1bc.txt
ls ?bc.txt
File Alias
# 给命令设置别名
# alias < 别名 >="< 原命令 >"
alias test="ls -l /"
# 取消别名
# unalias < 别名 >
unalias test
Piping
# 管道的符号为 |
[命令]|[命令]|[命令]
Redirect
# 输出重定向
# 将命令执行的输出保存在文件里 直接覆盖
[命令] > [文件]
ls /etc > 1.txt
# 追加重定向
# 追加来替代直接覆盖文件
ls /etc >> 1.txt
# 输入重定向
[命令] < [文件]
grep test < 1.txt
# 追加重定向
# 获取一段分隔符之间的内容
[命令] << [分隔符]
> [内容]
> [内容]
> [分隔符]
# 错误重定向
# 把命令发生的错误写到文件里
[命令] 2> [文件]
ls /nofile 2> 1.txt
ls /nofile 2>> 1.txt
# 同时实现输出和错误重定向
[命令] &> [文件]
write by dudu233