LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 03: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 03:57 PM.
 
Old 12-01-2016, 04:05 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,355

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
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 04:06 PM.
 
1 members found this post helpful.
Old 12-01-2016, 04:06 PM   #3
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,665
Blog Entries: 10

Rep: Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:06 AM
how to send the output of a command in a file defined by a eval $"$var1" toordog Programming 3 07-07-2010 05:26 PM
How to send command output to file?! mr_aliagha Linux - General 2 02-27-2009 02:06 PM
Send file output to 'kill' command jkarp2112 Linux - Newbie 4 06-25-2008 06:17 PM
IS it possible to send command output to a file as well as the screen helptonewbie Programming 6 09-16-2007 02:13 PM


All times are GMT -5. The time now is 12:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration