Operating System - HP-UX
1748225 Members
4720 Online
108759 Solutions
New Discussion

Re: How list unix files only excluding folders ?

 
SOLVED
Go to solution
SwissKnife
Frequent Advisor

How list unix files only excluding folders ?

Hi,

How list unix files only excluding folders ?

Kind regards,

Den.

5 REPLIES 5
Solution

Re: How list unix files only excluding folders ?

Quick & Dirty?

 ls -1p | grep -v '.*/'

I am an HPE Employee
Accept or Kudo
Steven Schweda
Honored Contributor

Re: How list unix files only excluding folders ?

> How list unix files only excluding folders ?

   Define "list".  Which files?

mba$ ls -ld test*
-rwxr-xr-x  1 sms  staff  8720 Aug 15  2015 test
-rw-r--r--  1 sms  staff    90 Aug 15  2015 test.c
drwxr-xr-x  3 sms  staff   102 Aug 15  2015 test.dSYM

mba$ ls -ld test* | grep -v '^d'
-rwxr-xr-x  1 sms  staff  8720 Aug 15  2015 test
-rw-r--r--  1 sms  staff    90 Aug 15  2015 test.c

mba$ find . -name 'test*'
./test
./test.c
./test.dSYM
./test.dSYM/Contents/Resources/DWARF/test

mba$ find . -name 'test*' ! -type d
./test
./test.c
./test.dSYM/Contents/Resources/DWARF/test

   As usual, many things are possible, depending on exactly what you
want to do.

SwissKnife
Frequent Advisor

Re: How list unix files only excluding folders ?

Hi,

 

thanks folks, very appreciated.

 

Both solution:

ls -1p | grep -v '.*/'
and
ls -ld test* | grep -v '^d'

 Looks good.

I prefer the 1st.

 

Kind regards, Den.

 

Patrick Wallek
Honored Contributor

Re: How list unix files only excluding folders ?

>>mba$ find . -name 'test*' ! -type d

 

Or there's always:

 

$ find . -type f

Steven Schweda
Honored Contributor

Re: How list unix files only excluding folders ?

> >>mba$ find . -name 'test*' ! -type d
>
> Or there's always:
>
> $ find . -type f

   It depends, of course, on whether we believe "files only" or
"excluding folders".  In "man find", look for "-type", where one might
find more than two categories.  For example:

             [...] Possible file types are as follows:

             b       block special
             c       character special
             d       directory
             f       regular file
             l       symbolic link
             p       FIFO
             s       socket

>    As usual, many things are possible, depending on exactly what you
> want to do.

   Still true, I claim.