![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with counting files please | gerard1 | Shell Programming and Scripting | 6 | 09-25-2006 10:37 AM |
| Counting files in a directory that match a pattern | dsravan | Shell Programming and Scripting | 31 | 07-24-2006 08:12 AM |
| Line counting in Directory | MobileUser | UNIX for Dummies Questions & Answers | 3 | 02-25-2006 01:15 AM |
| Counting number of files in a directory | iamalex | UNIX for Dummies Questions & Answers | 2 | 09-05-2005 07:13 AM |
| rm files in a directory, looping, counting, then exit | JporterFDX | Shell Programming and Scripting | 6 | 07-18-2002 05:56 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Counting files in one directory
I did a search on this forum and found this command to count the total of files in one directory:
ls -l | wc -l I did a test by creating one file in a folder and issue the command. But it return value "2". Abit confused now. Since there is one file in the directory, isn't it it should return value "1" ? At the same time I tried "ls -lrt | more", it return "total xxxxx". Is this figure showing the number of lines? I want to do a count on a directory to get the total files. Please advise. Appreciate. Thanks. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
The reason you are seeing 2 is because of the output of ls -l. Rather you may want to use ls -1 Notice the digit 1 against the letter l
Code:
[/tmp/test]$ ls -l total 0 -rw-r--r-- 1 xxxxxxxx g900 0 Jun 12 22:05 test [/tmp/test]$ ls -l | wc -l 2 [/tmp/test]$ ls -1 test [/tmp/test]$ ls -1 | wc -l 1 [/tmp/test]$ |
|
#3
|
|||
|
|||
|
Hi... thanks for the reply.
When I do a "ls -l", i get a return of "total 4000". Even I minus 1, still i will get a value of 3999. $ls -l | more total 4000 But when I did a ls -1|wc -l. I get a different figure of "310". ls -1 | wc -l 310 Is there a difference on the two values? I thought both the command should return the same figure. Please correct me if i'm wrong. Need some explanation. Thanks. |
|
#4
|
||||
|
||||
|
Post the output of ls -l
|
|
#5
|
|||
|
|||
|
Hi,
This is the actual figure in my machine $ls -l | more total 4696146 $ls -1| wc -l 4312 Thanks. |
|
#6
|
|||
|
|||
|
The "total" is something to do with the amount of disk space that directory is using I think. Its nothing to do with the number of files in the directory.
wc -l seems the way to go. |
|
#7
|
|||
|
|||
|
total in ls command
|
|||
| Google The UNIX and Linux Forums |