LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-15-2010, 08:44 AM   #1
revsarah
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Rep: Reputation: -2
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 ?)
 
Old 10-15-2010, 08:46 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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?
 
Old 10-15-2010, 12:51 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,174
Blog Entries: 4

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Moved: This thread is more suitable in Linux-General and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 10-15-2010, 01:17 PM   #4
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,209

Rep: Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473
Quote:
Originally Posted by revsarah View Post
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
 
Old 10-15-2010, 05:41 PM   #5
qweasd
Member
 
Registered: May 2010
Posts: 436

Rep: Reputation: Disabled
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.
 
Old 10-15-2010, 06:40 PM   #6
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
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.

Last edited by pr_deltoid; 10-15-2010 at 06:55 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
move all files in current directory into a subdirectory in the current directory jakykong Linux - Newbie 8 07-16-2013 11:46 PM
Number of files in directory bullium Linux - General 13 08-31-2011 08:50 AM
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 06:22 AM
A simple command displaying the size of a directory satimis Linux - Newbie 5 11-24-2004 12:06 AM
finding the number of files in each directory ridertech Programming 1 06-02-2004 10:26 PM


All times are GMT -5. The time now is 12:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration