From: moonhkt on
Hi All

I try to list out all the files under particular directory. Some files
without extension.
How to ignore Directory by ls ?

e.g.

#!/bin/ksh
MDIR=/phx/migration
for i in $MDIR/load $MDIR/src
do
echo $i
cd $i
CURRDIR=`pwd`
echo CURRDIR=$CURRDIR
ls * *.*
done
From: Sidney Lambe on
On comp.unix.shell, moonhkt <moonhkt(a)gmail.com> wrote:
> Hi All
>
> I try to list out all the files under particular directory. Some files
> without extension.
> How to ignore Directory by ls ?
>
> e.g.
>
> #!/bin/ksh
> MDIR=/phx/migration
> for i in $MDIR/load $MDIR/src
> do
> echo $i
> cd $i
> CURRDIR=`pwd`
> echo CURRDIR=$CURRDIR
> ls * *.*
> done

I don't think you can do that with just ls.

/bin/ls -p | sed '/[\/=@|]/d'

That will remove everything that isn't a simple file
from the listing. Named pipes and symbolic links and
sockets and directories.

Sid
From: Thomas 'PointedEars' Lahn on
moonhkt wrote:

> I try to list out all the files under particular directory. Some files
> without extension.

Filename extension is a WinDOS concept. This is comp.*unix*.shell.

> How to ignore Directory by ls ?

One wonders if you ever RTFM before posting.

> e.g.
>
> #!/bin/ksh
> MDIR=/phx/migration
> for i in $MDIR/load $MDIR/src

Can be compacted to

for i in $MDIR/{load,src}

But you really don't want to use `for' here (consider $IFS in filenames).

> do
> echo $i
> cd $i

Here you go down the tree, but you never go up again.

> CURRDIR=`pwd`
> echo CURRDIR=$CURRDIR
> ls * *.*
> done

find -L $MDIR/{load,src} ! -type d

is a lot better, of course (-L dereferences symlinks, so you can exclude
symlinked directories as well).

man find


PointedEars
From: pk on
Thomas 'PointedEars' Lahn wrote:

>> #!/bin/ksh
>> MDIR=/phx/migration
>> for i in $MDIR/load $MDIR/src
>
> Can be compacted to
>
> for i in $MDIR/{load,src}
>
> But you really don't want to use `for' here (consider $IFS in filenames).

If what you're saying was true, then

for i in *

will never work when filenames have $IFS in them.

From: Bill Marcum on
On 2010-03-29, moonhkt <moonhkt(a)gmail.com> wrote:
> Hi All
>
> I try to list out all the files under particular directory. Some files
> without extension.
> How to ignore Directory by ls ?
>
> e.g.
>
> #!/bin/ksh
> MDIR=/phx/migration
> for i in $MDIR/load $MDIR/src
> do
> echo $i
> cd $i
> CURRDIR=`pwd`
> echo CURRDIR=$CURRDIR
> ls * *.*
> done
ls * will list all the files that aren't hidden, you don't need *.*
To list all files including hidden files, use ls -a.


--
THEY'RE IN UR BED, EATING UR DREAMZ