Linux basic command

Ao Yin 2021-04-08 10:33:11
linux basic command

One 、 Command format

Linux The basic format of the command in is as follows :

 command [ Options ] [ Parameters ]

notes : Some special commands do not follow this format

Two 、 system information

2.1、 Get the current user

who am i

2.2、 Get the current directory


2.3、 obtain IP Information

ip a|address

2.4、 Connect to remote address

ping domain name |IP

3、 ... and 、 Directory command

3.1、 List the contents

ls [-aldtr] [ Directory name ]
# By default, the directory name lists the current directory
# -a: List all the files and directories
# -l: List file and directory details
# -d: List only the directory itself
# -t: Sort by creation time
# -r: In reverse order
ll [-aldtr] [ Directory name ] # ls -l Abbreviated form , And ls Use consistent

3.2、 Toggle directory

cd [ route ]
# When the directory name is missing , Switch to the current user's home Under the table of contents

Special directory path :

Symbol route
. Current directory
.. Superior directory
/ System root
~ Current user's home Catalog
- Return to the last Directory

3.3、 Create directory

mkdir [-mp] Directory name
# -m: Specify permissions
# -p: Create multi-level directory

3.4、 Delete directory

rmdir Directory name
# Only empty directories can be deleted
rm [-rf] Resource name # Delete resources ( Directory or file )
# -r: Recursive delete
# -f: Don't ask

3.5、 Copy resources

cp [-rp] Source resource path Target resource path
# -r: Recursive replication
# -p: Copy with attributes , Instead of using default properties

3.6、 Move / Rename resource

mv The source of resources [ The target path ][ New resource name ]
# If the target path is not written , That is to rename ; If the new resource name is not written , Mobile ; If you write both , Move and rename

Four 、 File command

4.1、 create a file

touch file name [ file name ] [ file name ] [ file name ]...

4.2、 Edit the file

vi | vim file name # Enter view mode
i | a | o # Enter edit mode
# i: Start editing at the current cursor ;a: After the current cursor ;o: Start a new line under the cursor ;
ESC # Launch editing mode
: # Enter the bottom line command mode
wq! # Save and exit
q! # Exit without saving
# In view mode , Press down ZZ( Twice capitalized z), Save and exit quickly
4.2.1、 Show / Hide line numbers

In bottom line command mode , Input set nu/nonu enter , You can show or hide line numbers

4.2.2、 Jump to a line

In bottom line command mode , Input to n enter , Can jump to n That's ok

4.2.3、 Find content

In view mode , Input /xxx You can find... In the file xxx Content , Press n Find the next one ; Press N Find the last one

5、 see file

5.1、 Check all
cat file name # Start with the first line to see the contents of the file , Show it all
tac file name # View the contents of the file from the last line , Show it all
nl file name # Start with the first line to see the contents of the file , Show it all , And display the line number
5.2、 View by page

similar cat , But it will be displayed page by page , More convenient for users to read page by page , And the most basic command is to press the blank key (space) The next page shows , Press b The key will go back (back) One page shows

more file name

Common operation command

  • Enter Down n That's ok , Need to define . The default is 1 That's ok
  • Ctrl+f Scroll down one screen
  • Space bar Scroll down one screen
  • Ctrl+b Scroll up one screen
  • b Scroll up one screen
  • = Output the line number of the current line
  • :f Output filename and line number of current line
  • v call vi Editor
  • ! command call Shell, And execute the command
  • q sign out more

And more similar ,less You can browse files at will , Support page turning and search , Supports page up and page down .

less file name

Common operation command

  • / character string : Search down " character string " The function of
  • ? character string : Search up " character string " The function of
  • n: Repeat the previous search ( And / or ? of )
  • N: Repeat the previous search in reverse ( And / or ? of )
  • b Page up
  • d Turn back half a page
  • h Show help screen
  • q sign out less command
  • u Scroll forward half a page
  • y Roll a line forward
  • Space bar Scroll one page
  • Enter key Roll a line
  • G Jump to the last line
  • [pagedown]: Page down
  • [pageup]: Page up
5.3、 View by line

head Command can be used to view the contents of the beginning of a file , There is a common parameter -n Used to display the number of rows , The default is 10, It shows 10 The content of the line .

head [-qvcn] file name
# -q: Hide filename ( Default )
# -v: Show filename
# -c: How many characters are displayed
# -n: How many lines are displayed


tail The command can be used to view the contents of a file , There is a common parameter -f Often used to look up log files that are changing .

tail -f filename Will be able to filename The last part of the file is shown on the screen , And keep refreshing , as long as filename Update to see the latest file content .

tail [-fqvcn] file name
# -f: Cyclic reading , Read out every time new content is added
# -q: Do not display processing information
# -v: Display processing information
# -c < number >: Number of characters read
# -n < number >: Number of rows read

5、 ... and 、 Pack command

Linux The commonly used compression package format in is :.tar.tar.gz.gz Of , But it also supports .zip and .rar Format .

5.1、tar type

5.1.1、 Compress
tar [-cvzf] Compressed file name Target resource name [-C Pathname ]
# -c or --create: New compressed file
# -v: Display during execution of instructions
# -z or --gzip or --ungzip: adopt gzip Instruction processing backup file .
# -f < Compressed file name > or --file=< Compressed file name >: Specify the compressed file . Be careful , This option must be at the end of the option

5.1.2、 decompression
tar [-xvzf] Compressed file name [-C Pathname ]
# -x or --extract or --get: Unzip the compressed file

5.1.3、 View compressed files
tar [-tvzf] Compressed file name
# -t or --list: List the contents of the compressed file .

5.2、zip type

Linux This is not supported by default zip, So you need to install zip and unzip Software .

The installation command is as follows :

yum -y install zip
yum -y install unzip

5.2.1、 Compress
zip [-qr] Compressed file name [ Target resources ] [ Target resources ] ...
# -q: Do not show instruction execution
# -r: Recursive processing , Process all files and subdirectories in the specified directory

5.2.2、 decompression
unzip [-lnv] Compressed file name
# -l: Display the files contained in the compressed file
# -n: When decompressing , Don't override the original file
# -v: Look at the contents of the compressed file , Do not decompress

5.2.3、gzip command

gzip Is a command that can be compressed or decompressed , After it compresses the file , The name will be followed by ".gz" Extension .

gzip [-drl] Resource name | Compressed file name
# -d: decompression
# -r: Recursive processing
# -l: List information about compressed files

6、 ... and 、 User command

Linux The system is a multi-user and multi task time-sharing operating system , Any user who wants to use system resources , You must first apply to the system administrator for an account , Then enter the system as this account .

On the one hand, the user's account can help the system administrator to track the users who use the system , And control their access to system resources ; On the other hand, it can help users organize files , And provide security protection for users .

Each user account has a unique user name and password .

After the user enters the correct user name and password at login , You can access the system and your home directory .

6.1、 Create user

useradd [-dgG] user name
# -d: Specify the user's home directory , If not specified , It's in /home Create a folder with the same user name as the home directory
# -g: Specifies the user's membership group
# -G: Specify the user's satellite group

6.2、 Set the password

passwd [-dlu] user name
# -d: Delete password
# -l: Lock account , Make it unavailable
# -u: Unlock the account , Make it available

6.3、 Switching users

su user name

explain :

[root@192 ~]# :root The user is in 192 Sign in , The current in the ~ Under the table of contents ,# On behalf of Super Administrator .

[silence@192 root]$ :silence The user is in 192 Sign in , The current in the root Under the table of contents ,$ On behalf of ordinary users .

6.4、 Modify the user

usermod [-degGlLuU] user name
# -d < Log in to the directory >: Modify the directory when the user logs in
# -e < Term of validity >: Modify the validity period of the account
# -f < Buffer days >: Modify how many days after the password expires to close the account
# -g < group >: Modify the user's group
# -G < group >: Modify the additional group to which the user belongs
# -l < Account name >: Change user account name
# -L: Lock user password , Invalidate password
# -u <uid>: Modify the user ID.
# -U: Unlock password .

6.5、 Delete user

userdel [-r] user name
# -r: Delete the user's home directory

7、 ... and 、 User group command

Each user has a user group , The system can centrally manage all users in a user group . Different Linux The system has different rules for user groups , Such as Linux The following user belongs to a group of users with the same name , This user group is created at the same time as the user is created .

7.1、 Create user group

groupadd [-g gid] Group name
# -g gid: Specified group id

groupadd The command is used to create a new workgroup , Information about the new workgroup will be added to the system file .

Related documents :

  • /etc/group Group account information .
  • /etc/gshadow Security group account information .
  • /etc/login.defs Shadow Password Suite configuration .

7.2、 Modify user groups

groupmod [-n gname] Group name
# -n: Modify user group name

7.3、 Delete user group

groupdel Group name

8、 ... and 、 File permissions

Reference resources :

Linux The system is a typical multi-user system , Different users are in different positions , Have different permissions .

In order to protect the safety of the system ,Linux The system accesses the same file for different users ( Including catalog files ) There are different rules for the authority of .

stay Linux We can use ll perhaps ls –l Command to display the properties of a file and the users and groups to which the file belongs .

stay Linux The first character in represents that the file is a directory 、 Files or linked files, etc .

  • When it comes to d It's a directory
  • When it comes to - File ;
  • if l Is represented as a linked document (link file);
  • if b It means the interface equipment available for storage in the device document ( Random access device );
  • if c Is the serial port device in the device file , For example, keyboard 、 mouse ( Disposable reading device ).

In the next characters , In groups of three , And they are rwx The combination of three parameters of . among , r Representative readable (read)、 w Representative may write (write)、 x Representative executable (execute). It should be noted that , The location of these three permissions will not change , If you don't have permission , There will be a minus sign - nothing more .

The properties of each file are shown in the first section on the left 10 Characters to determine :

Use from left to right 0-9 These numbers represent .

The first 0 Bit to determine the file type , The first 1-3 The position is the owner ( The owner of the document ) Have permission to this file . The first 4-6 The genus group is determined by the position ( The same group of users of the owner ) Have permission to this file , The first 7-9 Determine that other users have permissions for this file .

about root Users , In general , The file's permissions don't work for it .

8.1、 Modify file belongs to group

chgrp [-R] Group name file name
# -R: Recursive modification

8.2、 Modify file owner

The generic group can be modified at the same time

chown [-R] user name [: Group name ] file name

8.3、 Modify file permissions

chmod [-R] xyz file name

Linux There are two ways to set file properties , One is numbers , One is the symbol .

Linux There are nine basic permissions for a file , Namely owner/group/others( The owner / Group / other ) Each of the three identities has its own read/write/execute jurisdiction .

Let's review the data just mentioned above : The permission character of the file is : -rwxrwxrwx , The nine permissions are in groups of three ! among , We can use numbers to represent each authority , The score comparison table of each authority is as follows :

  • r:4
  • w:2
  • x:1

Each identity (owner/group/others) Three rights of each (r/w/x) Scores need to be accumulated , For example, when the permission is : -rwxrwx--- The score is :

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= --- = 0+0+0 = 0

Options and parameters :

  • xyz : This is the permission attribute of the number type just mentioned , by rwx The addition of attribute values .
  • -R : Recursion (recursive) Continuous change of , That is to say, all files in the subdirectory will be changed

Nine 、 Process command

9.1、 Check the process

ps -ef | grep Process keywords

View the firewall process ID:

9.2、 Close the process

kill [- Semaphore ] pid
# Common semaphores :1 (HUP): Reload process .9 (KILL): Kill a process .15 (TERM): Normally stop a process .

本文为[Ao Yin]所创,转载请带上原文链接,感谢

  1. HttpServletRequest, obtaining request header and request body through request, solving Chinese garbled code and other problems
  2. Mybatis learning notes - one to one, one to many, many to many association query
  3. Mybatis learning notes - basic concepts and operation
  4. Spring Cloud 升级之路 - 2020.0.x - 3. Undertow 的 accesslog 配置
  5. Spring cloud upgrade road - 2020.0. X - 3. Accesslog configuration of undertow
  6. 被Java培训机构坑骗后,我在这里找回了自信
  7. After being cheated by java training institutions, I found my confidence here
  8. Linux下安装Mysql出现的常见问题以及解决办法
  9. Common problems and solutions of installing MySQL under Linux
  10. java并发编程JUC第十二篇:AtomicInteger原子整型
  11. Java Concurrent Programming JUC Chapter 12: atomicinteger atomic integer
  12. 面经手册 · 第29篇《Spring IOC 特性有哪些,不会读不懂源码!》
  13. Chapter 29 "what are the features of spring IOC? I can't understand the source code! 》
  14. 浅析linux容器--Docker
  15. Analysis of Linux container -- docker
  16. 换种方法学操作系统,轻松入门Linux内核
  17. 浅析linux容器--Docker
  18. Another way to learn operating system, easy access to Linux kernel
  19. Analysis of Linux container -- docker
  20. 手摸手教你阅读和调试大型开源项目 ZooKeeper
  21. Hand in hand teaching you to read and debug large open source project zookeeper
  22. 基于SpringBoot 在线答题系统 含小程序!
  23. 10个优秀开源JavaScript模板引擎
  24. JavaScript基础知识及写法
  25. Based on springboot online answering system, including small procedures!
  26. 重磅!谷歌Fuchsia操作系统将支持运行Linux应用程序
  27. (四十) springcloud分布式商城之跟我学习SpringCloud-Gateway整合Eureka路由转发
  28. Spring IOC 特性有哪些,不会读不懂源码!
  29. 手摸手教你阅读和调试大型开源项目 ZooKeeper
  30. 10 excellent open source JavaScript template engines
  31. Basic knowledge and writing method of JavaScript
  32. win10安装mysql5.7
  33. Heavy weight! Google's Fuchsia operating system will support running Linux applications
  34. (40) Spring cloud distributed mall learn from me spring cloud gateway integrates Eureka routing and forwarding
  35. What are the spring IOC features? I can't understand the source code!
  36. Hand in hand teaching you to read and debug large open source project zookeeper
  37. Install mysql5.7 in win10
  38. SCIP:构造数据抽象--数据结构中队列与树的解释
  39. Spring Cloud+Nacos实现服务注册中心(Hoxton版本)
  40. rabbitmq-server的安装与升级
  41. SCIP: constructing data abstraction -- Explanation of queue and tree in data structure
  42. Spring cloud + Nacos to implement service registry (Hoxton version)
  43. Installation and upgrade of rabbitmq server
  44. Lei Jun: Xiaomi's spring conference has been largely streamlined, which will take at least four hours. Some products will be directly released on Weibo
  45. IntelliJ IDEA 2021最新激活码(亲测有效,可激活至 2089 年)
  46. java版本spring cloud+spring boot+mybatis 分布式商城 微服务商城 多租户商城 电子商务 直播带货商城 社交电商
  47. win10安装Redis5.0
  48. (十五)springboot电子商务商城之SpringCloud-使用Eureka集群搭建实现高可用服务注册中心
  49. (十四)springboot电子商务商城之SpringCloud-Eureka自我保护模式和InstanceID的配置
  50. 花生壳内网穿透(Linux版)
  51. Docker部署elasticsearch(单机)
  52. (十三)springboot电子商务商城之SpringCloud-使用Eureka集群搭建实现高可用服务注册中心
  53. (十二)springboot电子商务商城之Eureka注册中心开启密码认证
  54. 七、Spring Boot 集成 Thymeleaf 模板引擎
  55. mysql 命令行秒复制数据库
  56. Windows安装Mysql(msi 图形安装)
  57. The latest activation code of IntelliJ idea 2021
  58. Java应用全链路启动速度提升至15s,阿里云SAE能力再升级
  59. Linux基础命令
  60. Who moved your red envelope? Risk control report of 2021 spring festival activities