LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help me with command in linux (https://www.linuxquestions.org/questions/linux-newbie-8/help-me-with-command-in-linux-4175562323/)

learnlinuxvn 12-25-2015 03:09 AM

Help me with command in linux
 
1 Attachment(s)
Let me ask you use who command if I only want to show only the username and login now how I have:D:D:D

Keruskerfuerst 12-25-2015 03:18 AM

The login name is displayed on the very left side.
If $ is displayed, you are logged in as user.
If # is displayed, you are logged in as root.

learnlinuxvn 12-25-2015 03:24 AM

I want to filter condition show who command to display only the login names and hours logged

NoStressHQ 12-25-2015 04:18 AM

Quote:

Originally Posted by learnlinuxvn (Post 5468731)
I want to filter condition show who command to display only the login names and hours logged

Well... A little bit of English improvement would be a GREAT help for the rest of your work... As docs are written in english and to get proper help, it's better to be understood... I'm not sure we understand what you want...

I guess... That you want to display some info exclusively... So:
1. man man.... USE MAN... man who => Why ? Because OFTEN an argument does what you want.
2. then: "man whatever-you-need"...
3. finally LEARN: grep, sed, awk, Bash (or eq).... Grep/sed helps you to filter text... awk kinda-parse records..

Good luck.

Garry.

PS/ $ who -s ??

jamison20000e 12-25-2015 08:30 AM

Code:

man who
...

wpeckham 12-25-2015 08:32 AM

Expand the question
 
Agree with above, your meaning is unclear.

Do you mean you want the logon name and time for the users currently logged in?

That can be pulled in several ways, and filtered in several ways to avoid displaying what you do NOT want.

I have a snip that may be useful:
Code:

#!/bin/bash
# awkc - print out one or more columns

p=\$$( echo $1 | sed 's/,/,\$/g' )
shift
eval "awk '{ print $p }'" $*

#eof

I place this in a script names acol and drop it in /usr/local/bin with permissions 755.

Using that I might try
Quote:

who|acol 1,3,4
to see if that is what was wanted.

Please let us know is that helps. If not, please provide more detail about your question and need.

Greg321 12-25-2015 03:14 PM

Quote:

Originally Posted by learnlinuxvn (Post 5468728)
Let me ask you use who command if I only want to show only the username and login now how I have:D:D:D

Since you only want the username and login time, here it is. The first line is the code and below it is the output of the code:

Code:

who | awk '{ print $1, $4 }'

greg 14:57
greg 14:57
greg 15:25
greg 15:36

To add a title for each field
Code:

who | awk 'BEGIN { printf "%-19s" "%-9s\n", "User", "Login Time" } { printf "%-19s" "%-7s\n", $1, $4 }'
User              Login Time
greg              14:57 
greg              14:57 
greg              15:25 
greg              15:36

There is also the w command which is similar to who with gives additional info.

Code:

w

16:04:23 up  1:08,  4 users,  load average: 0.18, 0.15, 0.14
USER    TTY        LOGIN@  IDLE  JCPU  PCPU WHAT
greg    :0        14:57  ?xdm?  11:41  0.04s /bin/sh /usr/bin/startkde
greg    pts/0    14:57    1:07m  0.00s  0.72s kdeinit4: kded4 [kdeinit]
greg    pts/1    15:25  29:05  0.06s  0.06s /bin/bash
greg    pts/2    15:36    1.00s  0.16s  0.00s w


Another command is last. You can use this command to see current and passed logins.

There you have it. who, w, and last.

Enjoy!

AnanthaP 12-26-2015 02:09 AM

I think he want who am i with hours logged

OK

NoStressHQ 12-26-2015 04:12 AM

Quote:

Originally Posted by AnanthaP (Post 5469023)
I think he want who am i with hours logged

OK

I think that's something "in the way"... But WHERE does he want that ? I suspect it is for the prompt, but maybe I'm wrong...

wpeckham 12-26-2015 08:46 AM

waiting ...
 
I think that at this point we need to wait for the OP to fill us in on what he really needs. We have offered a couple of possible answers to the question he almost asked, and without clarification we are just spinning our wheels. We need direction, and the OP can provide that.

Greg321 12-26-2015 02:27 PM

Quote:

Originally Posted by AnanthaP (Post 5469023)
I think he want who am i with hours logged

OK

I'm just going with what the OP supplied us. As wpeckham said, we need feedback from the OP if our suggestions had help or not or we're just spinning our wheels on guesses.

As mentioned earlier, Op can try w and last to get additional information on logins.

There is another approach called process accounting. It logs users logins and length of time and what they did, etc. The package name is call psacct

the command is ac

NoStressHQ 12-26-2015 02:43 PM

Well in fact looking at his other posts, it seems he's a lamer... Asking here for us doing his homework for free...

Of course as he can't speak minimal English, don't expect any gratitude :).

Greg321 12-26-2015 04:07 PM

Quote:

Originally Posted by NoStressHQ (Post 5469246)
Well in fact looking at his other posts, it seems he's a lamer... Asking here for us doing his homework for free...

Of course as he can't speak minimal English, don't expect any gratitude :).

Yep, we're not mind readers :)


All times are GMT -5. The time now is 10:04 PM.