<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: List only filenames in a directory in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244672#M614367</link>
    <description>Elmar, &lt;BR /&gt;&lt;BR /&gt;Can you please explain the [*/=&amp;gt;@|]$ part in your sed statement ?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Brecht</description>
    <pubDate>Tue, 22 Jun 2010 09:02:31 GMT</pubDate>
    <dc:creator>Brecht De Baets</dc:creator>
    <dc:date>2010-06-22T09:02:31Z</dc:date>
    <item>
      <title>List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244652#M614347</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I want to list only the files in a directory (so no subdirectories and just the filenames). The result should be in a new file called files.txt.&lt;BR /&gt;So far I have used the following statement :&lt;BR /&gt;ls -l | grep ^- | awk '{print $9}' &amp;gt; files.txt&lt;BR /&gt;&lt;BR /&gt;In certain directories I have filenames like :&lt;BR /&gt;1    3.doc&lt;BR /&gt;&lt;BR /&gt;The statement above only gives the following result :&lt;BR /&gt;1 &lt;BR /&gt;&lt;BR /&gt;I have also tried the following :&lt;BR /&gt;ls -l | grep ^- | awk '{for (i=9; i&amp;lt;=NF; i++) {printf("%s ", $i)} printf("\n")}' &amp;gt; files.txt&lt;BR /&gt;&lt;BR /&gt;But now the result is :&lt;BR /&gt;1 3.doc&lt;BR /&gt;&lt;BR /&gt;Is there a way to become the full filename with all the spaces in it(so 1    3.doc) ?&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Mon, 21 Jun 2010 11:25:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244652#M614347</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T11:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244653#M614348</link>
      <description>Brecht,&lt;BR /&gt;What about:&lt;BR /&gt;# find . -type f -exec ls -l {} \; | cut -c 59-&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Raj.</description>
      <pubDate>Mon, 21 Jun 2010 11:29:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244653#M614348</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2010-06-21T11:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244654#M614349</link>
      <description>Thanks for the reply,&lt;BR /&gt;&lt;BR /&gt;If I use the statement you posted, I also see the directory-structure, so :&lt;BR /&gt;&lt;BR /&gt;/mnt/appserv/ontwikkel/1   3.doc    &lt;BR /&gt;&lt;BR /&gt;I only need the filename.&lt;BR /&gt;&lt;BR /&gt;Regards,</description>
      <pubDate>Mon, 21 Jun 2010 11:35:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244654#M614349</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T11:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244655#M614350</link>
      <description>&lt;!--!*#--&gt;&amp;gt;But now the result is: 1 3.doc&lt;BR /&gt;&lt;BR /&gt;Isn't that what you want?  (If you are complaining about the trailing space, you must explicitly mention it, since we can't see them.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Is there a way to become the full filename with all the spaces in it (so 1 3.doc)?&lt;BR /&gt;&lt;BR /&gt;Well, you can smarten up your awk script:&lt;BR /&gt;ll | awk '&lt;BR /&gt;/^-/ {&lt;BR /&gt;   for (i=9; i &amp;lt; NF; ++i)&lt;BR /&gt;      printf("%s ", $i)&lt;BR /&gt;   printf("%s\n", $NF)&lt;BR /&gt;}' &amp;gt; files.txt&lt;BR /&gt;&lt;BR /&gt;Or you can use find(1) with -prune:&lt;BR /&gt;find . ! -name . -prune -o -type -f -print&lt;BR /&gt;&lt;BR /&gt;The names will have leading "./".</description>
      <pubDate>Mon, 21 Jun 2010 11:39:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244655#M614350</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244656#M614351</link>
      <description># ls -l | grep ^- |cut -c 59-  #Cheers.&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Jun 2010 11:56:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244656#M614351</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2010-06-21T11:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244657#M614352</link>
      <description>My actual filename contains more than 1 space, so 1spacespacespacespace3.doc (the editor of the forum threw the extra spaces away).&lt;BR /&gt;&lt;BR /&gt;The result with the awk command returns the filename with only 1 space.&lt;BR /&gt;&lt;BR /&gt;The statement :&lt;BR /&gt;"find . ! -name . -prune -o -type -f -print"&lt;BR /&gt;returns an error&lt;BR /&gt;&lt;BR /&gt;I also needs something to cut the directories away, so I only get the filename as a result.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Brecht</description>
      <pubDate>Mon, 21 Jun 2010 11:57:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244657#M614352</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T11:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244658#M614353</link>
      <description>&amp;gt;the editor of the forum threw the extra spaces away.&lt;BR /&gt;&lt;BR /&gt;Right, you need to mention it or attach a file.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;The result with the awk command returns the filename with only 1 space.&lt;BR /&gt;&lt;BR /&gt;You could smarten up awk by using index to find your $9 string and then use substr but $9 may not be unique.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;"find . ! -name . -prune -o -type -f -print" returns an error&lt;BR /&gt;&lt;BR /&gt;Sorry, not -f:&lt;BR /&gt;find . ! -name . -prune -o -type f -print&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I also need something to cut the directories away&lt;BR /&gt;&lt;BR /&gt;That's the easy part, for ".":  :-)&lt;BR /&gt;find . ! -name . -prune -o -type f -print |&lt;BR /&gt;  sed -e 's:^\./::'</description>
      <pubDate>Mon, 21 Jun 2010 12:10:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244658#M614353</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T12:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244659#M614354</link>
      <description>&amp;gt;ls -l | grep ^- | cut -c 59- solved my problem.&lt;BR /&gt;&lt;BR /&gt;Just wait until you have a file with more than the default field width for the filesize.</description>
      <pubDate>Mon, 21 Jun 2010 12:12:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244659#M614354</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T12:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244660#M614355</link>
      <description>Point taken, Dennis.&lt;BR /&gt;&lt;BR /&gt;find . ! -name . -prune -o -type f -print |&lt;BR /&gt;sed -e 's:^\./::' is indeed a better statement.&lt;BR /&gt;&lt;BR /&gt;I had to exclude the -print option. Otherwise it returned nothing ?&lt;BR /&gt;&lt;BR /&gt;Also, when I replace the .(local dir) with the directory to search in, I don't get the filename but the directory itself, so :&lt;BR /&gt;&lt;BR /&gt;find /mnt/appserv/ontwikkel ! -name . -prune -o -type f -print | sed -e 's:^\./::'&lt;BR /&gt;&lt;BR /&gt;gives as a result : &lt;BR /&gt;&lt;BR /&gt;/mnt/appserv/ontwikkel&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Mon, 21 Jun 2010 12:31:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244660#M614355</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T12:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244661#M614356</link>
      <description>&amp;gt;I had to exclude the -print option. Otherwise it returned nothing?&lt;BR /&gt;&lt;BR /&gt;(Sorry, I can't get to my HP-UX system until tomorrow.  From what I remember, you need that -print right there.&lt;BR /&gt;Which part returned nothing, the find or the whole pipeline?)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;when I replace the .(local dir) with the directory to search in, I don't get the filename but the directory itself, so:&lt;BR /&gt;find /mnt/appserv/ontwikkel ! -name . -prune -o -type f -print | sed -e 's:^\./::'&lt;BR /&gt;&lt;BR /&gt;The monkey (cherchez le singe!) principle indicates you change all of the "." with /mnt/appserv/ontwikkel:&lt;BR /&gt;DIR=/mnt/appserv/ontwikkel&lt;BR /&gt;find $DIR ! -name $DIR -prune -o -type f -print | sed -e "s:^$DIR/::"&lt;BR /&gt;&lt;BR /&gt;Or cd to that directory then use "find .".</description>
      <pubDate>Mon, 21 Jun 2010 12:42:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244661#M614356</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T12:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244662#M614357</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;The following statement gives the expected result :&lt;BR /&gt;&lt;BR /&gt;find $DIR -type f | sed -e "s:^$DIR/::"&lt;BR /&gt;&lt;BR /&gt;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).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Brecht</description>
      <pubDate>Mon, 21 Jun 2010 13:14:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244662#M614357</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T13:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244663#M614358</link>
      <description>&amp;gt;The following statement gives the expected result&lt;BR /&gt;&lt;BR /&gt;The -prune option was in case you had subdirectories.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;if I include them I only get to see the directory without the filename.&lt;BR /&gt;&lt;BR /&gt;I'll do some testing when I get back to make sure it isn't something obvious:&lt;BR /&gt;Ah, if you don't have ".", you have to use:&lt;BR /&gt;find $DIR ! -path $DIR -prune -o -type f -print | sed -e "s:^$DIR/::"&lt;BR /&gt;&lt;BR /&gt;Or: -name $(basename $DIR)</description>
      <pubDate>Mon, 21 Jun 2010 13:27:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244663#M614358</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T13:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244664#M614359</link>
      <description>Thanks Dennis,&lt;BR /&gt;&lt;BR /&gt;Actually I can have subdirectories, but I don't need to see them.&lt;BR /&gt;&lt;BR /&gt;The statement &lt;BR /&gt;&lt;BR /&gt;find $DIR ! -path $DIR -prune -o -type f | sed -e "s:^$DIR/::" &lt;BR /&gt;&lt;BR /&gt;gives a nice result, but if there are some subdirectories onder the $DIR directory, they are also listed. &lt;BR /&gt;How can they be left away ?&lt;BR /&gt;&lt;BR /&gt;For example : under $DIR, I have :&lt;BR /&gt;1 file (test.dat) and one not-empty directory (testdir). If I issue the above statement, I get :&lt;BR /&gt;&lt;BR /&gt;test.dat&lt;BR /&gt;testdir&lt;BR /&gt;&lt;BR /&gt;However I only want test.dat to be displayed.</description>
      <pubDate>Mon, 21 Jun 2010 13:46:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244664#M614359</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-21T13:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244665#M614360</link>
      <description>&amp;gt;I can have subdirectories, but I don't need to see them.&lt;BR /&gt;&lt;BR /&gt;That -prune should skip those.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;find $DIR ! -path $DIR -prune -o -type f | sed -e "s:^$DIR/::"&lt;BR /&gt;&amp;gt;gives a nice result, but if there are some subdirectories under the $DIR directory, they are also listed.  How can they be left away?&lt;BR /&gt;&amp;gt;I only want test.dat to be displayed.&lt;BR /&gt;&lt;BR /&gt;That's what the "-print" on the end should do.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Jun 2010 13:57:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244665#M614360</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-21T13:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244666#M614361</link>
      <description>Hi Dennis,&lt;BR /&gt;&lt;BR /&gt;If I add the -print option again, I don't get any results ?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Brecht</description>
      <pubDate>Tue, 22 Jun 2010 06:02:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244666#M614361</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-22T06:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244667#M614362</link>
      <description>A solution might also be:&lt;BR /&gt;&lt;BR /&gt;ls -aF | grep -v /$ | sed 's|[*/=&amp;gt;@|]$||' &amp;gt;files.txt&lt;BR /&gt;&lt;BR /&gt;Or a variant. (Some tools might combine the grep and sed, for instance...)</description>
      <pubDate>Tue, 22 Jun 2010 06:28:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244667#M614362</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2010-06-22T06:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244668#M614363</link>
      <description>&amp;gt;If I add the -print option again, I don't get any results?&lt;BR /&gt;&lt;BR /&gt;What is the exact command you are using so I can try to duplicate it?</description>
      <pubDate>Tue, 22 Jun 2010 07:24:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244668#M614363</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-06-22T07:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244669#M614364</link>
      <description>Dennis,&lt;BR /&gt;&lt;BR /&gt;find $DIR ! -path $DIR -prune -o -type f -print | sed -e "s:^$DIR::"&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Brecht&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2010 07:36:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244669#M614364</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-22T07:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244670#M614365</link>
      <description>Brecht, # ls -l|grep ^- | awk '{for(i=1;i&amp;lt;9;i++) {$i=""};print}' |sed 's/^[ ]*//g' #Cheers</description>
      <pubDate>Tue, 22 Jun 2010 08:08:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244670#M614365</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2010-06-22T08:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: List only filenames in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244671#M614366</link>
      <description>Thanks for the replies :&lt;BR /&gt;&lt;BR /&gt;Elmar, your statement seems to work fine !&lt;BR /&gt;&lt;BR /&gt;Raj, If I try your statement, I lose some spaces in filenames with more than 1 space.&lt;BR /&gt;For example filename 1spacespacespace2.dat&lt;BR /&gt;return 1space2.dat.</description>
      <pubDate>Tue, 22 Jun 2010 08:59:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/list-only-filenames-in-a-directory/m-p/5244671#M614366</guid>
      <dc:creator>Brecht De Baets</dc:creator>
      <dc:date>2010-06-22T08:59:52Z</dc:date>
    </item>
  </channel>
</rss>

