In: Computer Science
Can you explain the answer: thanks.
who | awk ‘ { print $1 } ‘ | sort –u | wc –l
ls –l | wc –l > /tmp/count
find ~username –type –d –print
person = `who | grep $1`
Here is the explanation of each commands:-
who | awk ‘ { print $1 } ‘ | sort –u | wc –l
who command is used to know current logged in user in the system.
| is a pipe special charachter which takes output from one command and uses as input in the next command
awk is a scripting language which does not requires compiling and is used for manipulating data and generating reports.
sort command is used to sort the file in a particular order.
wc command is used to count the words.
So, in the above code.
First it displays current logged in user in the system and passes the information to awk command where it 'print $1' prints first word of each logged in user. This output is then sorted and only unique entries will remain and duplicate will be removed and a sorted list will be obtained. wc -l command will then count and display number of lines.
ls –l | wc –l > /tmp/count
ls command is used for listing the contents of the directory or list of directories.
> is a special character which is used to create/clean a file.
so in this command,
first it will list out the names of files in a directories with details of file size, modified date and time, file name , owner of the file and permissions on the file. Then the wc command will count the number of lines in the output and it will then stored in a file named count at location tmp/count.
find ~username –type –d –print
find command is used to find the usernames and prints them.
person = `who | grep $1`
This command is used to store the value of the first user found in person variable.