linux-history-ps1-1

1. Serial Port Terminal (/dev/ttySn)
Serial Port Terminal (Serial Port Terminal) is a terminal device that uses a computer serial port to connect. The computer treats each serial port as a character device. For a while, these serial port devices were often referred to as terminal devices, because at that time their biggest use was to connect to terminals. The device names corresponding to these serial ports are /dev/tts/0 (or /dev/ttyS0), /dev/tts/1 (or /dev/ttyS1), etc. The device numbers are (4,0), ( 4, 1) etc., respectively corresponding to COM1, COM2, etc. under DOS system. If you want to send data to a port, you can redirect the standard output to these special file names on the command line. For example, typing at the command line prompt: echo test> /dev/ttyS1 will send the word “test” to the device connected to the ttyS1 (COM2) port

2. Pseudo terminal (/dev/ pty/)

Pseudo Terminal (Pseudo Terminal) is a pair of logical terminal devices (ie master and slave devices, the operation of the master will be reflected on the slave).
For example /dev/ptyp3 and /dev/ttyp3 (or /dev/pty/m3 and /dev/pty/s3 respectively in the device file system). They are not directly related to actual physical devices. If a program regards ptyp3 (master device) as a serial port device, its read/write operations on the port will be reflected on another ttyp3 (slave device) corresponding to the logical terminal device. And ttyp3 is another logical device used by the program for read and write operations. The telnet host A communicates with the login program of host A through a “pseudo terminal”.

3. Control terminal (/dev/tty)
If the current process has a controlling terminal (Controlling Terminal), then /dev/tty is the device special file of the controlling terminal of the current process. You can use the command “ps -ax” to see which control terminal the process is connected to. For the shell you log in, /dev/tty is the terminal you use, and the device number is (5,0). Use the command “tty” to check which actual terminal device it corresponds to. /dev/tty is somewhat similar to a connection to the actual terminal device used.

4. Console (/dev/ttyn, /dev/console)
In Linux systems, the computer monitor is usually called the console terminal (Console). It simulates a type of Linux terminal (TERM=Linux), and there are some device special files associated with it: tty0, tty1, tty2, etc. When you log in on the console, tty1 is used. When using Alt+[F1—F6] key combination, we can switch to tty2, tty3, etc. tty1–tty6, etc. are called virtual terminals, while tty0 is an alias of the virtual terminal currently in use, and the information generated by the system will be sent to this terminal (also called the console terminal at this time). Therefore, no matter which virtual terminal is currently being used, the system information will be sent to the console terminal. /dev/console is the console, which is a device that interacts with the operating system. The system outputs some information directly to the console. Only in single-user mode, users are allowed to log in to the console.

5. Virtual terminal
A pseudo terminal in Xwindow mode. If you use konsole under Kubuntu, it is the virtual terminal you use. Use the tty command to see /dev/pts/name, the name is Current user name

PS1="\[\e[1;5;41;33m\][\[email protected]\h \W]\\$\[\e[0m\]" 
PS1="\[\e[1;32m\][\[\e[0m\]\t \[\e[1;33m\]\u\[\e[36m\]@\ h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"
\e control character\033 \u current user
\h Abbreviation of host name\H Host name
\w Current working directory\W Base name of current working directory
\t 24-hour time format\T 12-hour time format
\ ! Command history number\# Command history number after booting
\$ prompt

screen command:
Create a new screen session
screen –S [SESSION]
Join screen Session
screen –x [SESSION]
Exit and close the screen session
exit
Strip the current screen session
Ctrl+a,d
Show all open screen sessions
screen -ls
Resume a screen session
screen -r [SESSION]

history command

Add command to /etc/bashrc 
export HISTTIMEFORMAT=" %F %T "
export HISTSIZE=1000 # Set the number of history commands in the memory
export HISTFILESIZE=1000 # Set the number of history commands in the file
export HISTFILE=~/ history.log #Modify history storage file

export HISTCONTROL=erasedups # Clear duplicate entries in the entire command history
export HISTCONTROL=ignoredups # No Ignore the repeated commands in the command history
export HISTCONTROL=ignorespace # Ignore the commands that start with a space
export HISTCONTROL=ignoreboth # Equivalent to ignoredups and ignorespace


Clear command
history -c
history -w

The function of history-w is to overwrite the history commands in memory. bash_histroy

All The commands are recorded in .bash_history, there is a risk
Solution 1:
Step 1: Set the HISTCONTROL environment variable: export HISTCONTROL=ignorespace.
Step 2: When entering important commands, remember to add a space before entering the command.
Step 3: Execute history, you can see that the important command just entered does not appear in history.


Solution 2:
Step 1: Set the HISTIGNORE environment variable export HISTIGNORE=*.
Step 2: Enter important commands, such as mysql -uroot -p123.
Step 3: Check your history, you can see that the mysql command you just entered is not recorded in history.
Step 4: Restore the record of the command export HISTIGNORE=.
After step 4, the system returns to normal again, and the commands entered can be recorded normally again

Leave a Comment

Your email address will not be published.