Find the answer to your Linux question:
Results 1 to 2 of 2
I have an array setup: nodirs=("virtfs" "lost+found" "domlogs") for x in `ls /home` do if [-d $x ] then echo $x fi done That will print and output of all ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2

    BASH: traverse *some* directories

    I have an array setup:

    nodirs=("virtfs" "lost+found" "domlogs")

    for x in `ls /home`
    do
    if [-d $x ]
    then
    echo $x
    fi
    done

    That will print and output of all dirs under home, I want to avoid anything in the 'nodirs' array. I plan on going into each of those dirs and doing trivial task like 'du' and other things.

    BASH array is very difficult for conditional. If anyone could help with conditional so it no traverse into any value in 'nodirs' array I would be greatful much so.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    539
    you could pass the result through egrep with -v to negate the match:

    Code:
    ls /home | egrep -v "virtfs|lost\+found|domlogs"
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...