English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm a unix newbie and am baffled why 'ls' command doesn't automatically give number of files. What were the creators thinking??? "No one would care about how many files?" DUH. Anyways, please help if you can. THANKS!

2007-02-19 08:29:22 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

Try using this:

ls | wc -l

wc is the word count command, the "-l" flag indicates counting the lines. If you leave off the "-l", you'll get the byte, line, and character counts.

I'm sure the creators of UNIX were thinking to keep the commands small and focused only on the task they were responsible for. You can string together many commands to effectively "program" more advanced commands as needed.

2007-02-19 08:34:25 · answer #1 · answered by Jim Maryland 7 · 1 0

"ls" is the command to list the directory
"ls -la" shows the listing of the directory including files that start with "." and the current and parent directory links "/." and "/.."
"wc" is the counter, and "wc -l" is a line counter

so...

"ls | wc -l" will give you the number of normal files in the directory
"ls -la | wc -l" will give you the number of files in the directory including files that start with "." and the two current / parent directory links.

2007-02-19 08:37:08 · answer #2 · answered by Rob R 2 · 0 0

Better to use find command :

find . -maxdepth 1 -type f | wc -l

(or)

ls -p | grep -v /|wc -l

Visit point no 18 of following link :

http://mytpoints.blogspot.in/2014/09/find-utility.html


:-)

2014-09-02 00:54:41 · answer #3 · answered by Mukesh K 2 · 0 0

ls [d] [f...] List files in directory

ls -1 [f...] List files in detail

2007-02-19 08:34:33 · answer #4 · answered by ? 5 · 0 1

type

man ls

and this will let you read the manual for the ls command.

maybe ls -c or something

2007-02-19 08:34:09 · answer #5 · answered by plymouthbarracuda1969 3 · 0 2

ls -al | wc -l

2007-02-19 08:43:54 · answer #6 · answered by m34tba11 5 · 0 0

fedest.com, questions and answers