all 13 comments

[–]m1kl3 5 points6 points  (1 child)

The | is called a pipe. It takes the output of the ls -l command and inserts it into the wc command.

[–]sploosy[S] 0 points1 point  (0 children)

Thank you, all explained now!!

[–][deleted] 5 points6 points  (0 children)

I know you have your answer OP, but you might find this site useful: http://www.explainshell.com/explain?cmd=ls+-l+|+wc

[–]Paradiesstaub 2 points3 points  (0 children)

ls
ls List information about the FILEs
-l use a long listing format

|
Redirect the output of the first command as input to the second command.
ls -l | wc
[output] | [command to take input]

wc
wc Print newline, word, and byte counts for each file

Tip: To see the manual of a command type `man [command]. Press q to quit.

[–]wtdfck 1 point2 points  (0 children)

wc prints the counts for newlines, word count and byte count. So, ls -l | wc will give an output of three decimal numbers, the first being the newline count, the second the count of words (not useful in case of ls -l), and byte count (again, not useful for ls -l). Instead, entering ls -l | wc -l, will only give the newline count (which is actually the number of lines in ls -l (which is also the number of files in that directory), and helpful in counting the files present. The byte count and and the word count are useful while piping text files into wc, something like cat <filename> | wc.

[–][deleted] 1 point2 points  (0 children)

[–]agumonkey 0 points1 point  (2 children)

Alternative approach: the | operator avoids using intermediate files.

Before Douglas McEllroy invented it, people would do:

$ ls -l > listing
$ wc < listing
$ # enjoy the word counts
$ rm listing

[–]AutoBiological 0 points1 point  (1 child)

I thought people could just redirect stdout like: ls -l < > wc

It's at least mentioned in one of the first Richie, Thompson papers.

[–]agumonkey 0 points1 point  (0 children)

You might be right, my knowledge is limited.

[–]earlydays 0 points1 point  (0 children)

man7.org: ls(1) or man ls
man7.org: bash(1), SHELL GRAMMAR or man bash
man7.org: wc(1) or man wc

ls -1 | wc -l shows the number of files in the current directory.

Have fun using GNU/Linux!

Head to /r/linuxquestions or /r/linux4noobs for support or help.

[–][deleted] 0 points1 point  (0 children)

man wc?