Store the result of a Linux order to a record

 Store the result of a Linux order to a record



Ordinarily, while dealing with a Linux terminal, you might need to save the result of an order to a document. The following are 4 distinct manners by which to save terminal substance in a document.

This record can be utilized as data for another activity or to log terminal movement. The following are 4 distinct manners by which to save terminal substance in a document.

The accompanying strategies are material on all Linux conveyances and might actually be utilized on Macs and BSDs. The main thing you need to consider is which technique is ideal to take care of business.

1. Utilize the redirection administrator

The most essential and well known method for diverting result from the terminal to a record is to utilize the > and >> administrators. They divert result to a predetermined text document.

The > administrator diverts the result to a document and overwrites the items in that record while the >> administrator attaches the result to the furthest limit of the document. Here is an illustrative model:

First make a document utilizing the touch order.

Presently, a line is embedded into 'file1.txt' utilizing the > administrator. This can be considered unloading the result of the reverberation order into 'file1.txt'.

reverberation "first articulation" > file1.txt
A different line is remembered for 'file1.txt'.

reverberation "second articulation" > file1.txt
While review the items in 'file1.txt', we see that main the subsequent line is put away in the record. This is on the grounds that the > administrator overwrites the current document contents.

If you have any desire to add content to the document, the >> administrator should be determined.

If you simply have any desire to save the mistake, utilize the 2> and 2>> administrators all things considered.

In the event that you care about logging everything, use &> and &>> to divert all result (counting blunders) to a document without showing anything in the terminal.

2. Utilize the tee order

With the redirection administrators displayed over, the result of the order isn't shown on the screen. In the event that you believe it should show the result on the terminal and keep in touch with a record, you can utilize the tee order.

| tee - a
Symbol | pass the result of the order as contribution to tee, in this way showing the result on the screen. On the off chance that switch - an is determined, tee will add that result to the predetermined document, if not it will overwrite the items in that record.

You can likewise utilize the |& administrator and the tee order to show all that and log it.

|& tee - a

3. Utilizing the content order

With the content order, the result of orders entered after it is naturally kept in touch with a record until provoked to stop. This can be compared to a meeting that records terminal action.

In the first place, the content order is called with the name of the record to store the terminal action.

script
A message prompts that the content has begun, then the orders are composed consistently - date, pwd, ls and cal.


To end, the leave order is called. There is a message that the 'script' activity has finished. View the items in 'script_log.txt' utilizing feline. It very well may be seen that the items in the record resemble a precise duplicate of the terminal.


In any case, just when this document is seen in the shell with the feline order, will we get totally reasonable data. So attempt another other option, save the terminal result in '2-script_log.txt'.

Commandspwd and ls are placed.

Without composing exit, the terminal window is shut. While survey the items in '2-script_log.txt', you will consider it to be vacant.

At the point when a content meeting is begun, the items in that meeting are kept in memory and kept in touch with the record just when the leave order is called. Here, since exit isn't called, the items in that meeting are not saved to '2-script_log.txt'.

The content's superseding and affixing conduct is like the divert administrators and the tee order. Switch - an affixss the meeting's items to the beforehand existing document. Here, the result of the reverberation order is attached to 'script_log.txt'.

You can see the recently saved result of the date, pwd, ls, cal orders, trailed by timestamp; then data about the following meeting (finishing with timestamp).

4. Utilize the logave order

logave works like tee - it shows the result on the screen and furthermore saves to a record. It is utilized as underneath:

logsave
logave composes the result of the commandto the document indicated by . Investigate the result of 'mylog_file.txt'.

There is a great deal of data put away with the consequence of an order. Two timestamps are put away here: The first is the point at which the order was begun, and the second is the time at which the order finishes execution.

The result of various orders can be added to a similar record when switch - an is utilized with logave.

logsave - a
While survey the items in mylog_file.txt, you will see that the result of the two recently entered orders is delimited by a solitary line.

Post a Comment

Previous Post Next Post