Computer Science - Unix - Discussion

Discussion Forum : Unix - Section 2 (Q.No. 21)
21.
The command to count the number of files in the current directory by using pipes, is
ls | wc
ls -l | wc -l
ls | wc -w
ls | ws -c
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
9 comments Page 1 of 1.

RAPTOR said:   8 years ago
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.

Harshad said:   8 years ago
Yes, right @Brinda.

Abhi_007 said:   9 years ago
Yes, I agree the correct Answer is 'C'.

Deepak mallik said:   9 years ago
The correct answer: ls | wc-l

Aadesh Dubey said:   1 decade ago
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.

Praveen said:   1 decade ago
B is the correct answer.

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

Mohit Singh said:   1 decade ago
ls -l option will give one extra count then the number of files.

Girish said:   1 decade ago
ls -l | wc -l is correct option.

As it will give number of files stored in directory.

Brinda said:   1 decade ago
Incorrect option as it should be ls-l | wc-l

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

Post your comments here:

Your comments will be displayed after verification.