LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   LINUX: Send the last 3 lines of the output of the who command to a file called out1? (https://www.linuxquestions.org/questions/linux-newbie-8/linux-send-the-last-3-lines-of-the-output-of-the-who-command-to-a-file-called-out1-4175594603/)

deathgripping 12-01-2016 02:37 PM

LINUX: Send the last 3 lines of the output of the who command to a file called out1?
 
I recently learned about Filters in my Linux class. However this is throwing me off. I know what the who command is and about the tail command but how do I send it to a out1? And where does who fit into this?

is it

who tail +3 > out1 ?

Any help is appreciated.

suicidaleggroll 12-01-2016 03:05 PM

Close

As written, you're passing "tail" and "+3" as arguments to "who". What you need instead is to run "who" by itself, and redirect its output to the input of "tail". In Linux there are two types of I/O redirection, ">" and ">>" redirects output to a file, which you have done correctly, while "|" redirects output to the input of another process. You need to stick a "|" between "who" and "tail" so that the "tail" program can process the output of "who", rather than passing the literal string "tail" as an argument to "who".

Habitual 12-01-2016 03:06 PM

Code:

tail -3 who >> out1
spews error.
Did you notice?

Code:

who
and
Code:

who | tail -3
output are essentially equal result here, so unless the who utility is somehow 'different' on your system,
Code:

who >> out1
should do it.
Never ever saw
Code:

tail -3 who #whatever
before now.

See http://www.tldp.org/LDP/abs/html/io-redirection.html


All times are GMT -5. The time now is 08:23 AM.