![]() |
|
|
|
|
|||||||
| 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 |
| count the number of files which have a search string, but counting the file only once | sudheshnaiyer | UNIX for Dummies Questions & Answers | 1 | 08-11-2007 10:50 AM |
| Number of files in a directory | tantric | UNIX for Dummies Questions & Answers | 3 | 06-29-2007 02:22 PM |
| Counting files in one directory | matrixtlm | UNIX for Dummies Questions & Answers | 10 | 06-15-2007 04:14 PM |
| Counting files in a directory that match a pattern | dsravan | Shell Programming and Scripting | 31 | 07-24-2006 08:12 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 number of files in a directory
Some simple questions from a simple man.
If i wanted to count the number of files contained within a directory, say /tmp would ls -l /tmp ¦ wc -l suffice and will it be accurate? second one: How would i check the number of files with a certain string in the filename, in the same directory. Appolgies if this has been answered before, i've been unable to find any posts. Regards, Al Last edited by iamalex; 09-05-2005 at 06:53 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
ls -l /tmp | wc -l would count files, directories, and also the line that displays the total size of the listing.
The best way is ls -1 /tmp | wc -l (ls -number_one) although this still shows directories too. If you just want a count of files (including soft links, etc).... echo "`ls -l | grep -v "^d" | wc -l` - 1" | bc You can grep -v out stuff you don't want. On the second question.... ls /my/dir/*some_string* | wc -l Or to use regular expressions instead of globbing ls /my/dir | grep "some_[Ss]tring" | wc -l Many ways to skin these cats..... Cheers ZB |
|
#3
|
|||
|
|||
|
Top Man
Great, thanks, i had a feeling i was going wrong somewhere, excellent reply and really helpful.
regards, Al |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|