
はじめに
こんにちは!ゆうきです🤗
前回の記事Linuxひとりでできるもん 1はいかがでしたでしょうか?
関連記事になりますのであわせてご覧くださいね。
今回は引き続き仮想Linuxサーバの使い方を紹介していきたいと思います。
バックナンバー💻
●Linuxひとりでできるもん 1 仮想Linuxサーバの起動と停止
本記事では、実機操作を通して情報処理技術の理解を深めることを目的としており、
皆様の環境での動作を保証するものではありません。👀
前回までのおさらい
過去の記事で、Windowsのコンピュータに仮想マシンを作成し、Linuxサーバを動作させました。
「Linuxひとりでできるもん 1」ではその環境の起動と停止方法を実習しましたね。
今回はファイルを使っていきましょう😊
前回、「su -」コマンドでrootユーザになっていましたが、
実は他にも特権ユーザの権限を行使するコマンドはあって、
使用すると次のように表示されます。
[oracle@localhost ~]$ sudo cat /var/log/secure
あなたはシステム管理者から通常の講習を受けたはずです。
これは通常、以下の3点に要約されます:
#1) 他人のプライバシーを尊重すること。
#2) タイプする前に考えること。
#3) 大いなる力には大いなる責任が伴うこと。
[sudo] oracle のパスワード:
このように、特権を行使することには、
プライバシーや責任が伴っていることをよく考えてから作業してください。
特権ユーザにできないことは一切ないからです。
おさらいコーナーにも大切なことを書いてみました🍀
ファイルの見方
前回のLinuxひとりでできるもん 1の通りに手順を実行して、
仮想Linuxサーバの電源を入れてログインしていきましょう。
最初はあまり深く考えずに、以下のコマンドを実行してみてください。
「ls -l」とコマンドを実行して、表示される内容を確認します。
「pwd」とコマンドを実行して、表示される内容を確認します。
「ls -la」とコマンドを実行して、表示される内容を確認します。
[oracle@localhost ~]$ ls -l 合計 0 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ pwd /home/oracle [oracle@localhost ~]$ ls -la 合計 40 drwx------. 15 oracle oracle 4096 4月 23 16:06 . drwxr-xr-x. 3 root root 20 3月 10 08:34 .. -rw-------. 1 oracle oracle 1248 4月 21 10:08 .ICEauthority -rw-------. 1 oracle oracle 313 4月 23 11:05 .bash_history -rw-r--r--. 1 oracle oracle 18 8月 24 2018 .bash_logout -rw-r--r--. 1 oracle oracle 193 8月 24 2018 .bash_profile -rw-r--r--. 1 oracle oracle 231 8月 24 2018 .bashrc drwx------. 14 oracle oracle 4096 4月 20 17:25 .cache drwxr-xr-x. 14 oracle oracle 4096 3月 10 08:35 .config drwx------. 3 oracle oracle 25 3月 10 08:34 .dbus -rw-------. 1 oracle oracle 16 3月 10 08:34 .esd_auth drwx------. 3 oracle oracle 19 3月 10 08:34 .local drwxr-xr-x. 4 oracle oracle 39 3月 10 07:54 .mozilla -rw-------. 1 oracle oracle 1145 4月 23 16:06 .viminfo drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$
「ls -l」を実行すると、カレントディレクトリ(現在操作の基準となるディレクトリ)
のファイルおよびディレクトリが詳細リスト形式で表示されます。
「pwd」を実行すると、
カレントディレクトリのパスが表示されます。
「ls -la」を実行すると、
ファイル(ディレクトリ)名が「.」で始まるファイル(ディレクトリ)を無視しないで表示します。
「.」で始まるファイルは「隠しファイル(ディレクトリ)」で、
lsコマンドにオプションを付けることで見えるようになります。
その他に、「.」はカレントディレクトリのことで、
「..」はカレントディレクトリの上の階層のディレクトリのことです。
初めて見る方は、情報が多くて何が表示されているのかわかりづらいですよね😣
Linuxを使っているうちにだんだん見方がわかってくるので、
最初は一番右のファイル(ディレクトリ)名を見ればいいと思います。
ファイルなのかディレクトリなのかを判断するときは、
一番左の文字が「d」ならディレクトリ、「-」ならファイルです。
この2点をおさえておけば、入門編として十分です。
ファイルの作り方
「touch」というコマンドをオプションを指定せずに使用すると、
空ファイルを作成することができます。
実際にやってみましょう。
「ls -l」とコマンドを実行して、カレントディレクトリに作成予定のファイルがないことを確認します。
「touch db_hitoride_dekirumon.dat」とコマンドを実行して、空ファイルを作成します。
「ls -l」とコマンドを実行して、ファイルが作られたことを確認します。
[oracle@localhost ~]$ ls -l 合計 0 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ touch db_hitoride_dekirumon.dat [oracle@localhost ~]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 09:07 db_hitoride_dekirumon.dat drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$
ディレクトリの作り方とカレントディレクトリの移動
「mkdir <ディレクトリ名>」とコマンドを実行すると、ディレクトリが作成されます。
「ls -l <ディレクトリ名>」とコマンドを実行すると、ディレクトリ内のファイル情報が表示されます。
「cd <ディレクトリ名>」とコマンドを実行すると、カレントディレクトリを、指定したディレクトリに変更します。
[oracle@localhost ~]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 09:07 db_hitoride_dekirumon.dat drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ mkdir dekirumon [oracle@localhost ~]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 09:07 db_hitoride_dekirumon.dat drwxrwxr-x. 2 oracle oracle 6 4月 24 10:45 dekirumon drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ ls -l dekirumon 合計 0 [oracle@localhost ~]$ touch ./dekirumon/db_dekirumon.txt [oracle@localhost ~]$ ls -l dekirumon 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 10:45 db_dekirumon.txt [oracle@localhost ~]$ cd dekirumon [oracle@localhost dekirumon]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 10:45 db_dekirumon.txt [oracle@localhost dekirumon]$ pwd /home/oracle/dekirumon [oracle@localhost dekirumon]$
先に紹介した通り、「..」はカレントディレクトリの上の階層のディレクトリです。
これを「cd」コマンドと組み合わせて使ってみましょう❗
[oracle@localhost dekirumon]$ cd .. [oracle@localhost ~]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 09:07 db_hitoride_dekirumon.dat drwxrwxr-x. 2 oracle oracle 30 4月 28 09:53 dekirumon drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ pwd /home/oracle [oracle@localhost ~]$
コマンドを利用するときは、意味を理解しておくと、
知識を組み合わせて便利に使うことができます。
一時的にほかのディレクトリに移動しなければならない場合や、
間違えてディレクトリを移動してしまったときに便利なコマンドがあります。
「cd」で移動するひとつ前のカレントディレクトリに戻りたいときは、
「cd -」と入力して戻ることができます。
また、「cd」コマンドで移動先を指定せずに実行すると、ホームディレクトリに移動することができます。
実際にやってみましょう。
[oracle@localhost dekirumon]$ cd /var/tmp [oracle@localhost tmp]$ ls -l 合計 0 drwxr-xr-x. 2 abrt abrt 6 3月 10 08:21 abrt drwx------. 3 root root 17 4月 24 07:47 systemd-private-7dc76a6dd9a34329b29269e69ff22b67-bolt.service-QHkaYt drwx------. 3 root root 17 4月 24 07:46 systemd-private-7dc76a6dd9a34329b29269e69ff22b67-chronyd.service-ka2NSK drwx------. 3 root root 17 4月 24 07:47 systemd-private-7dc76a6dd9a34329b29269e69ff22b67-colord.service-Sat8Vc drwx------. 3 root root 17 4月 24 07:47 systemd-private-7dc76a6dd9a34329b29269e69ff22b67-cups.service-Cx0jAf drwx------. 3 root root 17 4月 24 07:46 systemd-private-7dc76a6dd9a34329b29269e69ff22b67-rtkit-daemon.service-Hrb3oB [oracle@localhost tmp]$ pwd /var/tmp [oracle@localhost tmp]$ cd - /home/oracle/dekirumon [oracle@localhost dekirumon]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 10:45 db_dekirumon.txt [oracle@localhost dekirumon]$ pwd /home/oracle/dekirumon [oracle@localhost dekirumon]$ cd [oracle@localhost ~]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 24 09:07 db_hitoride_dekirumon.dat drwxrwxr-x. 2 oracle oracle 30 4月 24 10:45 dekirumon drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ダウンロード drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 テンプレート drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 デスクトップ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ドキュメント drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 ビデオ drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 音楽 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 画像 drwxr-xr-x. 2 oracle oracle 6 3月 10 08:35 公開 [oracle@localhost ~]$ pwd /home/oracle [oracle@localhost ~]$
見ていて気付いた方もいらっしゃるかと思いますが、
プロンプトの「]」の左に書いてある単語は、
カレントディレクトリのディレクトリ名です。
そのため、ホームディレクトリに戻ってくると「~」と表示されていますが、
ホームディレクトリはチルダ(~)で表現できます。
実際に使ってみると次のようになります。
[oracle@localhost ~]$ cd ~/dekirumon [oracle@localhost dekirumon]$ ls -l 合計 0 -rw-rw-r--. 1 oracle oracle 0 4月 28 09:53 db_dekirumon.txt [oracle@localhost dekirumon]$ pwd /home/oracle/dekirumon [oracle@localhost dekirumon]$
おわりに
苦手意識を持たれる方も多いコマンド操作ですが、
説明があれば、実は極端に難しいわけではないと思っていただけましたでしょうか。
次回の記事では、もう少しステップアップしたいと思っているので、
しっかり復習して、コマンドマスターになっていきましょうね😀
投稿者プロフィール

-
「親しみやすさと技術力」をテーマに、技術情報・サービス・インフラ系資格取得に役立つ情報、社員等の情報をお届けします。
90名強の事業部員で鋭意、執筆中です。
少しでも当社を知って頂けるよう、愛情込めて頑張ります!
※facebook、X(旧twitter)、インスタグラムでは「DBひとりでできるもん」の更新情報を発信しています。
最新の投稿
Oracle Cloud2025年12月23日Oracle Cloud Infrastructure 2025 Certified Architect Associateを取得しました!
資格取得2025年12月19日Oracle Cloud Infrastructure 2025 Certified Foundations Associate、Oracle Cloud Infrastructure 2025 Certified AI Foundations Associate、Oracle Data Platform 2025 Certified Foundations Associateを取得しました!
お知らせ2025年12月17日第 14 回 NIPPON ITチャリティ駅伝に参加しました!
AIメディアブースト2025年12月11日チャットボット導入時の課題を解決!AIメディアブーストで手軽に高性能AIチャットボットを実装!




