Today's article is a cup of tee...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,775
Reaction score
10,337
Credits
97,436
Or it's time to tee off...

One or the other, or any additional puns you can think of.

I want to write an article or two that uses the tee command. It was an article I did write but looked like hot garbage. So, I asked my good buddy AI to help me out. They did a better job than I did. I told 'em to format it like it would fit my site, but AI is less than perfect. Still, it's a useful article for those looking to learn more about the tee command - and for me to reference in future articles...


Yes, I even let AI name the article.
 


Question::)

Before running:
Code:
ls -l | tee file1.txt file2.txt

Wouldn't one have to first create file1.txt and file2.txt with the touch command?

Looks like (didn't finish reading the whole article yet) lot's of good usage for many different things.
 
Wouldn't one have to first create file1.txt and file2.txt with the touch command?

This is AI. Those are just examples.

So, yes, but they're just an example and not actually something you're meant to run.

It's what the AI spits it out. In my version of the article, it included downloading a couple of pointless files and working with those. It was quite an awkward article.
 
This is AI. Those are just examples.

So, yes, but they're just an example and not actually something you're meant to run.

It's what the AI spits it out. In my version of the article, it included downloading a couple of pointless files and working with those. It was quite an awkward article.
Thanks for the confirmation.
I'll use it later on a system log.

Back to the vim tutorial I'm working on.
 
@Alexzee asked:
Wouldn't one have to first create file1.txt and file2.txt with the touch command?

The tee command will create the files which are its arguments:
Code:
[tom@min ~/teedir]$ ls
afile

[tom@min ~/teedir]$ ls | tee file1 file2
afile
file1
file2

[tom@min ~/teedir]$ ls
afile  file1  file2
 
@Alexzee asked:


The tee command will create the files which are its arguments:
Code:
[tom@min ~/teedir]$ ls
afile

[tom@min ~/teedir]$ ls | tee file1 file2
afile
file1
file2

[tom@min ~/teedir]$ ls
afile  file1  file2
I don't understand so I pulled up the man page.
When time allows I'll check out:
 
@Alexzee asked:


The tee command will create the files which are its arguments:
Code:
[tom@min ~/teedir]$ ls
afile

[tom@min ~/teedir]$ ls | tee file1 file2
afile
file1
file2

[tom@min ~/teedir]$ ls
afile  file1  file2

Wait, no... This...

LOL I misread the question as I was kinda busy at the moment.

The tee command happily creates files. (I'm in and out today. More out than in.)
 
Wait, no... This...

LOL I misread the question as I was kinda busy at the moment.

The tee command happily creates files. (I'm in and out today. More out than in.)
Ok so if I type this command (this is an example)
Code:
tee --append file1.txt file2.txt

The tee command will send standard input to the given files?
(rather than overwriting them)
 
Question::)

Before running:
Code:
ls -l | tee file1.txt file2.txt

Wouldn't one have to first create file1.txt and file2.txt with the touch command?

Looks like (didn't finish reading the whole article yet) lot's of good usage for many different things.

There's very little commands that error out if a given file doesn't exist (or does exist, depending on the functionality).
That is, commands that modify that specific file in question.

For example, if you CP a file to an existing file, Linux (Bash) won't mind you have overwritten a file. Same with many other commands: files get overwritten/changed without too much hasle. There's pro's and cons to that.
 
Last edited:
I don't understand so I pulled up the man page.
When time allows I'll check out:

That would be because the parameter is only just one file. If you TEE to 2 files ... aren't they the same ? Why would you do that ?
That is, if not using the append option.
The TEE command is already having two outputs (1: screen and 2: file), so just 1 file would be enough, right ?
 
That would be because the parameter is only just one file. If you TEE to 2 files ... aren't they the same ? Why would you do that ?
That is, if not using the append option.
The TEE command is already having two outputs (1: screen and 2: file), so just 1 file would be enough, right ?
Until yesterday using the tee command wasn't in my wheelhouse.
Opening my konsole and executing practices using the tee command is how I'll become more aquainted with it and how it works.
 
It's a great concept, and you can do many great stuff with it
It's one of those thing where you wonder: how would you ever do this, without such a command ..
 
Finding the time to do that is a whole together different thing, lol!
 
It's a great concept, and you can do many great stuff with it
It's one of those thing where you wonder: how would you ever do this, without such a command ..
This is one way to "do this, without such a command .." as tee:
Code:
[tom@min ~/]$ ls
filex  filey

[tom@min ~/]$ ls | tee lsfile
filex
filey
lsfile

[tom@min ~/]$ ls
filex  filey  lsfile

[tom@min ~/]$ cat lsfile
filex
filey
lsfile

[tom@min ~/]$ rm lsfile

[tom@min ~/]$ ls
filex  filey

[tom@min ~/]$ ls 1>lsfile

[tom@min ~/]$ ls
filex  filey  lsfile

[tom@min ~/]$ cat lsfile
filex
filey
lsfile
 
This is one way to "do this, without such a command .." as tee:
Code:
[tom@min ~/]$ ls
filex  filey

[tom@min ~/]$ ls | tee lsfile
filex
filey
lsfile

[tom@min ~/]$ ls
filex  filey  lsfile

[tom@min ~/]$ cat lsfile
filex
filey
lsfile

[tom@min ~/]$ rm lsfile

[tom@min ~/]$ ls
filex  filey

[tom@min ~/]$ ls 1>lsfile

[tom@min ~/]$ ls
filex  filey  lsfile

[tom@min ~/]$ cat lsfile
filex
filey
lsfile

Exactly

whatever command > whatever_text_file.txt

then

cat whatever_text_file.txt

But the problem is then that the output is only shown when the command is completed, which for some output may defeat the purpose as you want to know some information, before reaching the end.
Or you could TAIL -F the text file but that requires process forking, which is not easy as a noob.
 
But the problem is then that the output is only shown when the command is completed, which for some output may defeat the purpose as you want to know some information, before reaching the end.
Or you could TAIL -F the text file but that requires process forking, which is not easy as a noob.
It's possible to see the command's output and also have it recorded in a file using the script program which will write to a file named, typescript, and include some extra information which may itself be useful beyond just the recording of the command output alone:
Code:
[tom@min ~]$ ls
file1  file2  file3

[tom@min ~]$ script -c "ls -al"
Script started, output log file is 'typescript'.
total 8
drwxr-xr-x  2 tom tom 4096 Apr  9 21:07 .
drwxr-xr-x 19 tom tom 4096 Mar 10 12:08 ..
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file1
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file2
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file3
-rw-r--r--  1 tom tom    0 Apr  9 21:07 typescript
Script done.

[tom@min ~]$ ls
file1  file2  file3  typescript

[tom@min ~]$ cat typescript 
Script started on 2024-04-09 21:07:11+10:00 [COMMAND="ls -al" TERM="xterm" TTY="/dev/pts/4" COLUMNS="65" LINES="55"]
total 8
drwxr-xr-x  2 tom tom 4096 Apr  9 21:07 .
drwxr-xr-x 19 tom tom 4096 Mar 10 12:08 ..
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file1
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file2
-rw-r--r--  1 tom tom    0 Apr  9 21:06 file3
-rw-r--r--  1 tom tom    0 Apr  9 21:07 typescript

Script done on 2024-04-09 21:07:11+10:00 [COMMAND_EXIT_CODE="0"]
 

Members online


Latest posts

Top