[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

【Linux】コマンドラインにある「~」「$」「#」ってどんな意味?【入門者向け】

どうも、ゲームやアニメをこよなく愛する雑食性オタク、システムソリューション部のinusukiです。

今回は入門者向けにLinuxのCLI(コマンドラインインターフェース)上でよく目にする記号についてここに書き残しておきます。

関連する用語&コマンド集

用語 説明
ディレクトリ ファイルを入れるための入れ物でWindowsでいうとこのフォルダです。

ディレクトリの中に新たにファイルやディレクトリを作ることができます。

階層構造 ディレクトリの中にディレクトリ、その中にディレクトリ・・・という構造のことを指します。

また、木のように枝分かれしていくことから、別名:木構造/ツリー構造と呼んだりします。

ルートディレクトリ 階層構造になっているディレクトリの内、いちばん上にあるディレクトリです。

ルートは(/)として表記されます。

ホームディレクトリ ログインしているユーザーの基点となるディレクトリです。

ユーザーはそのディレクトリ内であれば、基本的自由にファイルやディレクトリを作成することができます。

例えば、dogユーザーを作成した際のホームディレクトリはデフォルトで/home/dogになります。

カレントディレクトリ 現行ディレクトリやワーキングディレクトリとも呼ばれます。

ログインユーザの今いるディレクトリのことを指します。

絶対パス(フルパス) ルートディレクトリから目的地までの経路(パス)のことを指します。
相対パス カレントディレクトリから目的地までの経路(パス)のことを指します。

 

コマンド 説明
cd change directory の略です。

その名の通り、ディレクトリを移動する際に使用します。

pwd print working directory の略です。

ルートディレクトリからカレントディレクトリまでの絶対パスを表示します。

Linux コマンドラインにある記号の意味とは?

こういうヤツですね。

それぞれ解説していきます。

[dog@hostname ~]$

[root@hostname ~]#

「~」

ログインユーザーのホームディレクトリを「~」と省略して表示しています。

dogユーザーのカレントディレクトリがユーザー自身のホームディレクトリ(/home/dog)の場合、表示上は/home/dogではなく「~」になります。

pwdコマンドを使って確認してみましょう。

[dog@hostname ~]$

[dog@hostname ~]$ pwd
/home/dog

比較対象として/var/logに移動します。

[dog@hostname ~]$ cd /var/log
[dog@hostname log]$

hostnameの後が「~」ではなく、「log」になりました(ヤッタネ!)

これはcdコマンドでディレクトリを移動したことによってカレントディレクトリが/var/logに変わったためです。

そのため、pwdコマンドの結果は以下の出力になります。

[dog@hostname log]$ pwd
/var/log

「$」

Linuxにおける「$」には様々な意味や用途がありますが、

CLIの末尾にある「$」は一般ユーザーでコマンドラインを操作していることを表しています。

[dog@hostname ~]$

「#」

CLIの末尾にある「#」は管理者ユーザー(root)でコマンドラインを操作していることを表しています。

僕はこれをハッシュタグと呼んでいた時期がありました。 #駆け出しエンジニア

[root@hostname ~]#

管理者ユーザーと一般ユーザーの違い

主な違いとしては扱える権限レベルの違いです。

管理者ユーザーは標準ですべての権限を持ち合わせていますが、初期の一般ユーザーは限られた権限しか持っていません。

管理者権限で一般ユーザーに権限を付与することができますが、目的にあった最低限の権限を付与することを推奨します。

これを権限運用上の原則の一つで、最小権限の原則(PoLP / Principle of Least Privilege)と呼びます。

 

また、Linuxではユーザーレベルの権限の他にファイルやディレクトリ単位で操作権限を設定することができます。

ここでは説明を割愛しますが、興味があれば「Linux パーミッション」で検索してみてください。

 

ご閲覧ありがとうございました。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
16
読み込み中...
16 票, 平均: 1.00 / 116
8,631
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

inusuki

Joined Beyond as a new graduate in April 2021.
Maybe it's because I have a problem with my output, but sometimes I say strange things.