tee: Replicate Standard Output

Now and then I come across a situation when I need to run a script or a Unix command and would like to not only see the output of it on the screen, but also save this output to some log file. Redirecting the standard output using standard Unix stream redirection isn’t always useful because your output will either be shown to you, or sent to the file – but not both at the same time

tee command

That’s where the tee command becomes really useful. You pipe your output to this command, and let it take care of the rest.

Here’s how you use it:

greys@simplyunix:~$ uname -a | tee /tmp/uname.txt
Linux simplyunix.com 2.6.16.29-xen #1 SMP Sun Sep 30 04:00:13 UTC 2007 x86_64 GNU/Linux
greys@simplyunix:~$ cat /tmp/uname.txt
Linux simplyunix.com 2.6.16.29-xen #1 SMP Sun Sep 30 04:00:13 UTC 2007 x86_64 GNU/Linux

What happens is that tee replicates the standard output to both your session and the specified file.

See also:




How To Find Out RedHat Version And More

If you’re a really curious mind, you won’t be satisfied with simply knowing the current release of your RedHat Linux, that’s why there’s a few more commands you could use to satisfy your interest.

RedHat release

If you simply want to confirm whether you’re using a RHEL4, RHEL5 or any of the previous RedHat Linux releases, this is the first place to look:

bash-3.1$ cat /etc/redhat-release
Red Hat Enterprise Linux Client release 5 (Tikanga)

RedHat kernel version and type

Next step is to find out the exact Linux kernel version on your system, and also confirm whether it’s 64-bit or not:

bash-3.1$ uname -a
Linux rhserver123 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 x86_64 x86_64 GNU/Linux

RedHat kernel build

For the most curious ones, here’s the last command. Use it to confirm who and when compiled the RedHat kernel you’re using, and what gcc compiler was used in the build process.

bash-3.1$ cat /proc/version
Linux version 2.6.18-8.el5 ([email protected]) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:14 EST 2007

See also




How To Take A Screenshot in Unix (xwd)

Quite often there’s a need for you to take a screenshot of your Unix desktop, and as always there’s a number of ways to do it. Today I’m going to cover the command line approach to taking screenshots.

Taking a Screenshot with xwd

Most modern Unix desktop systems come with Gnome desktop environment by default, and use Xorg as their default X11 server. This means you are likely to have the xwd tool in your OS, which allows you to take screenshots.

Furthermore, many Unix distros come with hundreds of command-line tools bundled with the default OS install. Imagemagick is one of such bundled toolkits, and you can use the convert tool which is part of it for converting the xwd-generated screenshot into any graphics format of your preference.

Here’s how you use these two commands together:

bash-3.0$ xwd -root | convert - /tmp/screenshot.png

In this line, xwd command is invoked to take a full screenshot of your desktop. You then pipe its output to the convert tool and specify where you want this output saved to.

See Also




How To Mount An ISO image

Mounting an ISO image of a CD/DVD before burning it is one of the basic steps to verifying you’re going to get exactly the desired result. It’s also a neat trick to access files from a CD/DVD image when you only need a file or two and not a whole CD. Why burn it at all when you can access files much quicker and easier by simply mounting the ISO image?

Every Unix OS has a way to access ISO filesystem, and today I’ll only give you examples for Linux and Solaris. In both cases, the two things you need for the example to work are the ISO image itself and an available mount point (basically, an empty directory) on your filesystem to mount it under.

Here’s how to mount an ISO in Linux:

# mount -o loop /net/server/linux-bootcd.iso /mnt

Here’s how to mount an ISO in Solaris:

First, you need to associate your ISO image with a virtual device:

# lofiadm -a /net/server/linux-bootcd.iso

lofiadm approach allows you to have virtual devices associated with as many ISO images as you like, and you can view the list of current associations at any moment:

# lofiadm
Block Device File
/dev/lofi/1 /net/server/linux-bootcd.iso

To mount a virtual device, you use the following command:

# mount -F hsfs /dev/lofi/1 /mnt

See Also