Search code examples
linuxbashshellunixzcat

Unix: Last command - How do I execute a sub command for file input?


I am trying to read an on old last file, but when I use the command below it does not work as expected. Is there a way I can do it in one line?

last -f `zcat /var/log/wtmp.1.gz`

I want to be able to read the file without decompressing the file.

The long version is the following:

zcat /var/log/wtmp.1.gz > /var/tmp/login
last -f /var/tmp/login

Solution

  • You cannot feed last via stdin in bash.

    # this won't work
    # zcat /var/log/wtmp.1.gz | last-
    

    Side note: However with zsh shell you could

    last -f =(zcat /var/log/wtmp-20130827.gz)
    

    Based on https://unix.stackexchange.com/questions/88343/how-to-tell-the-last-command-to-read-from-stdin