-1

Will:

ls -l|wc -l

Display the number of devices too? (Including files and directories)

4 Answers 4

3

It will show the number of lines output by ls -l which will include everything that has an entry in the current directory, including files (including special files if present), links, and directories.

3

No ls -l | wc -l will report the number of lines the ls -l command would give. Roughly the number of files+directories in the current directory plus something for the header.

1
  • If you're in /dev it'd give some sense of the number of devices, or potential ones since most of those get character special or block special files. So it may well show a potential number of devices/partitions/etc. beyond standard files Commented Jun 7, 2016 at 22:44
2

Yes, and also symlinks and sockets. And the first line (there are several questions here about what that number means) will also be counted.

But you'll typically only find devices in /dev (with subdirectories) and there's typically very few files there, so I'm wondering if that's really what you want to do. What are you trying to accomplish?

Also ls defaults to only putting one file name on each line when output is not to a terminal, and all the extra output generated by -l is wasted anyway, so ls | wc -l will give the same.

1

ls -l will display how many files contain the currunt directory and in long format. in total n files +1 line for total X as header. | wc -l counts the total lines that is fed so in total you will have n+1 (lines+(1)header after executing ls -l | wc -l

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .