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

What does chmod 777 do?

0 Answers  


What is echo command in batch file?

0 Answers  


How do I run a .sh file in linux?

0 Answers  


What file type is a makefile?

0 Answers  


Why bash is used in linux?

0 Answers  






What is nslookup command?

0 Answers  


What is the difference between diff and cmp command in unix?

0 Answers  


How do I check storage on linux?

0 Answers  


In order to display the last five commands you have entered using the fc command, you would type?

0 Answers  


What is command line in unix?

0 Answers  


What command do you type to find help about the command who?

0 Answers  


find out what file systems supported by kernel?

4 Answers  


Categories