How to use a bash tee command
Here you will find out:
- what a bash tee command is
- how to use the tee command
- when DiskInternals can help you
Are you ready? Let's read!
What is a bash tee command?
The Linux tee command is a command-line utility used to read standard inputs and write to standard outputs and other files simultaneously. This command is used alongside other commands. The name “tee” comes from T-splitter, a term used in plumbing. With the bash tee command, you can simultaneously display and save a file you’re working on.
The syntax and options of the tee command
Here’s the syntax of the bash tee command:
Explanation
Copy standard input to each FILE, and also to standard output.
Options:
To view all options of the “tee” command, type “tee –help”. However, the following options are the most commonly used.
-a (--append) – append to the indicated files and don’t overwrite the files
-i (--ignore-interrupts) - ignore interrupt signals
Using the tee command
The tee command is used mainly to display standard output (stdout) of a command and copy it to an indicated file.
Example:
The above command will run and display the desired output on the terminal, as well as write the output to the “linux.txt” file at the same time.
This is the basic syntax of the bash tee command.
How to append to a file
Without using the -a (--append) variable, the tee command will overwrite the content of the specified file. Here is how to use the -a (--append) variable with the tee command:
The command above will append the result from pinging diskinternals.com to the linux.txt file, instead of overwriting the content.
How to write to multiple files
Just the way you called the first file, you can call multiple files, too:
Example:
How to ignore the interrupt signal
When you press CTRL+C during the execution of a command, you'll likely get the interrupt signal (SIGINT). However, to ignore this signal when running the tee command, use -I (--ignore interrupts).
Example:
Using tee to write to a privileged file
You can write to a privileged file using the bash tee command. The tee command is used for piping to sudo permissions.
When you have a root file, obviously you’ll need permissions to write/append to that root file. However, when you use the tee command, it elevates the permissions and lets you copy to a root file.
Examples:
This may return:
Using tee:
You can open Linux files with Linux Reader
Let’s say you’re using a dual-boot PC and you’re booted to Windows, but need to access some files saved on your Linux partition. You don’t have to shut down and reboot to Linux for this purpose. Using DiskInternals Linux Reader, you can read and access Linux files on Windows. DiskInternals Linux Reader is user-friendly and has a couple of handy features you’ll love to use. It is an advanced PC utility, available for free.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command




