##Linux Basics
Foreword:
If it's blooming, the breeze is coming, and the heart is floating and sinking, smiling peacefully
This sentence comes from Sanmao's original essay:
The beauty of time lies in its inevitable passage, spring flowers, autumn moons, summers, winter snows, if you are in full bloom, the breeze, your heart is floating, lightly smiling and peaceful.
The translation is that if you are good enough, everything will be okay, with a stable attitude and calmly face the world.
Mentality is an artistic conception
It's natural to smile!
Don’t take the loss as a reason. You should find the reason from yourself. When you are good enough, correct your mentality. All problems are no longer a problem. Improve yourself, make yourself better and better, and become the flower that exudes charm.
One, bash interpreter features
1) Automatic completion of commands and files Note: Tab can only complete commands and files
[root@web02 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
2) Shortcut keys
Ctrl+c ## Terminate the program running in the foreground
Ctrl+d ## Exit Equivalent=exit
Ctrl+l ## Clear screen
Ctrl+a ##Move the cursor to the forefront of the command line
Ctrl+e ##Move the cursor to the back end of the command line
Ctrl+r ## Search history commands using keywords
Alt+. ## quoting the last parameter of the previous command is equivalent to! $
3) Historical commands
1. View historical commands
[root@xxx ~]# history
2. Clear history command
[root@xxx ~]# history -c
3. History command save file: cat ~/.bash_history
4. The history command saves 1000 by default and can modify HISTSIZE=2000 in /etc/profile
5. Find historical commands and run
(1) Cursor up and down keys
(2) Ctrl+r ## Search history commands (input a keyword of a certain command: must be continuous)
(3) !220 ## Execute the 220th command in the history command
(4) !String ## Search the most recent command starting with xxxx in the history command, for example!ser
(5)! $ 2 ## quote the last parameter of the previous command
[root@xxx home]# ls /root /home
[root@xxx home]# cd !$
cd / home
[root@xxx home]# ls /root /home
[root@xxx home]# touch !$/file1
touch /home/file1
4) Alias
# alias ## View the current alias
ll='ls -l --color=tty'
# alias egon='ls /etc/sysconfig/network-scripts/' ## Create alias
# unalias fly
[root@fly ~]# grep root /etc/passwd ## There is color by default
[root@fly ~]# alias grep
alias grep = 'grep --color = auto'
2. Command search priority
The bash shell finds the order of commands:
First priority: commands executed with absolute or relative paths
Second priority: the command specified by the alias
Third priority: Bash internal commands
Fourth priority: the first command found in the directory search order defined by the $PATH environment variable
Three, view help information
1) man manual
(1) Simple to use
man command
(2) The detailed explanation is as follows
man manual name such as man ls
Search: /-h n N
Tip 1: Find by chapter, the commonly used ones are 1 (command usage) 5 (text specification) 8 (system management commands)
/usr/bin/passwd command to modify user password man 1 passwd
/etc/passwd file holding user information man 5 passwd
/etc/exports man exports man 5 exports
Tip 2: Search by keyword (suitable for when you can’t remember the full name of the manual)
man -k "_selinux" ## Manual name or manual description contains keywords _selinux
Note: Find from whatis database (# makewhatis)
Tip 3: Search in all chapters
# man -a passwd
# man -f passwd
2) --help
Command --help
Example 1
[root@xxx ~]# ls --help
Usage: ls [OPTION]... [FILE]...
ls common options
-a ## all View all files in the directory including hidden files
-l ## Long list display
-h ## human displayed in a humane way
-d ## List only the directory name and not other content
-t ## Sort by modification time
-r ## Reverse order
-i ## Display the inode number (index number) of the file
3) Reference document\Configuration module file
[root @ iZm5e59rizbgmmp4net6zbZ ~] # ls /usr/share/doc/pam-1.1.8/
[root@iZm5e59rizbgmmp4net6zbZ ~]# firefox /usr/share/doc/pam-
1.1.8 / html / Linux-PAM_SAG.html
4) Official manual
5) baidu google
Seven, commonly used commands
Set hostname
[root@xxx ~]# hostnamectl set-hostname fly ## Exit and re-enter to see
Set time
[root@fly ~]# date --help
Check time
# date "+%Y_%m_%d %H-%M-%S"
Set time
#date -s "2018-05-17 09:51:50"
Write to hardware clock
Note: here is that the system time is maintained by the operating system in Linux
The hardware clock refers to the clock device on the motherboard, that is, the clock hardware time usually set in the BIOS screen is stored in CMOS
The system clock refers to the clock in the kernel. When Linux starts, the Linux operating system reads the time from CMOS into the system time variable. After that, the system clock operates independently. All Linux-related instructions and functions read the settings of the system clock.
The Linux system provides two time zones when setting the hardware clock. One is the local time zone. The hardware time is the same as the system time; the other is the UTC time zone. The hardware time is stored in UTC time when the system is initialized and converted to local time. Time set as the system clock
In the future, modify the time by modifying the system time. In order to maintain the consistency between the system time and the CMOS time, Linux will write the system time into the CMOS at regular intervals. Because the synchronization is performed at intervals (about 11 minutes), we execute the date If you restart the machine immediately after -s to modify the time, it may not be written to CMOS. This is the cause of the problem.
If you want to ensure that the modification takes effect, you can execute the following command
hwclock -w
This command forces the system time to be written into CMOS
Note: To make the system time accurate, it is best to use ntp method ps: centos7 replace ntp with chrony
Use the ntpdate command to synchronize time from the network to the hardware clock
The ntpdate command is a command that uses the NTP protocol to synchronize time from the network. NTP=Network Time Protocol Network Time Protocol
ntpdate 0.cn.pool.ntp.org
date
hwclock -w
ps: Alibaba Cloud provides 7 NTP time servers, which are Internet time synchronization server addresses
ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
ntp4.aliyun.com
ntp5.aliyun.com
ntp6.aliyun.com
ntp7.aliyun.com
Reboot
shutdown -r 10 ## Restart in ten minutes
shutdown -r 0 ## Restart immediately
shutdown -r now ## Restart now
init 6 ## Restart now
reboot ## Restart now
Shutdown
shutdown -h 10 ## Shut down in ten minutes
shutdown -h 0 ## Shut down immediately
shutdown -h now ## Shut down immediately
halt ## Shut down immediately
poweroff ## Turn off immediately
Cancel an ongoing shutdown or restart
showdown -c
Log out of the account
exit
logout
Ctrl+d