Linux Common Commands--(1) Environment Variables


1. ldd command

ldd用来打印或者查看程序运行所需的共享库(访问共享对象依赖关系),常用来解决程序因缺少某个库文件而不能运行的一些问题。Commonly used commands are as follows:

  • View the dynamic libraries required by the ls command:
$ which ls
  • View the detailed information of the packages that the libstdc++.so.6 dynamic library depends on. If the dependent packages are missing, not found will be displayed later:
$ whereis libstdc++.so.6

2. Set environment variables

2.1 Linux中PATH、 LIBRARY_PATH、 LD_LIBRARY_PATH

  • PATH
    PATH is a stored 可执行文件搜索路径system environment variable that contains a list of directories separated by colons ":". When a command is run, the operating system looks for the corresponding executable file in these directories and executes it if found. For example, when the ls command is executed on the command line, it will search for the ls command in the directories listed in the PATH variable in turn, and execute it if found, otherwise it will prompt that the command cannot be found. The PATH environment variable can be modified in the following ways:
  1. Temporary modification will no longer take effect after exiting:

export PATH=$PATH:/exe_path/bin

  1. Permanent modification:
# 修改 ~/.bashrc 或 /etc/profile 
export PATH=$PATH:/exe_path/bin

# 或者修改 /etc/environment
PATH=$PATH:/exe_path/bin

# 生效
source ~/.bashrc
或者
source /etc/profile
或者
source /etc/environment

This command will add the /exe_path/bin directory to the system's PATH variable.

  • LIBRARY_PATH
    LIBRARY_PATH is a stored 编译器查找库文件搜索路径system environment variable. When compiling source code, the compiler looks in these directories for the specified library files to link into the executable. The LIBRARY_PATH environment variable can be modified in the following ways:
  1. Temporary modification:

export LIBRARY_PATH=$LIBRARY_PATH:/compile_lib_path/lib

  1. Permanent modification:
# 修改 ~/.bashrc或系统级别的/etc/profile
export LIBRARY_PATH=/compile_lib_path/lib:$LIBRARY_PATH 
# 生效
source ~/.bashrc
或者
source /etc/profile

This command will add the directory /compile_lib_path/lib to the LIBRARY_PATH variable of the system. When compiling the program later, the compiler will search for library files in the directory /compile_lib_path/lib.

  • LD_LIBRARY_PATH
    LD_LIBRARY_PATH is 存储运行时共享库文件搜索路径a system environment variable. When running an executable program, the dynamic linker (ld.so) looks in these directories for the corresponding shared library files. Once these library files are found, they are loaded into the program. The LD_LIBRARY_PATH environment variable can be modified in the following ways:
  1. Temporary modification:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

  1. Permanent modification:
修改 ~/.bashrc 或者 ~/.bash_profile文件
export LD_LIBRARY_PATH=/ld_path/bin:$path
# 同步
source ~/.bashrc
或者 
source ~/.bash_profile

This command will add the /ld_path/bin directory to the LD_LIBRARY_PATH variable of the system. When running the program later, the dynamic linker will search for the shared library in the /ld_path/bin directory.

2.2 Difference between LD_LIBRARY_PATH and LIBRARY_PATH

LIBRARY_PATHThe environment variable is used to 编译期间specify the path to find the shared library when the program searches for the dynamic link library, for example, specify the directory of the dynamic link library that gcc compiles.
LD_LIBRARY_PATHThe environment variable is used to 运行期间specify a path other than the system default path when the program loads and searches for the dynamic link library. Note that the path specified in LD_LIBRARY_PATH will be searched before the system default path.

2.3 Precautions

It should be noted that if multiple paths are set in the environment variable, the operating system will 按照指定的顺序search the dynamic link library in turn. Therefore, the most commonly used paths should be placed first to improve the operating efficiency of the program.

2.4 View the currently used environment variables

You can use the following command to view the current environment information:

export

2.5 Set the path in the specified order

To be added

3. Set the server character set

3.1 What is a character set

Character Set (Character Set), also known as Encoding (Encoding), 是用于表示文本的一组字符和它们在计算机中的表示方式。different character sets contain different characters, representation methods, and supported languages, so using the same character in different character sets usually results in different results. In the Linux system, the default character set is UTF-8, which is an implementation of the Unicode character set.

3.2 View the current character set

echo $LANG

3.3 Modify the current character set

Commonly used character sets:

GB2312
GBK
UTF-16
UTF-32
UTF-8 (Common)

3.3.1 Temporarily modify the character set

LANG=zh_CN.UTF-8

3.3.2 Persistence save character encoding

  1. Modify the configuration file: /etc/locale.conf
    insert image description here
  2. Modify character set encoding by command

localectl set-local LANGUAGE=zh_CN.utf8

Guess you like

Origin blog.csdn.net/qq_39030233/article/details/131491250