Introduction to common basic commands of Linux

Philosophy of Linux

(1) Everything is a file
From the perspective of Linux, all devices are files, such as common block storage, sockets, character devices, pipe devices, etc. The dialogue with the device is realized by this special file.

(2) Small, single-purpose programs
Linux peripherals are composed of many small programs with a single function.
(3) Link programs to complete complex tasks together
to complete a complex program through numerous single-function programs.
(4) Avoid confusing user interfaces.
Linux, as a server-side program, focuses on stability rather than displaying very fancy images. Stability and resource saving are more important than anything else.
(5) The configuration data is stored in the text.
All things in the memory cannot be stored persistently. To achieve persistent storage, the configuration needs to be stored on disk.

Introduction to several commonly used Linux functions

The first one is echo. This command can be used to echo the target content, and it can be used with the pipeline to pass and collect parameters.

基本用法:
       echo 【长格式|短格式选项】 【需要回显的字符串】
   -n    在输出结束不显示换行符
   -e    开启解析反斜杠
   -E   默认选项,关闭解析反斜杠

  在-e选项开启时候,可以用以下的几个作为参数,可以实现一些功能
   \\      输出反斜杠
   \a     提示一次警告的响声
   \b     回退,会将全面的一个字符删除
   \c     后面的字符串将不会继续输出
   \e     后面的的一个字符将不会输出
   \f      直接将后面的字符串直接输出到下一行的同一个位置
   \n     输出一个新行
   \t      输出一个制表符
   \v     输出垂直制表符同\f

The second is the screen tool

In the daily use of Linux, very lengthy script tasks are often executed. During the execution, if the terminal terminal is caused by the network or other reasons, the executed task will follow the terminal, so there will be a problem of inconsistent results. In order to deal with this situation, there are two tools that can realize that even if the terminal task script is closed, the script will not be closed. These two tools are Screen and tmux. tmux is an enhanced version of screen.
Screen is a software package located in the epel source, and tmux is located in the baseos source. Here we use tmux as the introduction object.
First install the tmux software package.
Introduction to common basic commands of Linux
Here we introduce the brief use of tmux methods
basic usage

  1. Directly use the tmux command, you can directly enter the login shell
    Introduction to common basic commands of Linux
  2. You can also directly define the SESSION NAME to
    Introduction to common basic commands of Linux
    view the current tmux process information when creating a session
    Introduction to common basic commands of Linux
  3. You can also access the session through other sessions to
    Introduction to common basic commands of Linux
    achieve simultaneous viewing and operation on the same screen
    Introduction to common basic commands of Linux
  4. A single session can also be temporarily separated from the session
    Introduction to common basic commands of Linux
  5. Shortcut key introduction

Terminate a terminal window (need to confirm)
Introduction to common basic commands of Linux
shortcut key: exit or press ctrl+b, release and then press &

Open a new window on the basis of the current window

Shortcut key: first press ctrl+b, release and then press c to
Introduction to common basic commands of Linux
temporarily exit the current session

Shortcut key: first press ctrl+b, release and then press d

View Panel No.
Introduction to common basic commands of Linux
shortcuts: press ctrl + b, release and then press q

Shut down after all the split-screen window that merged into a window
Introduction to common basic commands of Linux
shortcut keys: press ctrl + b, then press release!

Summary of shortcut commands:

tmux new -s session name creates a new session
tmux ls view existing sessions
tmux a enters the most recent session
tmux a -t session name enters the specified session
tumx kill-session -t session name kills the specified session

control+b evoke tmux (command prefix)
o Cursor switch split screen window
c Create new window
w View all windows
"Horizontal panel
% Vertical panel
, modify window name
? View all commands, q Exit
q Display panel number, quickly enter panel You can select the corresponding panel
d suspend the current session
s view all sessions, q exit
$ modify the session name
p switch window
: command line mode

The third is the important date command, this command can be displayed, can also be converted, and can also set the time

The date command
mainly has the following parameters
-d display time string
-s set time
-u use UTC time
output format
%% a literal%
%a abbreviated week name
%A local full week name
%b abbreviated month name
%B full name Month name
%c displays the local time (format: Mon 29 Mar 2021 11:40:22 PM CST)
%d the day of the month (eg, 01)
%D is the %m%d%y combination
%e the day of the month The number is similar to %_d
%F full format date%Y-%m-%d
%g The last two digits of the year (see %G)
%G The full format of the year is similar to %V
%h similar to %b
%H 24 hour system (00 ..23)
%I 12-hour system (01..12)
%j The first day of the year (001..366)
%k Space filling is similar to %_H (0..23); same as %_H
%l hour, Space padding (1..12); same as %_I
%m Month (01..12)
%M Minutes (00..59)
%n Open a new line
%N Nanoseconds (000000000..999999999)
%p Morning and afternoon (AM or PM)
%P morning and afternoon (am or pm)
%q The quarter of the year (1..4)
%r Twelve hours of time (eg, 11:11:04 PM)
%R Twenty-four hours of time, similar to %H:%M
%s timestamp , From 1970-01-01 00:00:00 UTC
%S seconds (00..60)
%t a tab

The fourth command is ifconfig, ifconfig is an early command, with the new generation of technology ip, ifconfig will gradually be obsolete

Introduction to common basic commands of Linux
Officials have also begun to suggest gradually using ip addr or ip link to replace the
simple commands of this command . Ifconfig -s view the current network connection error messages.
Introduction to common basic commands of Linux

ifconfig 可以加如下的参数:
add<地址> 设置网络设备IPv6的IP地址。
del<地址> 删除网络设备IPv6的IP地址。
down 关闭指定的网络设备。
<hw<网络设备类型><硬件地址> 设置网络设备的类型与硬件地址。
io_addr<I/O地址> 设置网络设备的I/O地址。
irq<IRQ地址> 设置网络设备的IRQ。
media<网络媒介类型> 设置网络设备的媒介类型。
mem_start<内存地址> 设置网络设备在主内存所占用的起始地址。
metric<数目> 指定在计算数据包的转送次数时,所要加上的数目。
mtu<字节> 设置网络设备的MTU。
netmask<子网掩码> 设置网络设备的子网掩码。
tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
up 启动指定的网络设备。
-broadcast<地址> 将要送往指定地址的数据包当成广播数据包来处理。
-pointopoint<地址> 与指定地址的网络设备建立直接连线,此模式具有保密功能。
-promisc 关闭或启动指定网络设备的promiscuous模式。
[IP地址] 指定网络设备的IP地址。
[网络设备] 指定网络设备的名称。

Example:
Add the interface address of the network card and
Introduction to common basic commands of Linux
delete the redundant sub-interface
Introduction to common basic commands of Linux

The fifth command is export

The Linux export command is used to set or display environment variables.
When executing a program in the shell, the shell provides a set of environment variables. Export can add, modify or delete environment variables for subsequent execution of the program. The effect of export is limited to this login operation.

History timestamp setting

In the default setting, only the number can be viewed when viewing the command history history, but the specific command execution time cannot be viewed.
Introduction to common basic commands of Linux
In order to conveniently view the time of the last execution of the command, the time stamp can be set in the history through the variable setting. You need to edit the /etc/bashrc file and add
HISTTIMEFORMAT=”%Y%m%d-%H%M%S:” at the end of the file
export HISTTIMEFORMAT. After
Introduction to common basic commands of Linux
saving and exiting, re-source the file
Introduction to common basic commands of Linux
to view the history and see the timestamp
Introduction to common basic commands of Linux

Guess you like

Origin blog.51cto.com/15131458/2676884