Today I will introduce to you some very practical Linux commands.
locale
First let’s look at how to set up and view the current language. Generally, after we install the Linux system, the system uses the English language by default. To view the current language, you can use the following command:
# echo $LANG en_US.UTF-8
If you want to change it to Chinese language, how to do it. First, we need to check that the language currently supported by the system does not include Chinese. To view the language supported by the system, use the following command to view:
# locale -a aa_DJ aa_DJ.iso88591 aa_DJ.utf8 aa_ER aa_ER@saaho …… zh_CN.utf8 ……
zh_CN.utf8 This is the required Chinese language. Now, let’s change the language system to Chinese. The operation is as follows:
# LANG=zh_CN.utf8
Let’s test whether the setting is successful. Let’s see if there is Chinese in the help message.
# ls --help 用法:ls [选项]... [文件]... ……
Note : The above method to modify the language is only temporarily effective and will become invalid after the system is restarted. If you want to permanently change the language, you need to modify the configuration file /etc/locale.conf
bc
The bc command is a A calculator language that supports arbitrary-precision interactive execution. Bash has built-in support for four integer arithmetic operations, but it does not support floating point operations. The bc command can easily perform floating point operations, and of course integer operations are no longer a problem. Therefore, when we write shell scripts, we often use the bc command. Let's take a look at how it is used:
# 输入bc命令,将会进入交互式界面 # bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 3+4 7 1.2*3 3.6 4/3 1 <==== 这里怎么是1?我们需要设置精度,使用scale=保留几位小数点 scale=2 4/3 1.33
In addition, the bc command supports pipes, so we often use the bc command in shell scripts.
# echo '3.14*2' | bc 6.28 # echo 'scale=2;4/3' | bc 1.33
date
Finally we look at the date command, which is used to set or display the time and date. When we write shell scripts, this command is used very frequently. Let’s take a look at some of its common uses:
# 查看系统当前时间 date Wed Sep 2 09:15:35 CST 2020
We can also specify the desired format to display the date and time. The commonly used formats are as follows:
Format Explanation
%Y Year
%m Month
%d Date
##%w The day of the week (0-6), 0 represents Monday
# 输出类似2020-09-01 12:12:32时间格式 # date '+%F %T' 2020-09-02 09:21:04 # 将已知的日期格式修改为想要的 # date -d '2020-01-01' "+%Y/%m/%d" 2020/01/01 # 获取当前时间戳 # date +%s 1599009752 # 获取指定日期时间戳 # date --date='2020-01-01' +%s 1577808000 # 将时间戳转换为日期格式 # date -d @1599009752 "+%F %T" 2020-09-02 09:22:32
Related recommendations: "
linux course
"
The above is the detailed content of The use of several common commands under Linux - locale, bc, date. For more information, please follow other related articles on the PHP Chinese website!