Home > Operation and Maintenance > Linux Operation and Maintenance > The use of several common commands under Linux - locale, bc, date

The use of several common commands under Linux - locale, bc, date

齐天大圣
Release: 2020-09-02 13:10:26
Original
2634 people have browsed it

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
Copy after login

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
……
Copy after login

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
Copy after login

Let’s test whether the setting is successful. Let’s see if there is Chinese in the help message.

# ls --help
用法:ls [选项]... [文件]...
……
Copy after login

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
Copy after login

In addition, the bc command supports pipes, so we often use the bc command in shell scripts.

# echo &#39;3.14*2&#39; | bc
6.28
# echo &#39;scale=2;4/3&#39; | bc
1.33
Copy after login

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
Copy after login

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

  • ##% F Full date format, equivalent to %Y-%m-%d

  • %H Hours

  • ##%M Minutes
  • %S Seconds
  • ##%s The number of seconds elapsed since UTC time 1970-01-01 00:00:00
  • %T Time, equal to %H:%M:%S
  • ##%w The day of the week (0-6), 0 represents Monday

  • # 输出类似2020-09-01 12:12:32时间格式
    # date &#39;+%F %T&#39;
    2020-09-02 09:21:04
    
    # 将已知的日期格式修改为想要的
    # date -d &#39;2020-01-01&#39; "+%Y/%m/%d"
    2020/01/01
    
    # 获取当前时间戳
    # date +%s
    1599009752
    
    # 获取指定日期时间戳
    # date --date=&#39;2020-01-01&#39; +%s
    1577808000
    
    # 将时间戳转换为日期格式
    # date -d @1599009752 "+%F %T"
    2020-09-02 09:22:32
    Copy after login

    If you want to modify the system time, you need to use the -s option. However, it is generally not recommended to modify the system time. Anyway, some unexpected problems may occur.

    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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template