Common and practical Linux shell command memo for developers (summary)


Recently, they need to be developed under Linux system, so they often need to operate in the terminal. Linux has a lot of shell commands to help us with our tasks, but if we don’t use them often, we will forget them.

As an order memo, I will record the commands used in actual work and keep them updated for a long time.


Which is used to find a file and return the absolute path. The directory range to be searched is specified by the path of the system.

Since everything in Linux is a file, which specifies more about finding the command in the system.

For example, if we look up the LS command, we know the location of its executable file

which ls


Ln is a simple but very practical command. Its function is to link a file or folder.

Command syntax

Ln [parameter] [source file or directory] [target file or directory]

Link has soft link and hard link two kinds, we use soft link commonly.

ln -s test.txt  ../test1.txt

Set the test.txt The file link is called the test1. TXT file in the upper directory. In this way, other programs accessing test1.txt are just like accessing test1.txt test.txt The same.


The tee command is one of my favorite commands.

Before Android development, especially when compiling the source code, countless log messages would be printed in a moment on the terminal. It is not possible to rely on the naked eye. A better way is to save them with commands.

In addition, when using the find command to find files, if there are too many files, you can also use tee to help.

Tee command can accept standard input, output to standard output, and save to the corresponding file.

The standard input value is the keyboard input of the terminal, such as CIN of C + +, and the standard output is the output of the terminal, such as cout of C + +.


Tee [- AI] [-- help] [-- version] [file...]

The parameter a stands for adding content after, rather than overriding.

tee tmp

I type tee TMP at the terminal

Then I type Hello, and the terminal responds to hello

I type world, and the terminal responds to world.

Then, I went through cat TMP

The results of TMP are as follows:


This shows that the tee command saves the standard input to the specified TMP file accurately.


I also like to use locate very much. I use it to find things quickly. It is to check the database, not a file real search, so, the speed is faster.

For example, I want to find out if the system has any .

That’s all I need



Common shell commands of Linux

1. Directory command:

Ll /: view all file directories under the root file

2. Help command:

Man ls and LS -- help and info LS: (man LS: split screen display; -- help: all loaded, incomplete; info LS: more useless information)

3. Basic operation and command:

CTRL + R and the up key in the direction key: find the command that has been input for a long time 
CTRL + C Ctrl + Z: terminate or exit the current operation
Letter key I: enter text editing mode (init related settings of Linux operating system can be modified)
After editing, press ESC to exit. If you are sure to save the changes and return to the command line interface, enter the command - ---: WQ
If you do not save the command and exit the editing interface  
Save and force exit: q! 
Shift + G to end of file o: line feed

4. Use of table key

Auto complete command directory
 If there is only one directory under a certain directory, when you are hungry, you can directly type the table without entering the initial letter. The planning department will automatically complete the directory
 When you double-click a table, it usually displays all the names or lists all the directories and files in a directory

5. System level command

Command to change host name: VI / etc / sysconfig / network
 View current Linux system information
 Uname - a displays all information about the system and version
 Uname - R displays the kernel version
 Uname - M shows how many bits the computer is
 Cat / proc / version Linux view current operating system version information
 Cat / etc / issue or cat / etc / RedHat release Linux view version current operating system release
 View small version of system
 cat /etc/redhat-release
 View current host name
 View the first network card
 ifconfig eth0
 View and set system time
 Displays the currently running process, including CPU memory usage
 top -s
 Cmd1| cmd2 gives the output of CMD1 to the cmd2 command for execution
 For example, to view the process: PS fe|grep redis
 Grep: filtering
 #Grep // output the line containing the specified string
  -I // ignore case
  -R // recursion
  -V // reverse
  --Color // highlight find string
 Restart the Linux operating system
 init 6
 Shut down the Linux operating system
 shutdown -h now
 init 0
 Graphics and command line conversion
 vi /etc/inittab
 Init 3 command line mode
 Init 5 graphical
 View the run level of the virtual machine run (normal state starts with 5)
  cat /etc/inittab 
  1: Single user mode
  The same function of 2 and 3: multi user mode
  4: Function not defined (not used)
  6: Restart
 Show daemons directory tree
 Pstree or pstree - P (display PID)
 View running processes
 ps -aux
 Show all Java processes
 JPS (if JDK is not installed, it will show that there is no such command)
 Ends the running specified process
 Kill - 9 PID (refers to the ID of the process)
 Do not enter the system to change the root password
 1. Press E in grub option menu to enter editing mode
 2. Edit the kernel line, type "1" (space + 1), and then press enter
 3. Press B to restart
 4. Execute the following command after entering
  Root @ # passwd root (configure the password of root)
  Enter new UNIX password: enter a new password
  [email protected]#init 6

6. Disk operation

Displays the amount of disk space used by the system
 DF - H // display disk partition information
 mkfs.ext3  /Dev / sdb1 FS format // format hard disk partition
 Fdisk - L // view partition
 Du - H - S // view the usage space of the directory or partition  
  For example: Du - H / var / log / (indicates the space occupied by files in the var / log directory) 
   Du - H - S / var / log / (indicates viewing the usage space of the entire log directory)
 mount -t vfat/dev/sdb1/media/umnt  //mount 
 mount -o remount rw/  //重新mount ,或者将根目录以读写方式重新加载
 Umount / media / umnt // uninstall
 File system repair
 Fsck - Y / dev / sda1 (fixed can be partition or directory, best used in single user mode)
 //Linux file format
 ext4 ext3 ext2 vfat(fat32)
 //Windows file format
 ntfs fat32

7. Operation of users and groups

Super account root uid = 0
 General account uid > = 500
 System account uid = 1 ~ 499
 /Etc / passwd // save account information
 /Etc / shadow // save account password information
 /Root / root user home directory
 /Home / xxx // home directory of ordinary user XXX
 Add user and delete user useradd
 #Useradd // create user, for example: useradd admin another way: useradd - G manager Tom (attach to group manager)
 -U specifies the uid
 -D specifies the host directory
 -S specifies to use the shell
 -E specify the user expiration time
 -G specifies the basic group
 -G specifies the additional group
 #useradd openlab
 #Gpasswd - a OpenLab gropenlab // add the user to the group, for example: ා gpasswd - a Tom admin
 #Gpasswd - D OpenLab gropenlab // remove user from group
 #Echo "123456" | passwd -- stdin Feige // change password directly without interactive information
 #Userdel - R // delete with home directory
 #Userdel // deleting users does not delete user files
 #ID OpenLab // display user information
 Vipw // view users
 Create user group
 groupadd manager
 Vigr view group
 Groups manager to see which groups the user is in
 Change Password: 
 Method 1: passwd Tom mode 2: etho "root" | passwd -- stdin root // modify the password directly without interactive information
 Lock the account Tom and forbid it to log in
 usermod -L tom
 Switch current account to Caimin
 su -caimin
 Display the current login user account
 Check the system file to determine whether the operation of adding user group and adding user is correct
 Cat / etc / passwd or vipw
 Cat / etc / group or use vigr

8. File operation

CD entry operation
 PWD view current directory
 MKDIR new folder
 MKDIR - P // recursively creates a folder, for example: MKDIR - P. / test1 / Caimin / test2
 (. / refers to the user's current directory, / refers to the root directory, Linux's root directory is /, root's home directory is / root)
 Touch / TMP / test1 / file to create an empty file
 VI file // create an empty file and enter the editing interface. Press e to enter editing mode, and press ESC to exit editing
 : WQ save edit information and return to the command line interface: Q do not save and return to the command line interface: q! Force exit (do not save)
 List files and directories:
 ll -h /home/
 LS - S - H / home / (ll is equivalent to LS - L)
 VI and VIM text editing
 File content view
 Cat - N // display line number when viewing contents
 Cat / etc / rehat release // the line number is not displayed
 Cat - N / etc / passwd // display line number when viewing contents
 Displays the first or last 10 lines of the file
 Tail // view the last 10 lines of the file by default
 Head // view 10 lines of file header by default
  -N number // view the first few lines specified
 cat  cat -n  head tail
 Tail - f dynamically monitors file data (press Ctrl + C to exit)
 More percentage view, cannot roll back to view
 Less can look back to rollback
 Copy file
 cp ./tmp/file.txt /test
 duplicate catalog
 cp -r ./tmp/test01 ./test02(递归Copy file)
 Move, cut, rename, delete
 mv -rf
 Rename batch rename
 >> > overlay and append
 RM XXX / delete file RM - RF XXX / delete directory

9. Document authority

PWD view current location
 LS - L / Data0 displays the files in the current directory

10. Packaging tar principle

-Z compress-c pack-x unpack
 -F must have - C specify the decompression location - V output information
 /usr/bin/unzip  /bin/gzip /bin/gunzip
 Package case (tar command usually replaces GZ command)
 //Package a file
 tar -zcvf ./ test.tar  . / test (package the test folder into a test package)
 //Package multiple files into one package
 tar -zcvf folder.tar file1.txt file2.txt 
 //Unzip a file
 tar -zxvf ./test.tar
 //Unzip a file到指定目录
 tar -zxvf ./test.tar -C /home/test/
 //Package and compress multiple files
 tar -zcvf ./test.tar.gz folder1 folder2
 //Unpack and unzip multiple files
 tar -zxvf ./test.tar.gz
 Use tar to back up the contents of the specified directory / Data0 / including the contents of subdirectories to / data3 / Data0 tar.gz
 tar -zcvf /data3/data0.tar.gz /data0
 Recover the contents of tar file / data3 / Data0 tar.gz To / data2/
 tar -zxvf /data3/data0.tar.gz -C /data2
 Which CMD finds the path where the CMD command is located
 which reboot
 It is very efficient to locate the database
 Locate unzip (an index name) // to find the file, click
 Updatedb // update the database to make it effective
 Find file lookup - very slow
 Find path condition find / - name unzip (find the file named unzip in the root directory)
 Alias shell commands
 Alias (this operation is only valid for the current session < connection > and there is no alias for opening another connection)
 Eg: alias cle = clear
 Unalias cancel alias setting eg: unalias cle
 Permanent settings: enter VI ~ /. Bashrc (the environment configuration file under the home user directory, which is only for the current user)
 After entering the edit mode, add alias cle: 'clear' to save and return to the command line
 Enter the command source ~ /. Bashrc and you're done

The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.

Recommended Today

Summary of import and export usage in JavaScript

import import 和 require 的区别 import 和js的发展历史息息相关,历史上 js没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来。这对开发大型工程非常不方便。在 ES6 之前,社区制定了一些模块加载方案,最主要的有 CommonJS 和 AMD 两种。前者用于服务器,后者用于浏览器。ES6 在语言标准的层面上,实现了模块功能,而且实现得相当简单,完全可以取代 CommonJS 和 AMD 规范,成为浏览器和服务器通用的模块解决方案。也就是我们常见的 require 方法。 比如 `let { stat, exists, readFile } = require(‘fs’);` 。ES6 在语言标准的层面上,实现了模块功能。ES6 模块不是对象,而是通过export命令显式指定输出的代码,再通过import命令输入。 import 的几种用法: 1. import defaultName from ‘modules.js’; 2. import { export } from ‘modules’; 3. import { export as ex1 } from […]