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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does rmdir do in linux?

526


How do I do a whois search?

552


List the three main parts of an operating system command?

498


Write a command that will look for files with an extension "c", and has the occurrence of the string "apple" in it.

1153


What does history command do in linux?

519






Who am I command in linux?

549


What does make clean command do?

514


You wish to print a file ‘draft’ with 60 lines to a page. What command would you use?

554


How do I use nslookup in linux?

501


Is llvm a compiler?

535


What does c mean in linux?

560


What is finger command in linux?

538


What is the use of finger command in linux?

511


What are the examples of simple command?

511


tell me something about linux commands.

540