ファイルにLinux命令の出力を救う方法

によって Sukrit Dhandhania [[on]] 2009年4月8日

Linux

Linux機械を管理すれば命令を動かすと同時に多くのメッセージがあなたのスクリーンで過ぎ去るのを見ることはかなり本当らしい。 これらのメッセージのいくつかは他は重大かもしれないが、とるに足らない。 LinuxにおよびUNIXに良い記録エンジンがあるが syslogd そしてシステム・メッセージのほとんどは様々なファイルの適切な丸太のフォーマットを彼ログインされる /var/log 登録簿、それを命令の出力を記録するか、または走ったこと台本を書くこと有用時々見つけるかもしれない。 Linuxはあなたの命令の出力を記録するいくつかの方法を提供する。

これをする最も簡単な、おそらく共通の方法はaを置くことである 以上 出力ファイルの位置に先行している命令の後の印。

# ls /var/log > /tmp/varlog.log

丸太の上で示されている命令命令の出力 ls /var/log ファイルに /tmp/varlog.log. この命令についてのノートへの1つの事は単一を使用すればことである 以上 1つがあったら、ファイルに出力を命令の出力記録する印それは既に現在新しいファイルを作成する、またはきれい拭きなさい。 従ってファイルに命令の出力を付けたいと思えば、2を使用する必要がある 以上 1つの代りの印。 このようになるために変更される必要性の上で示されている命令:

# ls /var/log >> /tmp/varlog.log

Linuxに適切に示される用具がある logsave 同じような仕事をようにするかどれが 以上 印。 次の命令を使用して最初の例と同じ結果を達成できる:

# logsave /tmp/varlog.log ls /var/log

この命令は新しいの作成するか、または命令の出力とのある1つに重ね書きする ls /var/log. ほしければ logsave 出口を、とのそれを使用してそれに書くかわりにファイルに付けるため - a 選択:

# logsave - /tmp/varlog.log ls /var/log

間の相違の多くがない 以上 そして logsave 方法。 私が気づいた1つの事はそれだった logsave 大いによりきれいな出力を持ち、また出力ファイルに日付を加える。

関連のポスト:
  • Nohupの背景の連続したプロセス
  • netstatが付いているあなたのLinux機械を監視する方法
  • How to determine your free disk space in Linux
  • How to find your public IP address with the Linux command line
  • Getting started with iptables in Linux
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 3 comments… read them below or add one }

    1 kendon 04.09.09 at 12:09 am

    The one thing I noticed was that logsave has a much cleaner output

    and what do you mean by that? output is output, so either logsave is dismissing parts of the output or it should be the same?

    2 Sukrit 04.09.09 at 12:21 am

    By cleaner output I mean that the output is organized in a better fashion using whitespace and new lines. And the fact that logsave marks the beginning and end of a session of output makes it a lot easier to return to the log file to debug at a later time.

    3 John 04.09.09 at 10:09 pm

    Yes true I agree with Sukrit

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>