コマンドでファイル内容を表示

当ページのリンクには広告が含まれています。

スポンサーリンク

コマンドでのファイル内容を表示する方法を紹介します。

Linuxには設定ファイルなどのテキストベースのファイルがたくさんあるので、それらの内容を表示しなければならない場合が多くあります。

そんなときは! いくつかのコマンドを使い分け、ササッと必要な情報を閲覧しましょう。

コマンドでのファイル内容を表示

それでは実際にファイル内容を表示してみましょう。

まずは、catコマンドを使ってみましょう。

$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l

すると、このようにファイル内容をササッと表示することができます。

ただし! ファイルの文章が長い場合は

$ cat /etc/ssh/sshd_config 
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
...

必要な情報を通り過ぎてしまいます。

そんなときは……

moreコマンドを使ってみましょう。

$ more /etc/ssh/sshd_config 
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
...

「Enter」キーで、ページを送りながらファイルを閲覧することができます。

ファイルの末尾だけを見たい場合は、tailコマンドを使ってみましょう。

$ tail /etc/ssh/sshd_config 
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

基本操作 の人気記事

  1. コマンドの実行結果・標準出力をファイルに保存
  2. パイプ「|」を使って 複数のコマンドを組み合わせる
  3. ワイルドカードの使い方
  4. コマンドで システムをシャットダウン(システムの終了)
  5. コマンドラインの操作(カーソル移動・文字削除・補完)
  6. セミコロンを使って、複数のLinuxコマンドを続けて実行
  7. コマンドの入力・実行
  8. コマンド - ファイルのコピーと移動

関連記事(一部広告含む)