Thread: question about testing in shell programming

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    41

    question about testing in shell programming

    hi
    How can i list files which are only folders in Unix
    Tuan

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    find . -type d -print

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    -print is the default. "." is also the default directory. So you can get away with
    Code:
    find -type d
    ("d" means of type "directory") or
    Code:
    find path -type d
    Note that find is recursive -- it will show you subdirectories and so on too. If you just want a list of directories in the current directory, you can use something like this.
    Code:
    ls -l | grep ^d
    That gives you the long filename listing, however, which you may not want. If you just want the filenames, you could use something like this:
    Code:
    for file in *; do [ -d "$file" ] && echo $file; done
    I'm sure there's a cleaner way, but if there is, it escapes me at the moment.
    Last edited by dwks; 04-04-2008 at 07:32 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shell script basic question
    By PedroTuga in forum Linux Programming
    Replies: 1
    Last Post: 09-09-2006, 03:24 AM
  2. Testing user input question?
    By Hoser83 in forum C Programming
    Replies: 18
    Last Post: 02-15-2006, 01:18 PM
  3. Hi everyone..Testing strings and if question
    By tinkerbell20 in forum C++ Programming
    Replies: 7
    Last Post: 06-21-2005, 06:23 AM
  4. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM
  5. shell scripts?
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 05-06-2002, 05:43 AM