- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: List only filenames in a directory
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
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
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
тАО06-21-2010 06:14 AM
тАО06-21-2010 06:14 AM
Re: List only filenames in a directory
The following statement gives the expected result :
find $DIR -type f | sed -e "s:^$DIR/::"
Actually, I don't seem to need the -prune and the -name options (if I include them I only get to see the directory without the filename).
Regards,
Brecht
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2010 06:27 AM
тАО06-21-2010 06:27 AM
Re: List only filenames in a directory
The -prune option was in case you had subdirectories.
>if I include them I only get to see the directory without the filename.
I'll do some testing when I get back to make sure it isn't something obvious:
Ah, if you don't have ".", you have to use:
find $DIR ! -path $DIR -prune -o -type f -print | sed -e "s:^$DIR/::"
Or: -name $(basename $DIR)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2010 06:46 AM
тАО06-21-2010 06:46 AM
Re: List only filenames in a directory
Actually I can have subdirectories, but I don't need to see them.
The statement
find $DIR ! -path $DIR -prune -o -type f | sed -e "s:^$DIR/::"
gives a nice result, but if there are some subdirectories onder the $DIR directory, they are also listed.
How can they be left away ?
For example : under $DIR, I have :
1 file (test.dat) and one not-empty directory (testdir). If I issue the above statement, I get :
test.dat
testdir
However I only want test.dat to be displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2010 06:57 AM
тАО06-21-2010 06:57 AM
Re: List only filenames in a directory
That -prune should skip those.
>find $DIR ! -path $DIR -prune -o -type f | sed -e "s:^$DIR/::"
>gives a nice result, but if there are some subdirectories under the $DIR directory, they are also listed. How can they be left away?
>I only want test.dat to be displayed.
That's what the "-print" on the end should do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2010 11:02 PM
тАО06-21-2010 11:02 PM
Re: List only filenames in a directory
If I add the -print option again, I don't get any results ?
Regards,
Brecht
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2010 11:28 PM
тАО06-21-2010 11:28 PM
Solutionls -aF | grep -v /$ | sed 's|[*/=>@|]$||' >files.txt
Or a variant. (Some tools might combine the grep and sed, for instance...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2010 12:24 AM
тАО06-22-2010 12:24 AM
Re: List only filenames in a directory
What is the exact command you are using so I can try to duplicate it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2010 12:36 AM
тАО06-22-2010 12:36 AM
Re: List only filenames in a directory
find $DIR ! -path $DIR -prune -o -type f -print | sed -e "s:^$DIR::"
Regards,
Brecht
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2010 01:08 AM
тАО06-22-2010 01:08 AM
Re: List only filenames in a directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2010 01:59 AM
тАО06-22-2010 01:59 AM
Re: List only filenames in a directory
Elmar, your statement seems to work fine !
Raj, If I try your statement, I lose some spaces in filenames with more than 1 space.
For example filename 1spacespacespace2.dat
return 1space2.dat.