2

I'm making a script and every time something is done I would like to write into my custom .log file. How do I do that?

And in the end.. I'd just like to read it with Bash,.. do I just use cat?

Thanks.

2
  • 1
    sure, you can just use "echo" and/or redirect output using > and >> to a file. Commented Apr 4, 2013 at 12:39
  • 1
    Nothing wrong with this question. Why the downvotes? If you downvote, please clarify. Even more if against a low-scored user that needs incentive, not downvotes. Commented Apr 15, 2017 at 0:52

2 Answers 2

5

The simplest syntax I always use is 2>&1 | tee -a file_name.log.

The syntax can be used after a command or execution of a file. e.g.

find . -type f 2>&1 | tee -a file_name.log

or

./test.sh 2>&1 | tee -a file_name.log
Sign up to request clarification or add additional context in comments.

Comments

4

Just cat <log message here> >> custom.log.

The >> means add on to the bottom of the file rather than > which would delete the contents of the file and then write the message.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.