GNU/Linux >> Linux の 問題 >  >> Linux

テールコマンドの使用方法

はじめに

テール :UNIXシステムまたはUNIXライクなオペレーティングシステムに組み込まれているコマンド:

  • 386BSD。
  • ArchLinux。
  • AIX。
  • Android。
  • BSD NET/2。
  • Debian。
  • DragonFlyBSD。
  • GNUHurd。

使用法 :テキストファイルの最下行またはバイト、あるいはパイプされたデータの終わりを表示するために使用されます。

ヘッドコマンドを補完するものです

使い方は?

  • これを使用して、システムログのような大きなテキストファイルの末尾を表示できます。
  • デフォルトで最後の10行を読み取ることができます:
tail /var/log/user.log
  • または、表示する必要のある行数を指定できます。
tail -n 2  /var/log/user.log
tail --lines=2  /var/log/user.log

ヒント :–lines=行数=== -n行数

出力:

root@unixcop:~# tail --lines=2  /var/log/user.log
Oct  2 14:09:08 unixcop firefox-esr[2370]: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
Oct  2 14:09:08 unixcop firefox-esr[2370]: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
root@unixcop:~# 

  • テキストファイルからバイトを表示できます
  • バイトは1文字を意味します..10文字のテキストファイルを作成します
echo "--9LASTCHAR"> ~/bytes.txt
  • 次に、テールを使用して最後の8文字を表示します
tail -c 10 ~/bytes.txt
tail --bytes=9 ~/bytes.txt

出力:

root@unixcop:~# tail --bytes=10 ~/bytes.txt
9LASTCHAR
root@unixcop:~# 
  • tailを使用してさまざまなファイルから読み取ることができます
  • このオプションを比較に使用できます。
tail -q unix.txt cop.txt 
tail --quiet  unix.txt cop.txt
  • tail with option verboseを使用して、上記のファイル名でファイルのコンテンツを表示できます
tail -v unix.txt 
tail --verbose unix.txt 

出力:

==> unix.txt <==
Name         Email 
Mostafa      [email protected]

冗長オプションと静かオプションをマージして、それらの使用法を明確にします

出力:

root@unixcop:~# tail --quiet --verbose unix.txt cop.txt 
==> unix.txt <==
Name         Email 
Mostafa      [email protected]

==> cop.txt <==
Name         Email 
Mostafa      [email protected]
root@unixcop:~# 
  • パイプラインで使用できます
cat /var/log/user.log | tail -n 3
ls -lah /root | tail -n 5
  • ここでは、tailを使用してコマンドの結果をテキストファイルに保存できます
cat /var/log/user.log | tail -n 3 > output.txt

出力:

root@unixcop:~# cat /var/log/user.log | tail -n 3 > output.txt
root@unixcop:~# cat output.txt 
Oct  2 14:08:55 unixcop firefox-esr[2370]: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
Oct  2 14:09:08 unixcop firefox-esr[2370]: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
Oct  2 14:09:08 unixcop firefox-esr[2370]: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
root@unixcop:~# 
  • 次のように入力すると、テールバージョンを知ることができます:
tail --version 
  • さらにヘルプが必要な場合は、このオプションを使用できます:
tail --help 

結論:

この記事では、実際の例を使用して、tailコマンドの使用方法を明確にします。

For more Information use : man tail

Linux
  1. LinuxでSuコマンドを使用する方法

  2. tailコマンドを使用してログをリアルタイムで表示する方法

  3. basenameコマンドの使用方法は?

  1. WindowsでTelnetを使用する方法

  2. Linux Catコマンドの使用方法(例付き)

  3. Linux screen コマンドの使用方法

  1. LinuxでDisownコマンドを使用する方法

  2. LinuxSSコマンドの使用方法

  3. Linuxnohupコマンドの使用方法