Linux Admin – tee Command

  • Post author:
  • Post category:Linux
  • Post comments:0 Comments

The tee is a simple command, letting an administrator write command output and view a file at the same time. This simple command can save time over first writing stdout to a file, then viewing the file contents.

Following are the common Switches used with a tee.

CommandAction
-aAppend to files instead of clobber file
-iIgnore interrupts (for advanced use in scripting mostly)

Without tee to both view and write files and directories in /etc, where each begins with the letter “a”.

[root@centosLocal Documents]# ls -d /etc/a*

/etc/abrt     /etc/aliases.db    /etc/anacrontab   /etc/at-spi2  /etc/autofs.conf

/etc/auto.master.d  /etc/auto.smb  /etc/adjtime  /etc/alsa      /etc/asound.conf

/etc/audisp         /etc/autofs_ldap_auth.conf  /etc/auto.misc  /etc/avahi

/etc/aliases  /etc/alternatives  /etc/at.deny   /etc/audit   /etc/auto.master

/etc/auto.net

[root@centosLocal Documents]# ls -d /etc/a* > ./etc_report_a.txt

[root@centosLocal Documents]# cat ./etc_report_a.txt

/etc/abrt

/etc/adjtime

/etc/aliases

/etc/aliases.db

/etc/alsa

/etc/alternatives

/etc/anacrontab

/etc/asound.conf

/etc/at.deny

/etc/at-spi2

/etc/audisp

/etc/audit

/etc/autofs.conf

/etc/autofs_ldap_auth.conf

/etc/auto.master

/etc/auto.master.d

/etc/auto.misc

/etc/auto.net

/etc/auto.smb

/etc/avahi

[root@centosLocal Documents]#

This small task is much more efficient with the tee command.

[root@centosLocal Documents]# ls -d /etc/a* | tee ./etc_report_a.txt

/etc/abrt

/etc/adjtime

/etc/aliases

/etc/aliases.db

/etc/alsa

/etc/alternatives

/etc/anacrontab

/etc/asound.conf

/etc/at.deny

/etc/at-spi2

/etc/audisp

/etc/audit

/etc/autofs.conf

/etc/autofs_ldap_auth.conf

/etc/auto.master

/etc/auto.master.d

/etc/auto.misc

/etc/auto.net

/etc/auto.smb

/etc/avahi

[root@centosLocal Documents]#

Leave a Reply