Thursday, January 16, 2025
HomeComputer ScienceTee command in Linux with examples

Tee command in Linux with examples

The tee command in Linux is used to read from standard input and write to both standard output and one or more files simultaneously. It allows you to view the output on the terminal while also saving it to a file.

Syntax:

See also  Will Computer Science Be Replaced by AI?

command | tee [options] file_name

By default, tee overwrites the content of the file. To append data instead, use the -a option.

Examples:

1. Basic usage:

echo “Hello World” | tee file.txt

This will print “Hello World” to the terminal and save it to file.txt.

See also  grep command in Unix/Linux

2. Appending to a file:

echo “New line” | tee -a file.txt

This will append “New line” to file.txt and display it on the terminal.

The tee command is useful for logging, debugging, and when you need to capture command output while still viewing it.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x