Tag Info

New answers tagged

1

This has to do with the command you're using to pipe the string to wc. The echo command is slipping in an extra character at the end of your string, test, a new newline character, \n. So in effect you're counting this: test\n. You can disable this behavior with the -n switch to echo. $ echo -n "test" | wc -c 4 Or use a different command to generate your ...


2

I did a strace on both commands. The interessting thing is that when you pipe the output to head there are only 123 system calls. On the other hand when pipeing to tail there are 245 system calls (or more when there are more *.txt files). Case: head Here are the last few lines when pipeing to head: open("file12.txt", O_RDONLY) = 3 fadvise64(3, ...


2

Any process that does not block SIGPIPE will be killed if its output goes to the write end of a pipe that no one is reading from. So as soon as head closes its input (i.e. terminates), wc dies, which takes less time than finishing all the work.


0

You can do it for disappear your files: time wc -l *.txt > tee | tail But a bit you add time for tee command to time . With tee command : root@debian:/home/mohsen/test# time wc -l *.txt > tee | tail real 0m0.005s user 0m0.000s sys 0m0.000s Without tee command: root@debian:/home/mohsen/test# time wc -l *.txt | tail 8 f3.txt ...


4

Why does “ls | wc -l” show the correct number of files in current directory? Well, that's a false premise right there. It does not! Try this: mkdir testdir cd testdir # below two lines are one command, the newline is quoted so will be part of argument echo text | tee "file name" ls -l ls | wc -l Output of that last line is 2. Note how, when ...


8

Historically, ls wrote its output one file per line, which is a convenient format for processing with other text-based Unix tools (like wc). However, on a 24 line terminal with no scrollback, large listings had a tendency to scroll off the screen, making it hard to find what you were looking for. So, at some point, the BSD developers changed the behavior ...


10

Because the output of ls depends on the std output, it is different for terminal and pipe. Try /bin/ls | cat


30

From info ls: '-1' '--format=single-column' List one file per line. This is the default for 'ls' when standard output is not a terminal. When you pipe the output of ls, you get one filename per line. ls only outputs the files in columns when the output is destined for human eyes. Here's where ls decides what to do: switch ...



Top 50 recent answers are included