ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I created 26 files in a new directory with names a,b,c,..z and tried your problem.
For ls | wc -l, the answeer was 1.
For ls -l| wc -l, the answer was 27.
ls writes more than 1 file name to output, if the output window width is sufficient. In my case, it could write all 26 file names in a single line.
In case of ls -l, it found 26 lines for 26 files and 1 summary line
ppanyam
Quote:
from info coreutils ls
Code:
By default, the output is sorted alphabetically, according to the
locale settings in effect. (1) If standard output is a terminal, the
output is in columns (sorted vertically) and control characters are
output as question marks; otherwise, the output is listed one per line
and control characters are output as-is.
That clearly means that you must have done something
to your ls if it outputs files in columns when piping to wc.
I think this whole thread is getting a tad confused from the word go...
In the windows world they decided, for some weird reason, to introduce the term "Folder" to mean the same thing as "Directory".
In the unix world, there are no folders, only files and directories.
Let me just check something quickly...
Fire up konqueror (I usually use command line, not gui stuff)
Aww cwap!! The KDE types have copied Windows and called directories folders. Grumble moan (irritating puppies) whinge (arthritis) growl (gout) hrrumph!
Anyhoo, a Folder === Directory. Directory is older name.
So, no I did mean...
find . -type d | wc
..to count ddirectories (folders)
I think this whole thread is getting a tad confused from the word go...
In the windows world they decided, for some weird reason, to introduce the term "Folder" to mean the same thing as "Directory".
In the unix world, there are no folders, only files and directories.
Let me just check something quickly...
Fire up konqueror (I usually use command line, not gui stuff)
Aww cwap!! The KDE types have copied Windows and called directories folders. Grumble moan (irritating puppies) whinge (arthritis) growl (gout) hrrumph!
Anyhoo, a Folder === Directory. Directory is older name.
So, no I did mean...
find . -type d | wc
..to count ddirectories (folders)
And
find . -type f | wc
..to count ffiles.
Sigh!
I think the problem that I have is that one guy in the thread is counting
directories, and the other one is creating files.
Thanks for that explanation of find, though, but I don't refer to
directories as folders, and know how to use find, I do Unix/Linux
for a living.
;}
Cheers,
Tink
P.S.: Is the weather in CHCH as horrid as it is in WLGT at the moment?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.