Consolidate the Foundation Series IV: Linux knowledge summary



Now many companies use Linux server for project deployment, especially for Internet companies. For larger Internet companies, the system may be very complex and cannot be started locally. Generally, special development machines are used for developers to develop and test. None of the projects I contacted during my internship can be started locally, so I need to write the code, update the code to the development machine, compile the deployment, and check whether there are errors in the deployment process or check the log of accessing this machine. These operations need to be familiar with basic linux commands.

Today, I’d like to summarize the related concepts and basic operations of Linux. If you want to learn more, you can go to “brother bird’s private dishes”. At the same time, I hope you can practice more and understand it more deeply.


Linux knowledge summarizes the following parts: Linux common concepts, Linux common commands, VI operations and a simplest shell script.


1. Common concepts of Linux

1.1 differences between Linux and windows
  • Linux is case sensitive
  • All content in Linux is saved as files, including hardware. Everything is a document.
  • Linux does not rely on extensions to distinguish file types, but on permissions to distinguish file types. File names with suffixes are conventional and easy to manage
  • Programs under Windows cannot be installed and run in Linux
1.2 what are the advantages of character interface in Linux
  • Character interface takes up less system resources
  • Character interface reduces the possibility of error and attack
1.3 division type
  • Primary partition: there can only be 4 at most.
  • Extended partition

    • There can only be 1 at most
    • The maximum number of primary partition plus extended partition is 4
    • Cannot write data, can only contain logical partition
  • Logical partition
1.4 mounting
  • Partition required

    • /(root partition)
    • Swap partition (swap partition, twice of memory, no more than 2GB)
  • Recommended partition

    • /Boot (boot partition, 200 MB)
1.5 functions of common directories
  • /Root directory
  • /Bin command to save the directory (commands that ordinary users can read)
  • /Boot directory, boot related files
  • /Dev device file save directory
  • /Etc configuration file save directory
  • /Home directory of ordinary users
  • /Lib system library save directory
  • /MNT system mount directory
  • /Media mount directory
  • /Root root’s home directory
  • /TMP temporary directory
  • /The SBIN command saves directories (directories that super users can use)
  • /Proc written directly to memory
  • /sys
  • /Usr system software resource directory

    • /Usr / bin / system command (normal user)
    • /Usr/sbin/ system command (superuser)
  • /Related documents of VaR system

Bin and SBIN in the root directory and bin and SBIN in the usr directory are used to store system commands.

Proc and sys directories can’t be operated directly. These two directories store the overload point of memory.

2. Linux common commands

2.1 basic command format

Command [options] [parameters]

2.2 query contents in the directory

Ls [options] [file or directory]


  • -a: Show all files, including hidden files
  • -l: Show details
  • -d: View catalog properties
  • -h: Humanized display file size
  • -i: Show inode
2.3 directory processing command

MKDIR – P [directory name]

-P recursive creation

Original meaning of the order:make directories

CD [contents]

Original meaning of the order:change directory

  • Simplify operations

Cd ~ enter the home directory of the current user


CD – go to last directory

CD.. go to the previous directory

CD. Enter the current directory

Query directory location: PWD

Original meaning of the order:print working directory

2.4 deleting files or directories

RM – RF [file or directory]


  • -r: Delete directory
  • -f: Compulsory
2.5 copy command

CP [options] [source file or directory] [destination directory]


  • -r: Copy directory
  • -p: Copy associated file attributes
  • -d: Copy link properties if source is a linked file
  • -a: Equivalent to – PDR
2.6 cut or rename command

MV [original file or directory] [target directory]

2.7 link command

Ln – s [original] [target]

Generate linked file

Option: – s create soft link

Hard link features:

  • Having the same I node and storage block block can be regarded as the same file
  • Can be identified by i-node
  • Cannot cross partition
  • Cannot be used for directory

Soft link features:

  • Similar to Windows shortcut
  • Soft link has its own i-node and block block, but only the file name and i-node number of the original file are saved in the data block, and there is no actual file data
  • Lrwxrwxrwx means soft link, and the permissions of soft link files are rwxrwxrwx
  • Modify any file, the other changes
  • Delete the original file, soft link cannot be used
  • Soft link if the target file and the source file are not in the same directory, the source file must write the absolute path
2.8 file search command

Locate filename

Search by file name in background database, search faster


Background database searched by locate command


Update the database. The default is one update per day. Come on. Disadvantage: can only search by file name

Find [search scope] [search criteria]

search for file

find / -name install.log

Avoid large-scale search, which will be very expensive system resources

Find is to search the system for qualified file names. If you need to match, use wildcard matching, which is an exact match.

*Match anything
? match any character
[] matches any character in brackets

find /root -iname install.log

Case insensitive

find /root -user root

Search by owner

find /root -nouser

Find files without owners

find /var/log -mtime +10

Find files modified 10 days ago

find . -size 25k

Find files with a file size of 25KB

find . -inum 262422

Find the file whose I node is 262422

2.9 commands for search commands

Where is command name

Search command path and help document location


  • -b: Find only executables
  • -m: Find help files only

Which command can see directories and aliases

2.10 search string command

Grep [options] string filename

Match matching strings in files


  • -i: Ignore case
  • -v: Exclude specified string
2.11 help command

Man command

Command — help

Help shell internal command

Info command

2.12 compression command

ZIP format compression

Zip compressed filename source file

Compress files

Zip – R compressed filename source directory

Compress directory

Unzip in ZIP format

Unzip compressed file

GZ format compression

Gzip source file

Compressed to a compressed file in. GZ format, the source file disappears

Gzip – C source > compress file

Compressed to. GZ format, source file reserved

Gzip – R directory

Compress all the sub files in the directory, but not the directory

GZ format decompression

Gzip – D compressed file

Extract files

Gunzip compressed file

Extract files

Bz2 format compression

Bzip2 source file

Compress to. Bz2 format, do not keep source file

Bzip2 – K source file

Keep source files after compression

The bzip2 command cannot compress the directory

Packing command tar

Tar CVF package filename source file

Unpacking command

Tar – xvf package filename

. tar.gz Compressed format

In fact tar.gz The format is first packaged as. Tar format, and then compressed as. GZ format

Tar – zcvf compressed package name tar.gz source file

. tar.gz decompression

Tar – zxvf compressed package name tar.gz

. tar.bz2 Compressed format

Tar – jcvf compressed package name tar.bz2 source file

. tar.bz2 decompression

Tar – jxvf compressed package name tar.bz2

2.13 shutdown command

Shutdown time


  • -c: Cancel previous shutdown command
  • -h: Shut down
  • -r: Restart



init 0

2.14 restart


init 6

2.15 system operation level
  • 0: shutdown
  • 1: Single user
  • 2: Incomplete multi-user, excluding NFS service
  • 3: Full multiuser
  • 4: Unassigned
  • 5: Graphic interface
  • 6: Restart

cat /etc/inittab

Modify the default operation level of the system


Query system operation level


Sign out

2.16 mount command
  • Query and auto mount


Query the attached devices in the system

mount -a

Mount automatically according to the content of configuration file / etc / fstab

  • Mount command format

Mount [- t file system] [- O special options] device filename mount point

  • Mount CD

mkdir /mnt/cdrom

Set up mount point

mount -t iso9660 /dev/cdrom /mnt/cdrom/

Mount CD

  • Uninstall command

Umount device filename or mount point

umount /mnt/cdrom

2.17 viewing login user information

W user name

Command output:

  • User: login user name
  • TTY: login terminal
  • From: which IP address to log in from
  • Login @: login time
  • Idle: user idle time
  • Jcpu: time taken by all processes connected to the terminal
  • Pcpu: time occupied by the current process
  • What: currently running command

Who user name

  • Query user information of current login and past login


  • View last login time for all users


2.18 historical order

History [options] [history command save file]


  • -c: Clear history command
  • -w: Write the history command in the cache to the history command save file ~ /. Bash_ history

The history command will save 1000 by default, which can be modified in the environment variable configuration file / etc / profile

2.19 statistics

WC [options] [filename]


  • -c: Count bytes
  • -w: Count words
  • -l: Count lines
2.20 pipe code

Page view output

ls -l /etc | more

netstat -an | grep ESTABLISHED

2.21 users and user groups
  • Users: people using the operating system
  • User group: a group of users with the same system permissions
  • /Etc / group: store all user group information in the current system

    • Group name
    • Placeholder for group password
    • Group number
    • List of user names in the group
  • /Etc / gshadow: store the password information of the user group in the current system

    • Group name
    • Group password
    • Group manager
    • List of user names in the group
  • /Etc / passwd: store the information of all users in the current system

    • user name
    • Password placeholder
    • User number
    • User group number
    • User comment information
    • User home directory
    • Shell type
  • /Etc / shadow stores the password information of all users in the current system

    • user name
    • password

3. VI operation

3.1 operation mode
  • Command mode: command mode
  • Insert mode: input mode
  • Last line mode: bottom line mode
3.2 common instructions

vim + abc

Open the file and position the cursor to the last line

vim +2 abc

Second line

vim +/xxx abc

Skip to the first occurrence of the specified string
Opening multiple files at the same time can be switched by n n prev

3.3 common instructions for bottom line mode
  • :w

    • Save the file without exiting VI
  • :q

    • Exit VI
  • :!

    • Enforcement
  • /xxx

    • Find down, press n to find next, n to find previous. This is the same as the use of less command
  • ?xxx

    • Search forward, press n to find next, n to find previous
3.4 command mode common instructions
  • h: Cursor left
  • j: Cursor down
  • k: Cursor up
  • l: Cursor right
  • CTRL + F: page down
  • CTRL + B: page up
  • CTRL + D: turn down half page
  • CTRL + F: turn up half page
  • DD: delete the line where the cursor is located
  • o: Insert a line below the cursor and switch to input mode
  • YY: copy the line where the cursor is located
  • p: Paste below the line where the cursor is
  • P: Paste above the line where the cursor is

3. Shell Foundation

3.1 what is shell
  • Command line interpreter to start, suspend, stop, or write programs
  • Programming language, which can directly call Linux system commands
3.2 output command

Echo [options] [output]

3.3 scripting

First line


echo “hello world”

Give execution permission and run directly

chmod 755


Script execution via Bash


I have set up a technology exchange group. Every day, I will select articles to publish the technology morning post, where there will be technology tycoons to exchange, learn and grow together. If you need friends, you can add me wechat (wechat ID: Yonglun_ 1994). We will bring you into the group and send you a big learning package.

Consolidate the Foundation Series IV: Linux knowledge summary

Consolidate the Foundation Series IV: Linux knowledge summary

Pay attention to the official account:

Reply to [Java classic] to get the Java classic e-book;
Reply to java learning to obtain the learning materials of the whole java system;
Reply to Java project to obtain the learning materials of Java project;
Reply to [Internet cognition] and obtain relevant learning materials of Internet cognition;
Reply to [technology learning] for more technology learning materials;
Reply to MySQL learning to obtain MySQL learning materials;
Reply to [interview] to obtain interview related information;

Recommended Today

Decomposition: the application of PHP magic method in laravel

Original link:… For discussion, please go to the professional laravel Developer Forum: Laravel takes PHP to a whole new level, providing you with a great development experience (DX) for your next project. Therefore, some people call it “magic“. Today, I’m going to show you one of laravel’s tricks,Magic Methods 。 What is magic? […]