How to save the output of a Linux command to a file Kā lai saglabātu jaudu Linux komandu failu

by Sukrit Dhandhania on April 8, 2009 ar Sukrit Dhandhania 2009 8.aprīlī

Linux

If you administer a Linux machine it is quite likely that you see a lot of messages fly by on your screen as you run commands. Ja ievadāt Linux mašīna ir diezgan iespējams, ka jūs redzat daudz ziņu lidot uz ekrāna, kā jūs izmantojat komandas. Some of these messages are trivial, while others may be critical. Daži no šiem ziņojumiem ir niecīgs, savukārt citi var būt izšķirīga nozīme. Although Linux and UNIX have a fine logging engine in syslogd and most of the system's messages are logged in a proper log format in various files under he /var/log directory, you might find it useful sometimes to log the output of a command or script that you have run. Kaut gan Linux un Unix soda meža motoru syslogd un lielākā daļa no sistēmas ziņojumi ir iegājis pareizi log formāts dažādu failu zem viņš / var / log direktorijā, jūs varētu atrast noderīgu dažreiz ieiet izejas komandu vai skriptu ka jums ir palaist. Linux provides a number of ways to log the output of your commands. Linux nodrošina vairākus veidus, lai pieteiktos produkciju jūsu komandas.

The simplest, and probably the most common way to do this is to put a greater than sign after a command, followed by the location of the output file. Vienkāršākais un, iespējams, visizplatītākais veids, kā to izdarīt, ir likt lielāku par zīmi pēc komandas, pēc atrašanās vietas izejas failu.

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

The command shown above logs the output of the command ls /var/log into the file /tmp/varlog.log . Komanda norādīts iepriekš apaļkokiem izejas komanda ls / var / log stājas failu / tmp / varlog.log. One thing to note about this command is that if you use a single greater than sign to log the output the output of a command to a file it will create a new file if not already present, or wipe clean, if one is found. Viena lieta ir piezīme par šī komanda ir tā, ka, ja jūs izmantojat vienu lielāks nekā apzīmējumu log produkcijas izlaidi komandu failu, tas radīs jaunu failu, ja nav jau klāt, vai noslaukiet tīru, ja tāds ir atrasts. So, if you want to append the output of the command to a file you need to use two greater than signs instead of one. Tātad, ja jūs vēlaties pievienot izejas komandu failu, jums ir nepieciešams izmantot divas lielāka nekā apzīmējumus, nevis viens. The command shown above needs to be modified to look like this: Komanda norādīts iepriekš, ir jāpārveido, lai izskatās šādi:

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

Linux has a tool aptly named logsave which does a similar task as greater than sign. Linux ir instruments trāpīgi nosaukts logsave, kas nav līdzīgs uzdevums, jo lielāka zīme. You can attain the same result as the first example using the following command: Jūs varat sasniegt tādu pašu rezultātu kā pirmajā piemērā, izmantojot komandu:

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

This command will create a new or overwrite an existing one with the output of the command ls /var/log . Šī komanda izveidos jaunu vai pārrakstīt esošo, ar rezultātu komandu ls / var / log. If you want logsave to append the out to a file instead of writing over it, using it with the -a option: Ja jūs vēlaties logsave to pievienot, lai fails, nevis rakstiski, nekā tam, izmantojot to ar-iespēju:

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

There isn't much of a difference between the greater than and the logsave method. Nav liela atšķirība starp lielāks un logsave metodi. The one thing I noticed was that logsave has a much cleaner output and it also adds the date to the output file. Viena lieta, ko es pamanīju bija tas, ka logsave ir daudz tīrākas ražošanas un tas arī piebilst dienas izejas failu.

Related Posts: Related Posts:
  • Running process in the background with Nohup Running process fona ar Nohup
  • How to monitor your Linux machine with netstat Kā kontrolēt savu Linux mašīna ar netstat
  • How to determine your free disk space in Linux Kā noteikt savu brīvo diska vietu Linux
  • How to recursively copy files from an FTP server with Linux Kā rekursīvi kopēt failus no FTP serveri ar Linux
  • Getting started with iptables in Linux Iesākumam ar iptables Linux
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Get Simple Palīdzība konsultācijas tāpat kā šo vienu savā e-pastā ik dienas - bez maksas! Just enter your email address below: Vienkārši ievadiet savu e-pasta adresi:

    You can always opt out of this email subscription at any time. Jūs vienmēr varat atteikties no šīs e-pasta abonementu jebkurā laikā.

    { 1 trackback } (1 Trackback)

    Come salvare l'output di un comando Linux in un file | 3 sul Blog - Tech, Fun e Web 2.0 Come salvare l'produkcija di un desantnieks Linux un faila | 3 sul Blog - Tech, Fun e Web 2.0
    04.13.09 at 11:58 pm 04.13.09 at 11:58

    { 3 comments… read them below or (3 comments ... lasīt tos zem vai add one pievienot vienu } )

    1 1 kendon 04.09.09 at 12:09 am at 12:09 04.09.09 kendon am

    The one thing I noticed was that logsave has a much cleaner output Viena lieta, ko es pamanīju bija tas, ka logsave ir daudz tīrākas ražošanas

    and what do you mean by that? un ko tu ar to domā? output is output, so either logsave is dismissing parts of the output or it should be the same? produkcija ir, tik nu logsave ir noraidot daļu no produkcijas vai tas būtu pats?

    2 2 Sukrit Sukrit 04.09.09 at 12:21 am 04.09.09 at 12:21

    By cleaner output I mean that the output is organized in a better fashion using whitespace and new lines. Ar tīrākas ražošanas es domāju, ka produkcija ir organizēta labāk veidā, izmantojot atstarpes un jaunu līniju. 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. Un tas, ka logsave iezīmē sākumu un beigām sesijas produkcija ļauj daudz vieglāk atgriezties log failu atkļūdošanas uz vēlāku laiku.

    3 3 John John 04.09.09 at 10:09 pm 04.09.09 at 10:09

    Yes true I agree with Sukrit Jā taisnība, es piekrītu Sukrit

    Leave a Comment Leave 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> Jūs varat izmantot šos HTML tagus un atribūtus: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>