Tee command in Linux

The tee command reads the standard input and makes it changes to the standard output and saves the changes to the file.

Syntax :

tee <options> <file name>  

Options :

The following are some useful options that can be used with the tee command:

  • -a, --append : It is used to append the data to the given files, it does not overwrite data.
  • -i, --ignore-interrupts : It is used to ignore the interrupt signals.
  • -p : It is used to diagnose errors.
  • --help : It is used to display the help documentation.
  • --version : it is used to display the version information.

The -a option is used with thetee command to print the output and write it to a file.

Example :

echo 'Hi!Learning is always fun' | tee -a f2.txt  

Output :
tee-command-linux

By giving the below command, the teecommand allows us to write to multiple files. To write to the multiple files, specify the names of the files after the tee command.

echo "cat and dog" | tee f1.txt chercher.txt newfile.txt  

tee-linux

By giving the below command, the tee command allows us to write to a file having sudo privilege.

echo "music is in the air" | sudo tee -a f1  

tee-command-output-linux

By giving the below command we can ignore the interrupts by giving the -i option. This is useful if we want to stop and exit the command execution.

echo "cat and dog" | tee -i f1

tee-i-command-linux

By giving the below command, we can restrict the tee command not to write to the standard output, redirect it to "/dev/null".

echo "Linux" | tee f1 >/dev/null  

tee-command1-linux

tr command in Linux

The tr command is used to translate, like from lowercase to uppercase and vice versa or newlines into spaces. The command tr stands for 'translate'.

Syntax :

command | tr <'old'> <'new'>  

Examples :

By using the below command you can change the case of the data in the specified file.

cat f1 | tr "[a-z]" "[A-Z]"  
[OR]
cat f1 | tr "[:lower:]" "[:upper:]"  

By using the below command, you can translate the whitespace to the tab.

echo "Welcome to cherchertech " | tr [: space:] '\t'

By using the below command, you can translate braces in a file into parenthesis.


echo {welcome} to cherchertech |"tr '{}' '()'

By using the below command we can eliminate the repeat occurrences of the characters in a file by using the -s option. We can convert multiple continuous spaces into a single space by using the below command.

echo "Welcome        to          cherchertech" | tr -s [:space:] ' '

By using the below command, we can delete a specific character using the -d option.

echo "Welcome        to          cherchertech" | tr -d 'W'

By using the below command, we can remove all the digits from the string by using the -d option.

echo "The digits are 0123456" | tr -d [:digit:]

By using the below command, we can remove all the characters from the file by using the -cd option.

echo "The digits are 0123456" | tr -cd [:digit:]

Collective Outputs of all the options in order :

    tr-command-linux

    0 results
    Comment / Suggestion Section
    Point our Mistakes and Post Your Suggestions