What does the following command line produce? Explain each
aspect of this line.

$ (date ; ps -ef | awk {print $1}' | sort | uniq | wc -l )
>> Activity.log

Answers were Sorted based on User's Feedback



What does the following command line produce? Explain each aspect of this line. $ (date ; ps -ef..

Answer / vijay

There is a syntactical error in the question
The Actual command should be like

$(date;ps -ef | awk '{print $1}' | sort | uniq | wc -l ) >>
Activity.log

Answer::
"date" command gives the date

"ps -ef" -- gives all the process informations

awk '{print $1}'--- cuts the first column in the processes
(which is the usernames)

sort-- sorts all the usernames

uniq-- gives unique usernames
"wc -l" -- gives the total number of users running process

In compact--- The command displays the date and the number
of users(not repeated) who are executing some process.

The result when Activitylog is viwed after the execution
should be like

>>Fri Apr 3 12:48:21 IST 2009
>>38

Is This Answer Correct ?    16 Yes 0 No

What does the following command line produce? Explain each aspect of this line. $ (date ; ps -ef..

Answer / daniel

First let's dissect the line: The date gives the date and
time as the first command of the line, this is followed by
the a list of all running processes in long form with UIDs
listed first, this is the ps -ef. These are fed into the awk
which filters out all but the UIDs; these UIDs are piped
into sort for no discernible reason and then onto uniq (now
we see the reason for the sort - uniq only works on sorted
data - if the list is A, B, A, then A, B, A will be the
output of uniq, but if it's A, A, B then A, B is the output)
which produces only one copy of each UID. These UIDs are fed
into wc -l which counts the lines - in this case the number
of distinct UIDs running processes on the system. Finally
the results of these two commands, the date and the wc -l,
are appended to the file "Activity.log". Now to answer the
question as to what this command line produces. This writes
the date and time into the file Activity.log together with
the number of distinct users who have processes running on
the system at that time. If the file already exists, then
these items are appended to the file, otherwise the file is
created.

Is This Answer Correct ?    4 Yes 0 No

What does the following command line produce? Explain each aspect of this line. $ (date ; ps -ef..

Answer / alf55

There is one thing different between who and this command in
that there are processes on the system that are run as
daemons and they will end up in the count (so nicely
described in answer #3). But as pointed out in answer #2,
it does include the header line entry in its count. To fix
that problem, (date ; ps -ef | sed '1 d' | cut -d\ -f1 |
sort -u | wc -l) >> Activity.log
could be used.

The "sed '1 d' " will delete the first line (removing the
header line

the "cut -d\ -f1" (Note there a space after the "\" and
then another space for the field separator.) which is the
same as "awk '{print $1}'".

the "sort -u" does the same work as "sort | uniq".

The ">> Activity.log" is a redirection that appends so date
and the count is append to the current data in the file
"Activity.log". Note: is will not show the ">>" as shown in
answer #3.

Examples of users that will show up in this script that will
not show up using "who | cut -d\ -f1 | sort -u | wc -l":

apache
messagebus
haldaemon
dhcp
lighttp
postmaster
ldap
mysql
postgres
memcached
openvpn

Is This Answer Correct ?    1 Yes 0 No

What does the following command line produce? Explain each aspect of this line. $ (date ; ps -ef..

Answer / liam

It's retarded. The idea is clearly to post the number of
users (the first field of ps -ef), but they are going to
capture the title line. Also, just use 'who'!

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More Linux Commands Interview Questions

Explain about the command elm?

0 Answers  


How do you create a file in linux?

0 Answers  


What is df -i command?

0 Answers  


What does umask 077 mean?

0 Answers  


What is the symbol of linux?

0 Answers  






Linux system monitoring Tools?

6 Answers   HCL, IBM,


What is unix finger command?

0 Answers  


What Command used to lock user password?

0 Answers  


Where can I find bash in linux?

0 Answers  


How to know linux os is 32 bit or 64 bit?

0 Answers  


Which command is used to check the number of files and disk space used and the each user’s defined quota?

0 Answers  


What is cat command in linux?

0 Answers  


Categories