- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- list only directories
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2013 08:52 AM
03-27-2013 08:52 AM
hello,
i want to list in a directory all directories, but i have to exclude files and other directories
old way was "ls" ( but this command include files)
ls
Output
dir1
dir2
better way is "find"
find . \( -name . -o -prune \) -type d
Output
.
./dir1
./dir2
but does a better way exist to exclude "./" and "." . it should the same
output like "ls" (without files)
find . \( -name . -o -prune \) -type d | sed "s|./||g" | sort |grep -v "\."
regards
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2013 09:30 AM
03-27-2013 09:30 AM
Re: list only directories
How about:
ls -F | grep '/$'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2013 09:38 AM
03-27-2013 09:38 AM
Re: list only directories
How about:
# find . -type d ! \( -name . -o -name .. \) ./.ssh ./.sw ./.sw/sessions ./.sw/targets ./.sw/software ./bin ./.swa ./.swa/cache ./.swa/report ./DR ./progs ./progs/exe ./progs/memoryAllocation ./progs/memoryAllocation/progs ./progs/tapeinfo ./.elm ./Mail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2013 10:54 PM
03-27-2013 10:54 PM
Re: list only directories
You can just use this below to list directories.
ls -l | grep ^d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2013 11:20 PM
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2013 02:40 AM
03-28-2013 02:40 AM
Re: list only directories
this is the best solution :
find * -name . -o -prune -type d -print
my comments to the another solutions :
@ Dennis Handly
find * -name . -o -prune -type d -print
Perfect
@ "*" gets rid if "./" and using -print (properly) gets rid of ".".
@ But "*" will fail if too many files.
this applikation exist approximately 250 directories , so it works perfect.
i also tested the "find" command with approximately 60.000 files and a lot of
subdirectories. it works also without problems.
@ Matti_Kurkela
ls -F | grep '/$'
i need another cmd to replace ending "/" like :
ls -F | grep '/$' | sed "s|/$||g"
@ karthikbalu
ls -l | grep ^d
i need another cmd to get the directory like :
ls -l | grep ^d | awk '{ print $NF}'
@Patrick
find . -type d ! \( -name . -o -name .. \)
It includes also subdirectories like ./dir1/subdir2
better
find . -type d ! \( -name . -o -name .. \) -prune
but i also need another cmd to replace leading "./" like :
find . -type d ! \( -name . -o -name .. \) -prune |sed "s|^./||g"
regards
- Tags:
- find