システム環境構築に関する記事を掲載していきます!
  • トップ
  • サイト案内
  • お問い合わせ
  • サイトマップ
  • ランキング
SEARCH
LAB4ICT
  • トップ
    Top
  • ブログ
    Blog
  • システム
    System
  • サービス
    Service
  • 応用技術
    Tech
  • アート
    Art
SEARCH
LAB4ICT
  • トップ
    Top
  • ブログ
    Blog
  • システム
    System
  • サービス
    Service
  • 応用技術
    Tech
  • アート
    Art
  • トップ
    Top
  • ブログ
    Blog
  • システム
    System
  • サービス
    Service
  • 応用技術
    Tech
  • アート
    Art
Topics ライブカメラによる動画配信を開始しました!(横浜から富士山を眺める!/YouTube)
  • ホーム
  • OS - Linux
  • Commands
  • Login Session
  • Linuxのbashの全ユーザ用の設定ファイルの内容を確認する!
Login Session

Linuxのbashの全ユーザ用の設定ファイルの内容を確認する!

2023-02-10 2023-02-10
  • Webmaster
  • Webmaster
Linuxのbashの全ユーザ用の設定ファイルの内容を確認する!

Linuxのbashの全ユーザ用の定義ファイルを確認します。RHEL 8.4の内容を確認してみます。

記事の目次

  • 1 「/etc/profile」の内容を確認する!
  • 2 「/etc/bashrc」の内容を確認する!
  • 3 おわりに
  • 4 関連記事
  • 5 関連書籍(Amazon)

「/etc/profile」の内容を確認する!

「/etc/profile」には、主要な環境変数の定義が行われています。「/etc/profile」は、「/etc/bashrc」を呼び出します。

$ 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

if [ -n "${BASH_VERSION-}" ] ; then
        if [ -f /etc/bashrc ] ; then
                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc
                # Check for double sourcing is done in /etc/bashrc.
                . /etc/bashrc
       fi
fi

「/etc/bashrc」の内容を確認する!

「/etc/bashrc」は、「/etc/profile」から呼び出されます。全ユーザに設定するエイリアスや関数が定義されています。

$ 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.

# Prevent doublesourcing
if [ -z "$BASHRCSOURCED" ]; then
  BASHRCSOURCED="Y"

  # 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 gets 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

fi
# vim:ts=4:sw=4

おわりに

「/etc/profile」、「/etc/bashrc」は、各ユーザで必ず実行されます。1度しっかり確認しておくと、シェル環境に関する理解が深まると思います。

関連記事

【記事一覧】Linuxにログインしてコマンド操作を行う!
【記事一覧】Linuxにログインしてコマンド操作を行う!
Linuxにログインして、コマンド操作を行うための記事一覧を掲載します!...
【記事一覧】Linuxを使いこなす!
【記事一覧】Linuxを使いこなす!
Linuxを使いこなすための記事一覧を掲載します。...

関連書籍(Amazon)

N/A


 

Facebook postはてブLINEPocketFeedly
Login Sessionの関連記事
  • Linuxでターミナルの機能を拡張する!(tmux/セッションの復活)
    Linuxでターミナルの機能を拡張する!(tmux/セッションの復活)
    2023-08-15
  • Linuxでbashコマンドのヘルプを表示する!(help)
    Linuxでbashコマンドのヘルプを表示する!(help)
    2023-02-21
  • Linuxで特定の端末(tty)にメッセージを送信する!(write)
    Linuxで特定の端末(tty)にメッセージを送信する!(write)
    2023-02-16
  • Linuxで終了文字列を指定してテキストを標準入力にリダイレクトする!(cat/<< [終了文字列])
    Linuxで終了文字列を指定してテキストを標準入力にリダイレクトする!(cat/<< [終了文字列])
    2023-02-16
  • Linuxでターミナルの表示をクリアする!(clear)
    Linuxでターミナルの表示をクリアする!(clear)
    2023-02-15
  • Linuxでログイン中の全ユーザにメッセージを送信する!(wall)
    Linuxでログイン中の全ユーザにメッセージを送信する!(wall)
    2023-02-14
記事の検索(システム)
Generic selectors
完全一致
タイトル検索
本文検索
Post Type Selectors
関連記事(システム)
  • 【記事一覧】Linuxにログインしてコマンド操作を行う!

    2023-01-14

  • Linuxで正しいログイン先にログインしたことを確認する!(hostname/id/date/script)

    2023-01-14

  • Linuxの便利なコマンド入力方法を活用する!(bash:コマンド履歴/補完)

    2023-01-14

  • Linuxのコマンドラインで計算する!(bc)

    2023-01-21

  • Linuxのコマンドラインでカレンダーを表示する!(cal)

    2023-01-21

  • Linuxでテキストの内容を連続で処理する!(パイプ「|」でコマンドをつなげる!)

    2023-01-30

  • Linuxでコマンドの出力結果をリダイレクトする!(「>」でファイルに出力する!)

    2023-01-31

  • Linuxのコマンドラインで秒単位で時刻を表示する!(date)

    2023-02-04

  • Linuxでログインしたシステムの稼働状況を確認する!(uptime)

    2023-02-04

  • Linuxでログイン/ログアウトする!(CUI)

    2023-02-04

  • Linuxで標準出力をファイルにリダイレクトする!(exec >)

    2023-02-07

  • Linuxでコマンドプロンプトを変更する!(bash/PS1)

    2023-02-08

  • Linuxで使用中の端末を確認する!(tty)

    2023-02-09

  • Linuxのbashのユーザ用の設定ファイルの内容を確認する!

    2023-02-10

  • Linuxのbashの全ユーザ用の設定ファイルの内容を確認する!

    2023-02-10

記事の閲覧数(システム)
  • 496今日の閲覧数:
  • 246昨日の閲覧数:
  • 374今日の訪問者数:
  • 157昨日の訪問者数:
カテゴリー(システム)
  • Admin - Config 15
    • Tools 8
      • Ansible 8
    • VCS 6
      • Git 5
      • GitLab 1
  • Admin - Monitor 18
    • Hinemos 6
    • Logwatch 1
    • Prometheus 5
    • Zabbix 5
  • Admin - Remote 29
    • Cockpit 8
    • SSH 9
    • VNC 8
    • Wake on LAN 3
  • AI 13
    • Anaconda 1
    • PyTorch 5
    • Stable Diffusion 3
    • TensorFlow 3
  • App - Desktop 5
    • Document 2
    • Mail 1
    • Web Browser 1
  • App - Server 38
    • Bitnami 6
    • WordPress 12
  • Cloud 104
    • AWS 98
      • AWS Network 8
      • AWS Topics 10
      • Certification 10
      • Computing 5
      • Monitoring 3
      • Operation 25
      • Organization 3
      • Start Using 13
      • Storage 1
      • VDI 19
    • Azure 3
    • GCP 2
  • Container 17
    • Docker 10
    • Kubernates 6
  • Database 57
    • DB Server 51
      • Db2 14
      • MariaDB 10
      • MongoDB 12
      • PostgreSQL 15
    • DB Tools 5
      • A5M2 2
      • DBeaver 3
  • Development 13
    • IDE 9
      • Android Studio 6
      • Eclipse 2
    • Language 4
      • Java 1
      • JavaScript 2
      • TypeScript 1
  • Hardware 15
    • 3D Printer 3
    • GPU 5
    • PC 6
      • Firmware 6
  • IoT 14
    • Raspberry Pi 13
  • Network 26
    • Cisco 13
    • Voice Over IP 5
    • VPN 6
      • OpenVPN 6
  • OS - Debian 120
    • Debian 6
      • Debian 12 4
    • Ubuntu 113
      • Ubuntu Desktop 16.04 5
      • Ubuntu Desktop 18.04 20
      • Ubuntu Desktop 20.04 15
      • Ubuntu Desktop 22.04 48
      • Ubuntu Server 4
      • Ubuntu Topics 20
        • Ubuntu Packages 6
        • Ubuntu Security 3
  • OS - Linux 247
    • Commands 210
      • Account 17
      • Analyze 3
      • Configurations 12
      • Data Processing 45
      • Devices 5
      • Files 24
      • Filesystem 12
      • Login Session 22
      • Memory 4
      • Monitoring 10
      • Network 24
      • Performance 4
      • Process 8
      • Scheduler 4
      • Systemd 10
      • Text Editor 5
    • Hardware 4
    • Linux Topics 5
    • Shell Script 27
  • OS - RHEL 59
    • CentOS Stream 8 1
    • RHEL 8 12
    • RHEL 9 5
    • RHEL Topics 40
      • RHEL Packages 24
      • RHEL Security 3
      • RHEL Support 9
  • OS - Windows 99
    • Windows Desktop 80
      • Windows 10 23
      • Windows 11 50
      • Windows 7 7
    • Windows Server 3
    • Windows Topics 15
      • Account 1
      • Information 1
      • PowerShell 4
      • Tools 3
  • Security 18
    • CIS Benchmarks 3
    • Network Security 2
    • PKI 12
      • GnuPG 11
      • OpenSSL 1
  • Test Tools 6
    • JMeter 1
    • Test Data 3
  • Topics 16
    • Lab4ict 12
  • Virtualization 54
    • VM Desktop 41
      • Hyper-V Desktop 17
      • virt-manager 3
      • VirtualBox 15
      • VMware Player 5
    • VM Server 12
      • Hyper-V Server 5
      • VMware vSphere 6
アーカイブ(システム)
<
5月 2025
  • 5月 2025
  • 3月 2025
  • 10月 2024
  • 9月 2024
  • 8月 2024
  • 4月 2024
  • 2月 2024
  • 1月 2024
  • 12月 2023
  • 10月 2023
  • 9月 2023
  • 8月 2023
  • 7月 2023
  • 6月 2023
  • 5月 2023
  • 4月 2023
  • 3月 2023
  • 2月 2023
  • 1月 2023
  • 12月 2022
  • 11月 2022
  • 10月 2022
  • 5月 2022
  • 4月 2022
  • 3月 2022
  • 1月 2022
  • 12月 2021
  • 10月 2021
  • 6月 2021
  • 5月 2021
  • 4月 2021
  • 3月 2021
  • 2月 2021
  • 1月 2021
  • 12月 2020
  • 11月 2020
  • 5月 2020
  • 4月 2020
  • 3月 2020
  • 2月 2020
  • 1月 2020
  • 12月 2019
  • 11月 2019
  • 10月 2019
  • 6月 2019
  • 5月 2019
  • 3月 2019
  • 9月 2018
  • 8月 2018
  • 1月 2018
  • 12月 2017
▼
>
月火水木金土日
   1234
567891011
12131415161718
19202122232425
262728293031 
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
 123456
78910111213
14151617181920
21222324252627
28293031   
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
   1234
567891011
12131415161718
19202122232425
262728293031 
       
1234567
891011121314
15161718192021
22232425262728
2930     
       
   1234
567891011
12131415161718
19202122232425
26272829   
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
     12
3456789
10111213141516
17181920212223
24252627282930
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
  12345
6789101112
13141516171819
20212223242526
2728     
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
   1234
567891011
12131415161718
19202122232425
262728293031 
       
 123456
78910111213
14151617181920
21222324252627
282930    
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
 123456
78910111213
14151617181920
21222324252627
282930    
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
1234567
891011121314
15161718192021
22232425262728
       
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
    123
45678910
11121314151617
18192021222324
25262728293031
       
  12345
6789101112
13141516171819
20212223242526
27282930   
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
     12
3456789
10111213141516
17181920212223
242526272829 
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
     12
3456789
10111213141516
17181920212223
24252627282930
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
     12
3456789
10111213141516
17181920212223
24252627282930
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
  • トップ
  • サイト案内
  • お問い合わせ
  • サイトマップ
  • ランキング

(C) 2017-2025 LAB4ICT All Rights Reserved.

Generic selectors
完全一致
タイトル検索
本文検索
Post Type Selectors