LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2016, 02:37 PM   #1
deathgripping
LQ Newbie
 
Registered: Oct 2016
Posts: 1

Rep: Reputation: Disabled
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.

Last edited by deathgripping; 12-01-2016 at 02:57 PM.
 
Old 12-01-2016, 03:05 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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".

Last edited by suicidaleggroll; 12-01-2016 at 03:06 PM.
 
1 members found this post helpful.
Old 12-01-2016, 03:06 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to send the output of send command to a file auma78 Linux - Newbie 2 01-23-2011 12:06 AM
how to send the output of a command in a file defined by a eval $"$var1" toordog Programming 3 07-07-2010 04:26 PM
How to send command output to file?! mr_aliagha Linux - General 2 02-27-2009 01:06 PM
Send file output to 'kill' command jkarp2112 Linux - Newbie 4 06-25-2008 05:17 PM
IS it possible to send command output to a file as well as the screen helptonewbie Programming 6 09-16-2007 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration