tags:

views:

50

answers:

4

The character > (or >>) can be used with a command in Windows to log results of a command to file. Does Linux have this ability? How do you do it?

Example: $ find /?>find.txt

This command will make a file named find.txt in the current directory. This file will contain exactly what is found in the term window after typing the command:

Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  /V         Displays all lines NOT containing the specified string.
  /C         Displays only the count of lines containing the string.
  /N         Displays line numbers with the displayed lines.
  /I         Ignores the case of characters when searching for the string.
  /OFF[LINE] Do not skip files with offline attribute set.
  "string"   Specifies the text string to find.
  [drive:][path]filename
             Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
+1  A: 

Yes, you can redirect output from a command using > or >> in the shell on Linux as well. See the section on redirection in your shell documentation (link goes to the POSIX standard, other shells may support more advanced types of redirection).

echo "This is a test" > file.txt

If you want to print output to both a file and the terminal, you can use tee:

echo "This is a test" | tee file.txt

Note that given the document you link to, grep is probably the closest equivalent to the find command listed. find on Linux/Unix will recursively search for files with names or other metadata matching conditions given; grep will search through a single file for lines matching a given pattern.

Brian Campbell
your redirection link is helpful, thanks! If I could give you a vote, I would. Alas, my reputation is only 9 and I have to have 15 before being able to vote.
Captain Claptrap
+1  A: 

Yes, and it looks the same:

find --help > find.txt  # write to a new file
find --help >> find.txt # append to the file
eumiro
+4  A: 

It works the same way in Linux. > will overwrite the output file, >> will append to it. Some programs will print errors to STDERR, which you can capture using 2>. Sometimes you will see STDERR redirected to the same location as STDOUT using 2>&1, so that all output can be captured at once.

Brian
+1 for being concise and complete
Peter Tillemans
A: 

It work the same.

find / > log.txt

A extra bonus could be found with the tee command, this will save to a file and show the output the same time.

find / | tee log.txt
Johan