Save output to a text file from Mac terminal

 

Simply with output redirection:

system_profiler > file.txt

Basically, this will take the output of system_profiler and save it to the file file.txt. There are technically two different output "streams", standard output, and standard error. They are treated separately, and if you use the simple redirection method above, you will only redirect standard output to the file. If you want to redirect both standard output and standard error, you could do this:

system_profiler &> file.txt

The & tells the shell to redirect the standard output and standard error to the file.

If you want to just output standard error, you can do this:

system_profiler 2> file.txt

The 2 lets the shell know that it needs to only redirect standard error.

Using the > will overwrite the file if it‘s already there. If you want to append it to a file without erasing the old one, you can use >>, like so:

system_profiler >> file.txt

You can of course use the & and 2 for sending both standard out and standard error, and just standard error with the >> operator.

Save output to a text file from Mac terminal

时间: 2024-11-05 23:35:17

Save output to a text file from Mac terminal的相关文章

create feature from text file

'''---------------------------------------------------------------------------------- Tool Name: CreateFeaturesFromTextFile Source Name: CreateFeaturesFromTextFile.py Version: ArcGIS 9.1 Author: Environmental Systems Research Institute Inc. Required

What is a text file and what is a binary file :)

If you are not coming from a programming background it might not yet be clear what is really a file? What is a binary file and what makes something a text file? 其实总归一句话:[Files that consist exclusively of ASCII characters are known as text ?les. All o

How to find a specific string in a text file?

How to find a specific string in a text file? how i did it: i store the whole contents of the .txt file in a single string, close the file, and then, split the string, based on searching a specific character: a | bar. text file test.txt: helloooooooo

How to remove duplicate lines in a large text file?

How would you remove duplicate lines from a file that is  much too large to fit in memory? The duplicate lines are not necessarily adjacent, and say the file is 10 times bigger than RAM. A better solution is to use HashSet to store each line of input

shell脚本执行时报"bad interpreter: Text file busy"的解决方法

在执行一个shell脚本时,遇到了"-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy"错误提示,如下所示: [[email protected] bin]$ ./killSession.sh      -bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy 此时只需要在#!/bin/bash,加一空格#! /bin/bas

Writing Text File From A Tabular Block In Oracle Forms

The example given below for writing text file or CSV using Text_IO package from a tabular block in Oracle Forms. Suppose there is a tabular grid data block "Job_History" in your forms and you want to write a CSV on click of a button by reading w

SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell

导出到txt [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") [void][System.Reflection.Assembly]::LoadWithParti

【转】shell脚本执行时报"bad interpreter: Text file busy"的解决方法

1)问题现象: 在ubuntu下执行以下脚本( while_count),报错: -bash: ./while_count: /bin/bash: bad interpreter: Text file busy 2)问题原因: This happens because the script file is open for writing, possibly by a rogue process which has not terminated. 3)解决办法: Solution: Check

unity, read text file

using System.IO; //test read txt        //Resources.Load(...) loads an asset stored at path in a Resources folder.        //ref: http://docs.unity3d.com/Manual/class-TextAsset.html        //ref: http://forum.unity3d.com/threads/read-text-file-that-is