DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 29th April 2011
sharris sharris is offline
Package Pilot
 
Join Date: Jun 2010
Posts: 146
Default How-To get a directory count

Hello everybody!

I did a search and finally found out how to get the file count in various ways with-in a direcory. These works very well on FreeBSD current-9.0:

Code:
 ls | wc -l  #  count files and one for each directories in the current (target) directory.

find /target/directory -type f -print | wc -l    # count all files in all directories, but exclude directories count

find /target/directory -maxdepth 1 -type f -print | wc -    #  all files, in given directory only.
... but I found nothing about how-to get a count of directories only with-in a directory.

My questions is:

1) How do we get the count of all directories only with-in a directory.

2) and than how to get a list of all directory names with-in a given directory.

Thanks in advance
Reply With Quote
  #2   (View Single Post)  
Old 29th April 2011
rocket357's Avatar
rocket357 rocket357 is offline
Real Name: Jonathon
Wannabe OpenBSD porter
 
Join Date: Jun 2010
Location: 127.0.0.1
Posts: 429
Default

-type d
__________________
Linux/Network-Security Engineer by Profession. OpenBSD user by choice.
Reply With Quote
  #3   (View Single Post)  
Old 29th April 2011
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by sharris View Post
1) How do we get the count of all directories only with-in a directory.

2) and than how to get a list of all directory names with-in a given directory.
I will give you a hint. grep(1) can be your friend.
Code:
$ ls -l | grep ^d
Reply With Quote
  #4   (View Single Post)  
Old 29th April 2011
sharris sharris is offline
Package Pilot
 
Join Date: Jun 2010
Posts: 146
Default

I think I just wasted two semesters trying to get to know C++, boost, etc. When those forums give you a hint your on your own for any other week/month/years, with-out a clue writing a full-blown program for what these one-liners already did/done/case-close ...

There are no directories in /rescue but both will output [1] *OR* always output one extra to a count if called with-in a directory or sub-directory. It add a count of one for itself. I can live with that

Code:
find /rescue -type d -print | wc -l
Code:
find /rescue/ -type d -print | wc -l

If you call this a hint what could possibly works better? Or is it the new FreeBSD current?

Code:
$ ls -l | grep ^d
From with-in any directory it gave me as root a complete/exact list of all directories in a partition or directory ... WoW!

Thanks guys
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How is SSL hopelessly broken? Let us count the ways J65nko News 0 12th April 2011 01:17 AM
Xtracting Data after Fragmentation / Block Count / Partition Problems on Boot IronForge OpenBSD Installation and Upgrading 3 16th December 2010 01:09 AM
FreeBSD 7.2@amd64 atheros problem ath0: stuck beacon; resetting (bmiss count 4) asmo FreeBSD General 0 6th June 2009 11:02 AM
strange "~" directory in home directory gosha OpenBSD General 5 23rd February 2009 06:12 PM
how to copy a directory. bsdnewbie999 OpenBSD General 1 12th July 2008 02:36 PM


All times are GMT. The time now is 05:52 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick