LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   ls command and displaying the number of files in your current directory? (http://www.linuxquestions.org/questions/linux-general-1/ls-command-and-displaying-the-number-of-files-in-your-current-directory-838266/)

revsarah 10-15-2010 09:44 AM

ls command and displaying the number of files in your current directory?
 
What command will provide you with the number of files in your current directory?
Choose one answer.
A. ls -c
B. ls | wc -w (this one)
C. ls -n | count
D. ls -wc (this one ?)

GrapefruiTgirl 10-15-2010 09:46 AM

Hi, welcome to LQ. :)

Have you tried any/all the commands to see for yourself if any of them do as you wish? If so, what was the result. If not, why not?

XavierP 10-15-2010 01:51 PM

Moved: This thread is more suitable in Linux-General and has been moved accordingly to help your thread/question get the exposure it deserves.

TB0ne 10-15-2010 02:17 PM

Quote:

Originally Posted by revsarah (Post 4128484)
What command will provide you with the number of files in your current directory?
Choose one answer.
A. ls -c
B. ls | wc -w (this one)
C. ls -n | count
D. ls -wc (this one ?)

Try them and find out. And more importantly, DO YOUR OWN HOMEWORK

qweasd 10-15-2010 06:41 PM

Count files and folders that are not hidden:
ls | wc -l
Count all files and all folders, including . and ..
ls -a | wc -l
Same, without . and ..
ls -A | wc -l
Same, but now we only count honest to god files, not directories or pipes or anything else.
find . -maxdepth 1 -type f | wc -l

See man wc, man ls, and man find for more info.

pr_deltoid 10-15-2010 07:40 PM

not including hidden:
Code:

ls -1 | wc -l
including hidden (but not including . and ..):
Code:

ls -a1 | sed '1,2d' | wc -l
ls | wc -w doesn't work for hidden files/directories.


All times are GMT -5. The time now is 03:15 PM.