【随笔记】简单梳理/etc/profile、/etc/bashrc、/etc/profile.d/、~/.bash_profile、~/.bashrc

cat的实用技巧 cat>>/etc/profile<<EOF 前言 环境:Centos7.9 cat实用技巧 实用技巧1:输出多行字符 cat<< EOF >菜单大全: >青椒炒肉丝 >凉拌黄瓜 >铁锅炖大鹅 EOF 使用技巧2:覆盖或追加多行字符到文件 cat>>/etc/rc.local<< EOF #说明:这里的EOF没有加单引号,则shell默认会解析特殊字符,如遇$符号解析变量值 >菜单大全: >青椒炒肉丝 >凉拌黄瓜 >我家:$PATH #这里将被解析 阅读详情

结论:

在 /etc/profile 中配置系统变量;

在 ~/.bash_profile 中配置用户变量;

CentOS7系统

1、/etc/profile

[root@centos7 ~]# cat /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge

2、 /etc/bashrc

[root@centos7 ~]# cat /etc/bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi
  # Turn on parallel history
  shopt -s histappend
  history -a
  # Turn on checkwinsize
  shopt -s checkwinsize
  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
  # You might want to have e.g. tty in prompt (e.g. more virtual machines)
  # and console windows
  # If you want to do so, just add e.g.
  # if [ "$PS1" ]; then
  #   PS1="[\u@\h:\l \W]\\$ "
  # fi
  # to your custom modification shell script in /etc/profile.d/ directory
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        case ":${PATH}:" in
            *:"$1":*)
                ;;
            *)
                if [ "$2" = "after" ] ; then
                    PATH=$PATH:$1
                else
                    PATH=$1:$PATH
                fi
        esac
    }

    # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
       umask 002
    else
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4

3、~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

4、~/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

5、/etc/profile.d/

[root@centos7 ~]# ls -al /etc/profile.d/
total 84
drwxr-xr-x.  2 root root 4096 May 22 09:47 .
drwxr-xr-x. 75 root root 8192 May 22 10:22 ..
-rw-r--r--.  1 root root  771 Apr 11 13:09 256term.csh
-rw-r--r--.  1 root root  841 Apr 11 13:09 256term.sh
-rw-r--r--.  1 root root  196 Mar 25  2017 colorgrep.csh
-rw-r--r--.  1 root root  201 Mar 25  2017 colorgrep.sh
-rw-r--r--.  1 root root 1741 Apr 11 04:20 colorls.csh
-rw-r--r--.  1 root root 1606 Apr 11 04:20 colorls.sh
-rw-r--r--.  1 root root   80 Apr 11 12:18 csh.local
-rw-r--r--.  1 root root 1706 Apr 11 13:09 lang.csh
-rw-r--r--.  1 root root 2703 Apr 11 13:09 lang.sh
-rw-r--r--.  1 root root  123 Jul 31  2015 less.csh
-rw-r--r--.  1 root root  121 Jul 31  2015 less.sh
-rw-r--r--   1 root root  148 May 22 09:47 path.sh
-rw-r--r--.  1 root root   81 Apr 11 12:18 sh.local
-rw-r--r--.  1 root root  105 Apr 11 07:54 vim.csh
-rw-r--r--   1 root root  269 May 22 09:42 vim.sh
-rw-r--r--.  1 root root  164 Jan 28  2014 which2.csh
-rw-r--r--.  1 root root  169 Jan 28  2014 which2.sh

/etc/profile

 

    |- System wide environment and startup programs, for login setup

    |- 用于登录设置的全系统环境和启动程序

/etc/bashrc

    |- System wide functions and aliases

    |- 系统范围的函数和别名

/etc/profile.d/

    |- It's much better to create a custom.sh shell script in /etc/profile.d/ to make custom changes to your environment, as this will prevent the need for merging in future updates.

    |- 最好在/etc/profile.d/中创建一个custom.Shell脚本,以便对环境进行自定义更改,因为这将避免在将来的更新中合并。

~/.bash_profile

    |- User specific environment and startup programs

    |- 用户特定环境和启动程序

~/.bashrc

    |- User specific aliases and functions

    |- 用户特定别名和函数

系统启动时加载 /etc/profile -> 内部加载 /etc/profile.d/ 路径下的*.sh脚本;

用户登录时加载 ~/.bash_profile -> 内部加载 ~/.bashrc -> 内部加载 /etc/bashrc -> 内部加载 /etc/profile.d/ 路径下的*.sh脚本;

用户退出时加载 ~/.bash_logout ;

结论:

在 /etc/profile 中配置系统变量;

在 ~/.bash_profile 中配置用户变量;

从工业夹爪到Shadow Hand:一文看懂机器人灵巧手的硬件进化史(附避坑指南) 本文详细解析了机器人灵巧手从工业夹爪到Shadow Hand的硬件进化历程,涵盖刚性夹持器、自适应夹持器到多指灵巧手的技术突破。文章还提供了选购指南与技术避坑策略,帮助读者根据操作复杂度和环境结构化程度选择最适合的解决方案,适用于制造业、医疗和服务业等多个领域。 阅读详情

相关推荐

STM32L151C8T6低功耗实战:RTC闹钟唤醒停机模式的配置与优化

本文详细介绍了如何在STM32L151C8T6微控制器上配置与优化RTC闹钟唤醒停机模式,以实现极致的低功耗设计。文章从核心原理出发,结合STM32CubeMX配置实战,深入讲解了进入停机模式前的关键准备工作、唤醒后的系统恢复流程,并分享了将功耗降至个位数微安级的深度优化技巧与常见问题解决方案。

weixin_29166013的博客 298

linux学习(3)—— linux系统的常用命令

linux系统的常用命令

Archer__13的博客 1405

通讯软件013——分分钟学会Kepware OPC AE Server仿真配置

本文介绍如何使用Kepware软件仿真OPC AE Server配置。

zhouwl72的博客 2226

linux 环境变量配置 cat /etc/profile

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33728268的博客 2943

error C2039: “int_least8_t”: 不是“`global namespace'”的成员

在向H.265的测试软件HM16.0中配置boost的时候,发现 include &lt;boost/cstdint.hpp&gt;的时候总是会报错:错误 11 error C2039: “int_fast16_t”: 不是“`global namespace'”的成员 D:\Program Files\Caffe\VSContact\boost_1_58_0\boost\cstdint.hpp ...

flyerene的博客 1万+

IBIS模型中的Pullup和Pulldown曲线详解:如何避免信号完整性设计中的常见错误

本文深入解析IBIS模型中Pullup和Pulldown曲线的关键作用,揭示其在信号完整性设计中的黄金法则。通过详细分析曲线特性、常见误区及验证方法,帮助工程师避免设计错误,优化高速PCB设计。文章还展示了曲线数据在动态终端匹配、串扰预测和电源完整性分析中的高级应用,提升设计效率和可靠性。

weixin_30275415的博客 447

设置环境变量的三种方法

在shell的命令行下直接使用[export 变量名=变量值] 定义变量,该变量只在当前的shell(BASH)或其子shell(BASH)下是有效的,shell关闭了,变量也就失效了,再打开新shell时就没有这个变量,需要使用的话还需要重新定义。

weixin_43970884的博客 6012

K-L展开 (Karhunen-Loeve expansion)

K-L变换

susan_wang1的博客 2万+

linux /etc/profile $HOME/.bash_profile $HOME/.bashrc $HOME/.bash_login $HOME/.profile文件详解

linux /etc/profile $HOME/.bash_profile $HOME/.bashrc $HOME/.bash_login $HOME/.profile文件详解

hong_yu0315的博客 2726

前端监控性能指标

文章目录前端监控性能指标性能指标阶段性指标关键性能指标小程序W3C Level 1兼容性常规用法注意事项1、计算HTML文档请求使用 Nav Timing2、计算静态资源使用 getEntriesByType('resource') 代替 getEntries()3、secureConnectionStart 问题4、跨域资源设置响应头 Timing-Allow-Origin5、注意属性值为 0 ...

foolbird 1347

基于Python的军事装备信息爬虫实战:Scrapy+Playwright+智能反反爬技术

本文将详细介绍如何使用Python构建一个高效的军事装备信息爬虫系统。我们将从基础的HTTP请求开始,逐步深入到使用Scrapy框架、Playwright浏览器自动化以及最新的反反爬技术。文章包含完整的代码实现、性能优化策略以及数据处理方案,旨在为读者提供一个全面的军事信息爬取解决方案。关键词:Python爬虫、军事装备、Scrapy、Playwright、反反爬。

2201_76125261的博客 1155

Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)

在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容。如果每次都到安装目标文件夹内,找到可执行文件 来进行操作就太繁琐了,这种情况下就涉及到环境变量PATH的设置问题,而PATH的设置也是在linux下定制环境变量的一个组成部分。 环境变量配置的两个方法: 1)修改/etc/profile文件 推荐使用这种方法,因为所有...

魂影魔宅 6780

JAVA:Spring Boot 集成 Atomikos 实现分布式事务

摘要: Atomikos是一款基于JTA标准的分布式事务协调器,通过两阶段提交(2PC)协议实现跨数据库/消息系统的事务一致性,适用于金融等高要求场景。本文以Spring Boot集成Atomikos为例,演示多数据源(订单库、库存库)的分布式事务管理。核心步骤包括:引入Atomikos依赖、配置XA数据源、设置两阶段提交的MyBatis多数据源,并通过Atomikos协调全局事务,确保跨库操作原子性。代码示例涵盖配置类、YAML定义及MySQL XA数据源初始化,为分布式系统提供强一致性解决方案。

木头 334

Linux设置长时间不操作自动断开连接

简单梳理/etc/profile、/etc/bashrc、/etc/profile.d/、~/.bash_profile、~/.bashrcCentOS7系统 1、/etc/profile [root@centos7 ~]# cat /etc/profile /etc/profile System wide environment and startup...

测试0901-1 9896

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

.bash_profile和.bashrc的区别

Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别) 在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容。如果每次都到安装目标文件夹内,找到可执行文件 来进行操作就太繁琐了,这种情况下就涉及到环境变量PATH的设置问题,而PATH的设置...

diqi0762的博客 117

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Shell环境变量配置文件

介绍环境变量配置文件的基本概念和5种类型环境变量配置文件(/etc/profile、/etc/profile.d/*.sh、/etc/bashrc、~/.bash_profile、~/.bashrc)、并深入讲解配置文件加载顺序,在这里我们知道配置文件加载属性顺序,有利于我们全局把控定义配置文件和分析解决问题,接着展开描述了配置文件的加载方式、服务用户对象和登录态区分他们使用场景,最后介绍变量配置文件的特性,如可设置别名、函数等,充分利用特性以此扩展来提高工作效率,通过示例演示日常工作中常用的一些小技巧

Zephyrzh的博客,关注【蚕师】成为大厂技术人 2706

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

《鸟哥的Linux私房菜》重学笔记(六)linux关于bashrc与profile的区别

登入系统读取步骤: 当登入系统时候获得一个shell进程时,其读取环境设定档有三步 : 首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如 /etc/profile.d和/etc/inputrc(此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行) /etc/bashrc:为每一个运行bash shell的用户执行此文件.当ba...

zhougb3的博客 326

mysql bash profile_Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)

在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容。如果每次都到安装目标文件夹内,找到可执行文件来进行操作就太繁琐了,这种情况下就涉及到环境变量PATH的设置问题,而PATH的设置也是在linux下定制环境变量的一个组成部分。环境变量配置的两个方法:1)修改/etc/profile文件推荐使用这种方法,因为所有用户的s...

weixin_30402009的博客 415
上一篇: MongoDB索引深入
下一篇: Linux SVN备份迁移 - dump方式
hellboy0621
博客等级 码龄9年 61粉丝 147原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值