


This article brings you a basic and sufficient Linux command, which will cover various commands used in the series of blog building articles to facilitate query and learning. I hope it will be helpful to everyone.
File Owner (Owner)
When a user is created, Linux will create a The home directory, the path is /home/
Group
Each user has a user group, which is convenient for assigning permissions to a group of people when multiple people operate. When a user is created, a user group with the same name is automatically created.
If a user belongs to multiple groups at the same time, the user needs to switch between user groups to have the permissions of other user groups.
Others
Users who are neither the file owner nor a member of the group to which the file belongs are Others.
Super User (Root)
Root user is a special type of user who can access all files.
1. adduser to add user and passwd to change password
# 添加一个名为 git 的用户 adduser git # 设置 git 用户的密码 passed git
But because the created user has low permissions, sometimes we need to To elevate privileges, we can do this:
# 会打开 sudoers 配置文件 sudo visudo
Note that you are also editing the sudoers configuration file. Using this command will be safer than using sudo vim /etc/ sudoers. In addition to verifying the syntax, it will also Lock files during multi-user editing.
After opening the sudoers configuration file, we add this line of configuration:
# Allow git to run any commands anywhere git ALL=(ALL:ALL) ALL
Briefly explain this sentence git ALL=(ALL:ALL) ALL:
git represents the rules Applied user name
The first ALL indicates that the rule applies to all hosts
The second ALL indicates that the rule applies to all users
The third ALL indicates that the rule applies to all groups
The fourth ALL indicates that the rule applies to all commands
After we save and exit, the git user will obtain root permissions.
2. ls lists files and directories
ls lists files and directories
[root@iZ2ze learn-typescript.git]# ls branches config description HEAD hooks index info objects refs
ls -la by- a displays all files and directories (including hidden) and -l displays a detailed list:
[root@iZ2ze learn-typescript.git]# ls -la 总用量 20 drwxrwxr-x 7 git git 132 12月 15 12:33 . drwx------ 3 git git 127 12月 15 14:51 .. drwxrwxr-x 2 git git 6 12月 15 12:21 branches -rw-rw-r-- 1 git git 66 12月 15 12:21 config -rw-rw-r-- 1 git git 73 12月 15 12:21 description -rw-rw-r-- 1 git git 23 12月 15 12:21 HEAD drwxrwxr-x 2 git git 4096 12月 15 13:10 hooks -rw-rw-r-- 1 git git 217 12月 15 12:33 index drwxrwxr-x 2 git git 21 12月 15 12:21 info drwxrwxr-x 10 git git 90 12月 15 12:33 objects drwxrwxr-x 4 git git 31 12月 15 12:21 refs
Each line has 7 columns. We use branches as an example to explain the meaning of each column:
Focus on the content of column 1, taking drwxrwxr-x as an example. There are 10 digits in total. The first digit represents the file type, where - represents an ordinary file and d represents a directory file.
The 2nd to 4th digits represent owner permissions, where r represents read permissions, w represents write permissions, x represents executable permissions, - represents no permissions, and the 2nd to 5th digits are rwx, which represents all It can be read, written and executed.
The 5th to 7th digits represent group user permissions, here they are also rwx.
The 8th to 10th bits indicate other user permissions. Here is r-x, which indicates readable and executable permissions but no write permissions.
One more thing to add here:
The default permissions for a root user to create a folder are rwxr-xr-x:
[root@iZ2ze www]# mkdir test [root@iZ2ze www]# ls -l drwxr-xr-x 2 root root 6 12月 17 23:53 test
and the default permissions for a file to be created are rw- r--r--, note that creating a file will remove the x permission by default:
[root@iZ2ze www]# touch index.html [root@iZ2ze www]# ls -l -rw-r--r-- 1 root root 0 12月 17 23:54 index.html
This is why we sometimes need to add execution permissions after creating the file.
3. chown changes the file owner, and you can also change the file group at the same time
chown (change owner) Syntax:
# -R:递归更改文件属组 chown [–R] 属主名 文件名 chown [-R] 属主名:属组名 文件名
Change the owner of index.html to git:
[root@iZ2ze www]# chown git index.html [root@iZ2ze www]# ls - -rw-r--r-- 1 git root 0 12月 17 23:54 index.html
Change the owner and group of index.html to git:
[root@iZ2ze www]# chown git:git index.html [root@iZ2ze www]# ls -l -rw-r--r-- 1 git git 0 12月 17 23:54 index.html
4. chmod changes file permissions
In addition to using r w x, permissions can also be expressed as numbers. The corresponding relationship between arrays and letters is:
r:4
w:2
x:1
All such correspondences are mainly for the convenience of derivation. For example, if we want a file to be readable and writable, then we can easily set the permission to 6 (4 2). Similarly, if we know that a permission is 3, we can also deduce The exit permission is writable and executable, because only 2 1 can be equal to 3.
Let’s take a look at the specific syntax of chmod (change mode):
# -R:递归更改文件属组 chmod [-R] xyz 文件或目录
xyz represents the permissions of Owner, Group, and Others respectively. If we set the permissions of a file like this:
chomd 750 index.html
We can know that the Owner's permission is 7, which means it can read, write and execute, the Group's permission is 5, which means it can read and execute, and the Others' permission is 0, which means it cannot read, write and execute. The corresponding letters are: rwxr-x---.
In addition to this numerical method, there is also a way to change permissions using symbolic types:
在这种方式里,我们将三种身份 Owner、Group、Others,分别简写为 u(User)、g、o,用 a 表示所有身份,再使用 + - = 表示加入、去除、设定一个权限,r w x 则继续表示读,写,执行权限,举个例子:
chomd u+x,g-x,o-x index.html
意思就是 Owner 加上执行权限,Group 和 Others 去除执行权限。
当然我们也可以直接设定权限
chmod u=rwx,g=rx,o=r index.html
此时文件的权限就相当于 -rwxr-xr--。
此外,我们还可以省略不写 ugoa 这类身份内容,直接写:
chmod +x index.html
此时相当于使用了 a,会给所有身份添加执行权限。
5. su 切换身份
# 切换为 git 用户 su git
6. whoami 显示用户名
# whoami root
7. pwd 显示当前目录
[git@iZ2ze www]$ pwd /home/www
8. cd 切换工作目录
# 进入 /home/www/ cd /home/www # 进入自己的主目录 cd ~ # 进入当前目录的上上两层 : cd ../..
10. mkdir 创建目录
mkdir 创建目录:
mkdir new_folder
mkdir -p 递归创建目录:
mkdir -p one/two/three
11. touch 创建文件
用于修改文件或者目录的时间属性,当文件不存在,系统会创建空白文件
touch new_file
12. echo 打印输出
echo 是 Shell 命令,用于打印输出:
# 显示转义字符 echo "\"test content\""
创建或覆盖文件内容为 "test content":
echo "test content" > index.html
如果是想追加内容,就用 >> :
[root@iZ2ze www]# echo "test content" > index.html [root@iZ2ze www]# cat index.html test content [root@iZ2ze www]# echo "test content" >> index.html [root@iZ2ze www]# cat index.html test content test content
13. cat 连接文件并打印输出
查看文件内容:
cat ~/.ssh/id_rsa.pub
清空 index.html 内容:
cat /dev/null > index.html
把 index.html 的内容写入 second.html:
cat index.html > second.html
把 index.html 的内容追加写入 second.html:
cat index.html >> second.html
把 index.html 和 second.html 追加写入 third.html:
cat index.html second.html >> third.html
14. cp 复制文件或目录
将目录 website/ 下的所有文件复制到新目录 static 下:
# -r:若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件。 cp –r website/ static
15. mv 移动并重命名
文件改名:
mv index.html index2.html
隐藏文件:
# 文件名上加上 . mv index.html .index.html
移动文件:
# 仅仅移动 mv /home/www/index.html /home/static/ # 移动又重命名 mv /home/www/index.html /home/static/index2.html
批量移动:
mv /home/www/website/* /home/www/static
16. rm 删除一个文件或者目录
# 系统会询问 rm file # -f 表示直接删除 # -r 表示目录下的所有文件删除 # 删除当前目录下的所有文件及目录 rm -r * # 跑路 rm -rf /*
17. vi/vim
Linux 内建 vi 文书编辑器,Vim 是从 vi 发展出来的一个文本编辑器。
基本上 vi/vim 共分为三种模式,分别是命令模式(Command mode),输入模式(Insert mode)和底线命令模式(Last line mode)。我们边操作边介绍这三种模式:
我们执行 vim index.html,如果没有该文件,则会创建文件:
vim index.html
此时是命令模式,在命令模式下,输入的任何字符都会被视为命令,接下来几个常用的命令:
i 切换到输入模式。
x 删除当前光标所在处的字符。
: 切换到底线命令模式。
我们按下 i,便会进入输入模式
输入模式下,左下角有 -- INSERT -- 标志:
此时我们可以进行各种输入,当输入完毕后,按下 ESC 回到命令模式
此时左下角的 INSERT已经消失不见了,如果我们要保存退出,我们先输入 : ,进入底线命令模式
在底线命令模式中,常见的命令有
w 保存文件
q 退出程序
我们输入 wq,表示保存并退出,此时我们就会发现并创建了一个 HTML 文件。
18. ssh 远程连接工具
注意 ssh 监听是 22 端口。
其基本语法为:
ssh [OPTIONS] [-p PORT] [USER@]HOSTNAME [COMMAND]
监听端口示例:
ssh -p 300 git@8.8.8.8
打开调试模式:
# -v 冗详模式,打印关于运行情况的调试信息 ssh -v git@8.8.8.8
相关推荐:《Linux视频教程》
The above is the detailed content of Organize a list of commonly used Linux commands (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
