/etc/profile file and /etc/profile.d/ folder under Linux

Regarding
the two important profile files of the profile file, there are two essential files for users in the UNIX/Xenix system - the profile file in the etc directory and the .profile file in the user's home directory ($HOME). The former is a system file, which works on all users under the system, and the latter is the user's own "private" file.
The functions of these two files are similar to the Autoexec.bat file under DOS system, the difference is that the Autoexec.bat file can be empty, and the contents of these two files not only cannot be empty, but must exist. They are automatically executed by the system when the user logs in (Login registration) to set the working environment for the user.
The profile file in the etc directory is the file that the operating system executes first when each user logs in, and then gives control to the .profile file in the user's home directory. When the system gives the main prompt ($), the user will You can start your own work. The whole process above is transparent to the user.
The main functions of the /etc/profile file include: displaying UNIX/Xenix version information or prompt information of system-specific applications, setting a mask (umask), processing terminals and mailboxes (mail box), and prohibiting the use of news for non-root users command etc.
Because the scope of the /etc/profile file is all users, non-common settings should be placed in the user's own .profile file. The following describes the .profile file in detail.
.profile is a hidden file, which cannot be displayed by ordinary listing commands (l, ls, lf, ls-l, etc.). All hidden files in UNIX/Xenix systems are preceded by a "." character.
Display implicit file attributes on UNIX/Xenix systems with the following command:
$l - a
The original .profile file is automatically generated by the system for the user when the system administrator uses the Sysadmsh command or the mkdev user command to create a user, and the user can use vi to edit the file for his own use. The utility generated by the .profile file does not disappear until the user logs out of the system, and starts to function again when the user logs back in.
Setting the terminal type
When users use UNIX/Xenix systems, they may encounter such a phenomenon: after each login, the system will ask the user to type in the terminal type, and then the prompt will be given after the user enters the corresponding information. Why is this?
There is such a statement in the original .profile file:
eval 'test -m ansi:ansi -m:${TERM:ansi}-r -s -Q'
The function of this statement is to require the user to type in all Use the type of terminal and test.
If we add the following command to the .profile file:
TERM=terminal-name The
TERM variable specifies the terminal type.
Such as: TERM=vt100, and comment out the eval statement. After doing this, when the user registers again, there is no need to type in the terminal type.
Define the PATH variable
This variable is similar to the PATH variable of the DOS system, and its format is as follows:
PATH=$PATH:$HOME/bin:/usr/informix/bin:.
Description:
1. The "·" at the end of the statement indicates the current path , indispensable;

2. Separate different paths with ":";

3. $PATH is the default variable provided in the system, and its initial value is /bin:/usr/bin;

4. The order of the paths is very important, and the order of the paths should not be reversed. For example, if a user has compiled an executable file with the same name as a system command, and placed it under $HOME, and intends to use this command instead of the system-provided command with the same name, the PATH should be set to:
PATH=$HOME/bin: $PATH:/usr/informix/bin:.
Because, if there are the same commands or executable files in different paths, the first path shall prevail. At this time, SHELL first searches the $HOME/bin path, finds the executable file under it, and calls it for the user, instead of running the standard command of the same name under /bin or /usr/bin.

Setup Prompt
Users can change PS1 (Primary Prompt), PS2 (Secondary Prompt) to more popular forms. Under normal circumstances, when logging in as a
super user, the main prompt is "#", other users are "$", and PS2 is generally "<". The method of modifying the prompt is as follows:
Format: PS1="$LOGNAME> "
Description: Change the main prompt from the default value to the user's registered name.
Use the stty command to reset the terminal configuration

/etc/profile.d/ is easier to maintain than /etc/profile. If you don’t want any variables, just delete the corresponding shell script under /etc/profile.d/. You don’t need to do it like /etc/profile. change this file

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326775628&siteId=291194637