LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-15-2005, 06:20 AM   #1
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Rep: Reputation: 15
Question List total number of directories


Hi!

Could someone tell me how to list the total number of directories I would have for instance in my home directory?

Thank you in advance
 
Old 04-15-2005, 06:39 AM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
find -type d | wc -l
 
Old 04-15-2005, 10:27 AM   #3
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Terve ToniT!

Thank you for your quick reply. I have tried find -type d | wc -l and got the number 11 but when I do a ls -F to verify how many directories I have, I only see two directories. How it comes that the command find -type d | wc -l gives me 11 ?

Regards
 
Old 04-15-2005, 10:42 AM   #4
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Oups! sorry I didn't notice the subdirectories. So I have not 2 directories but 12 and when I do the command find -type d | wc -l the output is 13. So it's counting also the directory I am currently in. Is there a way to ignore this directory ?

Regards
 
Old 04-15-2005, 11:24 AM   #5
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
find -type d | wc -l | awk '{print $1-1}'


You can try those commands separatedly.
  • Find is used to find files or directories. Argument "-type d" limits search to only diretories.
    Typing just
    Code:
    find -type d
    gives you a listing of those directories.
  • wc is an acronym from word count. It is used to count bytes, words or lines.
    Parameter "-l" means to show only number of lines in the input (which was this case the output of previous command). You can test this eg. by writing
    Code:
    wc
    , typing something and hitting ctrl-d (means end of buffer) at the end and examine the output.

    Other ways to test it is like
    Code:
     cat /etc/inittab | wc
    (cat is used to type files to output[generally screen, in this case as input to wc]).
  • The last command is awk, a small programming language called with a command '{print $1-1}', which means that for every line in the input, print the first field(a section in the line separated by space or enter) minus one.

    You can test this by writing
    Code:
    awk '{print $1-1}'
    and typing some numbers. (hit ctrl-d to end)


You might want to also try commands
Code:
man find
,
Code:
man wc
and
Code:
man awk
.

Also typing
Code:
info coreutils
gives you a good overview of the toolbox that
is available to the shell.

Last edited by ToniT; 04-15-2005 at 11:26 AM.
 
Old 04-18-2005, 04:04 AM   #6
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks a lot ToniT!

That was a great and well explained tutorial ! itís uncredible how powerful shell commands can be.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM
How many total TCP sockets can my linux box have? how can I check the number used? abefroman Linux - Networking 2 11-09-2005 03:11 PM
How can I see the total number of file locks being currently used? abefroman Linux - Software 1 11-08-2005 06:16 PM
Number of files and directories ALF Linux - Software 4 06-11-2003 10:34 AM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:23 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration