How can I exclude certain files and directories when run ls -laR?

How can I exclude certain files and directories when run ls -laR?

am 17.10.2007 17:57:29 von jzhang2006

How can I exclude certain files and directories when run ls -laR >
output?

Suppose I have following directory structure:


auto/ mystuffs/ cache/ logs/ department/ sche.txt testing.txt

I DO NOT want directory logs, auto and file sche.txt in my output
file, how can I exclude them?

Thanks,

J

Re: How can I exclude certain files and directories when run ls -laR?

am 17.10.2007 17:58:54 von Joachim Schmitz

schrieb im Newsbeitrag
news:1192636649.617607.10570@q3g2000prf.googlegroups.com...
> How can I exclude certain files and directories when run ls -laR >
> output?
>
> Suppose I have following directory structure:
>
>
> auto/ mystuffs/ cache/ logs/ department/ sche.txt testing.txt
>
> I DO NOT want directory logs, auto and file sche.txt in my output
> file, how can I exclude them?
ls -laR mystuffs cache departement testing.txt

Bye, Jojo

Re: How can I exclude certain files and directories when run ls -laR?

am 17.10.2007 18:04:02 von cichomitiko

jzhang2006@gmail.com wrote:
> How can I exclude certain files and directories when run ls -laR >
> output?
>
> Suppose I have following directory structure:
>
>
> auto/ mystuffs/ cache/ logs/ department/ sche.txt testing.txt
>
> I DO NOT want directory logs, auto and file sche.txt in my output
> file, how can I exclude them?
[...]

ksh:

ls -laR !(logs|auto|sche.txt)

bash:

shopt -s extglob
ls -laR !(logs|auto|sche.txt)

zsh:

setopt kshglob
ls -laR !(logs|auto|sche.txt)

(or use the zsh extended globbing - it has a different syntax)


Dimitre

Re: How can I exclude certain files and directories when run ls -laR?

am 17.10.2007 18:45:02 von jzhang2006

On Oct 17, 12:04 pm, "Radoulov, Dimitre"
wrote:
> jzhang2...@gmail.com wrote:
> > How can I exclude certain files and directories when run ls -laR >
> > output?
>
> > Suppose I have following directory structure:
>
> > auto/ mystuffs/ cache/ logs/ department/ sche.txt testing.txt
>
> > I DO NOT want directory logs, auto and file sche.txt in my output
> > file, how can I exclude them?
>
> [...]
>
> ksh:
>
> ls -laR !(logs|auto|sche.txt)
>
> bash:
>
> shopt -s extglob
> ls -laR !(logs|auto|sche.txt)
>
> zsh:
>
> setopt kshglob
> ls -laR !(logs|auto|sche.txt)
>
> (or use the zsh extended globbing - it has a different syntax)
>
> Dimitre

Thanks, Dimitre. The ksh seems work fine. One question:

If I do not want to run this script from the current directory. Say,
the current directory is /home/XYZ/eng/test/. My script is in /home/
ABC/build. Then if I want to list the content of /home/XYZ/eng/test/,
with exclusion of logs, auto and sche.txt. How can i run it? I would
run:

ls -laR /home/XYZ/eng/test/ !(logs|auto|sche.txt)

It does not seem to work that way. Advice?

J

Re: How can I exclude certain files and directories when run ls -laR?

am 17.10.2007 20:51:56 von cichomitiko

wrote in message ...
> On Oct 17, 12:04 pm, "Radoulov, Dimitre"
> wrote:
>> jzhang2...@gmail.com wrote:
>> > How can I exclude certain files and directories when run ls -laR >
>> > output?
>>
>> > Suppose I have following directory structure:
>>
>> > auto/ mystuffs/ cache/ logs/ department/ sche.txt testing.txt
>>
>> > I DO NOT want directory logs, auto and file sche.txt in my output
>> > file, how can I exclude them?
>>
>> [...]
>>
>> ksh:
>>
>> ls -laR !(logs|auto|sche.txt)
>>
>> bash:
>>
>> shopt -s extglob
>> ls -laR !(logs|auto|sche.txt)
>>
>> zsh:
>>
>> setopt kshglob
>> ls -laR !(logs|auto|sche.txt)
>>
>> (or use the zsh extended globbing - it has a different syntax)
>>
>> Dimitre
>
> Thanks, Dimitre. The ksh seems work fine. One question:
>
> If I do not want to run this script from the current directory. Say,
> the current directory is /home/XYZ/eng/test/. My script is in /home/
> ABC/build. Then if I want to list the content of /home/XYZ/eng/test/,
> with exclusion of logs, auto and sche.txt. How can i run it? I would
> run:
>
> ls -laR /home/XYZ/eng/test/ !(logs|auto|sche.txt)
>
> It does not seem to work that way. Advice?

It does. It's

ls -laR /home/XYZ/eng/test/!(logs|auto|sche.txt),

not

ls -laR /home/XYZ/eng/test/ !(logs|auto|sche.txt)

(no space between / and !)


Dimitre