Common Linux Command Recording

The following commands are commonly used in Linux system, because I don't want to remember any commands, so I will record some of the commands I think are commonly used to facilitate future query. This article updates some new commands irregularly. Classification is based on my own preferences \ experience. It may be a little different from other people's classification.

Change system status class Command

init

Using such commands generally requires root permission;

init 0 # Shutdown
init 6 # restart
reboot #restart


View system resource class commands

OP commonly used

vmstat

# vmstat [refresh delay] [refresh frequency]

vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 2298560 201728 748024    0    0     2     1   29   23  0  0 100  0  0
 0  0      0 2298428 201728 748024    0    0     0     0  266  270  0  0 100  0  0
 0  0      0 2298428 201728 748024    0    0     0     0  247  236  0  0 100  0  0

free

# free

              total        used        free      shared  buff/cache   available
Mem:        4037772      789260     2298740       22276      949772     2952424
Swap:       2094076           0     2094076


Operation file class Command

RD commonly used

tail

For continuous observation of log file changes.

Use case:

# grammar
tail -f /log_name_path 

# Ctrl + C is quit


tail -f /log_name_path* | grep Keyword
# Show only keyword related logging

zip

Word shorthand zipper is zipper, zipper is not to pack files. un has a negative prefix. upzipper unlocks the zipper. It just needs to pour out all the packed items.

# Compress and specify directory
zip -r /home/kms/kms.zip /home/kms/server/kms

# Extract and specify directory
unzip /home/kms/kms.zip -d /home/kms/server/kms


Communication command

RD, OP, Security common

scp

$scp -r root@88.88.88.88:/tmp/filename ./tmp
password:


Find class Command

Generally used to combine other commands;

grep

If there is a demand for code audit under the Linux terminal, the system also does not have ide tools. If you want to search in the project directory, those files contain characters that call the current functions and variables.

grep -in "function/variable" -r ./home/my/www/cms

-i     Ignore the case of letters when comparing.
-n    Place the relevant line number in the file before each line. The starting line number of each file is 1. When processing each file, the line counter will be reset.
- r    What directory path to search from

shopt

In short, it is the enhanced version of the command line. The original command line can't use the regular matching pattern. It can be used through short.

The short command is used to display and set behavior options in the shell to enhance shell usability.
The short command displays all the shell operation options that can be set without any parameter options.

Case study:

# grammar
shopt -s extglob #Open the short command
shopt -u extglob #Close the short command


# After opening
# Delete files whose filename does not end in jpg
rm -rf !(*jpg) 

# Delete files with names ending in jpg or png
rm -rf *@(jpg|png)

# Delete all files in the current folder except css and js
shopt -s extglob
rm -rf !(css | js)
shopt -u extglob 

Five modes that can be matched:
? (pattern list) - the given pattern matches 0 or 1 times
*(pattern list) - the given pattern matches more than 0 times, including 0 times
+(pattern list) - the given pattern matches more than once, including once
@(pattern list) - the given pattern only matches once
! (pattern list) - does not match the given pattern in parentheses

When using short in zsh shell, you need to pay attention to:
When an error is reported as follows,

zsh: no matches found: !(js|css)

Solve,

# Switch to bash:
exec bash

# Then?
source ~/.bashrc

# After using short, you can switch back to zsh mode
exec zsh

Because zsh uses env configuration file ~ /. zshrc instead of ~ /. bashrc, zsh does not have this function.

Keywords: Linux shell

Added by broheem on Wed, 16 Oct 2019 06:39:56 +0300