Prev: Sed & Awk (was: Re: Printf - Columns/Tables)
Next: building the printf format for a variable number of args
From: moonhkt on 29 Mar 2010 05:32 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 29 Mar 2010 07:18 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 29 Mar 2010 08:49 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 29 Mar 2010 09:03 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 29 Mar 2010 10:14 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
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Sed & Awk (was: Re: Printf - Columns/Tables) Next: building the printf format for a variable number of args |