Computer Science - Unix - Discussion

Discussion :: Unix - Section 2 (Q.No.21)

21. 

The command to count the number of files in the current directory by using pipes, is

[A]. ls | wc
[B]. ls -l | wc -l
[C]. ls | wc -w
[D]. ls | ws -c
[E]. None of the above

Answer: Option C

Explanation:

No answer description available for this question.

Brinda said: (May 30, 2013)  
Incorrect option as it should be ls-l | wc-l

And to view hidden files as well it should be ls-la | wc-l

Girish said: (Dec 5, 2013)  
ls -l | wc -l is correct option.

As it will give number of files stored in directory.

Mohit Singh said: (Sep 10, 2014)  
ls -l option will give one extra count then the number of files.

Praveen said: (Feb 8, 2015)  
B is the correct answer.

Because, -w for word count and -c for character count.

Aadesh Dubey said: (May 7, 2015)  
A. ls | wc --> Display the lines, words, and characters.

B. ls-l | wc -l--> Display total lines including one extra count since ls -l will give you another line with (total 0).

C. ls | wc -w--> Display all files and provide word count, but what will happen if a file name contains space, will it still give count as 2 or will it give the count as 3.

$ls
Test file
Test
$ls | wc -w

D. ls | ws -c --> Will give the character count of the list of files.

E. None of the above --> According to me this should be the answer.

Any thoughts will be much appreciated.

Deepak Mallik said: (Dec 10, 2016)  
The correct answer: ls | wc-l

Abhi_007 said: (Dec 13, 2016)  
Yes, I agree the correct Answer is 'C'.

Harshad said: (May 6, 2017)  
Yes, right @Brinda.

Raptor said: (Jul 13, 2017)  
ls | wc -w is the correct answer!!
try it in your linux systems and you will find that.
ls | wc- l and ls | wc -c gives the same result!.


So OPTION C is correct.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.