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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain getopts command of linux?

595


How do I change directories in linux command line?

479


What is shell scripting commands?

533


Explain the ‘ls’ command in linux

560


Write a command that will do the following: -look for all files in the current and subsequent directories with an extension c,v -strip the,v from the result (you can use sed command) -use the result and use a grep command to search for all occurrences of the word orange in the files.

842






List the three main parts of an operating system command?

504


Main configuration file and command used for NFS enabling exported directories and deamons?

510


Who am I command in linux?

564


What is difference between free and available memory in linux?

516


How do you ask politely?

534


How do I set permission to run in linux?

583


What are the basic commands for user management?

548


What could be the problem when a command that was issued gave a different result from the last time it was used?

703


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

544


The head command writes the how many lines of a file to screen?

553