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
What is gnu in linux?
Who linux commands?
If we transfer 100 files by ftp to remote server, how to know the files are successfully transfer or some file are not transferred?
How many interfaces(ethernet cards) are working using single command?
What is the use of mv command in linux?
How many types of dos commands are there?
How do you limit memory usage for commands?
Information technology is widely used in
How do I remove a soft link in linux?
Who is unix command?
What is the command to see on which port which service is running? And what is the difference between /etc/services file and net stat command?
What is difference between egrep and grep?
How do I check cpu usage?
What are grep commands?
How do I check cores in linux?