0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Day3:ファイル内容を表示する(cat / less / head / tail)

0
Posted at

LPIC-1 100日チャレンジ Day3

ファイル内容を表示する(cat / less / head / tail)


🎯 今日のゴール

  • ファイル内容を表示する主要コマンドを理解する
  • それぞれの違いを説明できる
  • 大きなファイルを安全に閲覧できる

📌 ① cat コマンド

🔹 役割

ファイルの内容を一気に表示する。


cat ファイル名

例:


cat /etc/hosts

🔹 注意点

  • 大きなファイルには不向き(全部表示される)

📌 ② less コマンド

🔹 役割

ファイルをスクロールしながら閲覧できる。


less ファイル名

🔹 操作方法

キー 動作
Space 次ページ
b 前ページ
/文字列 検索
q 終了

例:


less /var/log/syslog


📌 ③ head コマンド

🔹 役割

ファイルの先頭を表示する。


head ファイル名

🔹 行数指定


head -n 20 ファイル名

→ 先頭20行表示


📌 ④ tail コマンド

🔹 役割

ファイルの末尾を表示する。


tail ファイル名

🔹 行数指定


tail -n 20 ファイル名

🔹 リアルタイム監視(超重要)


tail -f ファイル名

ログ監視で頻出。


🧠 コマンドの使い分け

コマンド 用途
cat 小さいファイル
less 大きなファイル
head 先頭確認
tail 末尾確認
tail -f ログ監視

💻 今日の実践


cat /etc/passwd
less /etc/passwd
head -n 5 /etc/passwd
tail -n 5 /etc/passwd


🧪 Day3 確認テスト

【選択問題】

Q1

大きなファイルをスクロールしながら閲覧するコマンドは?

A. cat
B. less
C. head
D. tail


Q2

ファイルの末尾を表示するコマンドは?

A. head
B. cat
C. tail
D. less


Q3

ログファイルをリアルタイムで監視するオプションは?

A. -r
B. -l
C. -f
D. -a


【記述問題】

Q4

catとlessの違いを説明せよ。



✅ 解答

Q1:B
Q2:C
Q3:C

Q4例:
catはファイルを一括表示する。
lessはスクロールや検索が可能で大きなファイルに適している。


🔥 明日のテーマ

grep と正規表現
(検索の最重要分野)


#LPIC #Linux #資格勉強 #100日チャレンジ #Qiita

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?