search

What is linux etc profile

Apr 11, 2023 am 11:00 AM
linux

linux etc profile is a file related to Linux environment variables. The content modified in this file is effective for all users; Linux users can customize their own operating environment by modifying the corresponding system. environment variables.

What is linux etc profile

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Linux /etc/profile file detailed explanation

linux /etc/profile file changes will involve the system environment, and also It’s about Linux environment variables. To learn Linux, you need to understand the relevant principles of Linux profile files. Here, we will use files for detailed analysis. This change will affect all users.

 1. Linux is a multi-user operating system. After each user logs into the system, he will have a dedicated operating environment. Usually the default environment for each user is the same. This default environment is actually the definition of a set of environment variables. Users can customize their own running environment by modifying the corresponding system environment variables.

 2. Often modify environment variables in the /etc/profile file. The modified content here will affect all users. The following main operations will be performed in this file.

 3. How to add environment variables.

For example, add "NAME=liheng". Add the following content at the end of the profile file: export NAME=liheng

The variable value liheng can be quoted or not, and the effect is the same.

 4. Content added or modified in the profile file needs to be logged out of the system to take effect.

 5. How to understand the repeated definition of variables.

What often appears is the definition of the PATH variable.

For example: PATH variable is set by default in the peofile file PATH=¥¥¥¥¥¥¥ (can’t remember). In the future, PATH may be set, which is usually added at the end of the profile file. PATH=······(for example). The PATH recognized in the system is ········¥¥¥¥¥¥¥¥¥, which means that for environment variables with the same name, the one written later will take effect first (in layman's terms). Everyone must pay attention.

 6. Introduction to special characters.

For example, there is the following content in the profile. The following content explains the usage of special symbols.

export A=/q/jing:aaa/cc/ld

export B=.:/liheng/wang export A=/cd/cdr:$A

Everyone Pay attention to the red symbols:

 : indicates parallel meaning. For example, if there are multiple values ​​of variable A, use the : symbol to separate them.

 . Indicates the current directory you are operating in. For example, the pap command will look for the B environment variable.

Type the pap command in /home. The system first searches for the content about B in the /home directory (i.e. the current path), linuxidc. com">www.linuxidc.com If there is no content about B in the /liheng/wang directory. $ represents the value of the variable before this definition, for example, $A represents /q/jing:aaa/cc/ld. In other words, A=/cd/cdr:/q/jing:aaa/cc/ld

 7. Use the env command to display all environment variables. Just type env at the command prompt.

The set command displays all locally defined Shell variables.

8. Common environment variables

PATH: Determines which directories the shell will search for commands or programs

HOME: The current user’s home directory

MAIL: refers to the current user's mail storage directory.

SHELL: refers to what kind of Shell the current user is using.

HISTSIZE: refers to the number of historical command records saved.

LOGNAME: refers to the login name of the current user.

HOSTNAME: refers to the name of the host. If many applications want to use the host name, it is usually obtained from this environment variable.

LANG/LANGUGE: It is an environment variable related to language. Users who use multiple languages ​​​​can modify this environment variable.

PS1: It is the basic prompt, which is # for root users and $ for ordinary users.

PS2: It is a subsidiary prompt, the default is ">". You can modify the current command prompt by modifying this environment variable. For example, the following command will modify the prompt into the string "Hello, My NewPrompt :)".

 # PS1="Hello,My NewPrompt:) "

 9. Use the modified .bashrc file (in the user's home directory) to edit environment variables, which is only useful to the current user. Editing environment variables by modifying the /etc/profile file is useful for all users. Everyone must pay attention to the difference.

 10. The Linux profile file will be run when the system starts. You can add other commands in it, but they must be added correctly, otherwise the system will not start.

Continued

  • /etc/profile, /etc/profile.d, ~/.bashrc, ~/.bash_file, what are the differences between these files? Many newcomers may be confused. Even many people who configure some software environment variables are very confused.

~/.bashrc and ~/.bash_file are consistent. You should understand that this is the host directory. , that is, the environment variables inside are also called shell variables. They are local and only valid for a specific shell. Don’t forget to use the source command after modification.

/etc/profile, /etc/profile.d, the first one is the file, and you will understand at a glance later that .d represents the directory, and the variables in /etc/profile are global and apply to all users’ shells. efficient.

  • Whenever we enter a command in the terminal, the system will respond. The most important thing is the search path. You can see it through echo $PATH. The search path of the system command is: Meet separate.

When we download a software, if we want to start the program without adding a path, if we enter eclipse anywhere in the shell, that is, to start the program, we can add the eclipse program Just add the path of the executable program to PATH.

In fact, we can have another method, please see the following code

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.


if [ -d /etc/profile.d ]; then              # 判断/etc/profile.d 是不是一个目录
  for i in /etc/profile.d/*.sh; do       #如果是一个目录,到该目录下,取出每一个shell程序
    if [ -r $i ]; then                             #如果该shell可以执行
      . $i                                               # 则执行它
    fi
  done
  unset i
fi

The modified code is part of /etc/profile, indicating that /etc/profile will execute /etc/ first All *.sh files in the profile.d/ directory. This also gives us an scalable idea. If we need to configure JDK, then create the jvm.sh file under /etc/profile.d/. If we need to configure ant, then create the ant.sh file under /etc/profile.d/
The effect obtained in this way Consistent, if you don’t believe me, try it yourself.

Then, just add your own configuration in the corresponding configuration file.

Recommended study: "linux video tutorial"

The above is the detailed content of What is linux etc profile. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Maintenance Mode in Linux: When and Why to Use ItMaintenance Mode in Linux: When and Why to Use ItApr 25, 2025 am 12:15 AM

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Linux: Essential Commands and OperationsLinux: Essential Commands and OperationsApr 24, 2025 am 12:20 AM

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

Linux Operations: Managing Files, Directories, and PermissionsLinux Operations: Managing Files, Directories, and PermissionsApr 23, 2025 am 12:19 AM

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

Linux Architecture: Unveiling the 5 Basic ComponentsLinux Architecture: Unveiling the 5 Basic ComponentsApr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)