Find the answer to your Linux question:
Results 1 to 3 of 3
Hi! I am new to C Shell. I would like to write a script which able to search through a folder which might have files and many subdirectories in it. ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    1

    Question C Shell How to search through empty subdirectories?

    Hi! I am new to C Shell. I would like to write a script which able to search through a folder which might have files and many subdirectories in it. How can I return value = true if the main folder having empty subdirectory? Thanks.

  2. #2
    Just Joined!
    Join Date
    Apr 2008
    Location
    Bosnia
    Posts
    4
    Hi,

    Probably something like this

    search=$*

    if test -z "$*"
    else
    cd $search
    # Make links in folder for every file
    for f in $(find ~ | grep -i "$search" | grep -v "$(pwd)" | grep -v ".Trash" | sed s/[\ ]/{}/g)
    do
    file=$(echo $f | sed s/{}/\ /g ) # return spaces
    link="$(date +"%H%M%S-%N")-$(basename "$file")"
    ln -s "$file" "$link"
    done
    zenity --info --text="Done"
    fi

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Moving to a more appropriate forum.

    I'm having difficulty following Mirza's solution, so I'm not sure that it's doing what you want.

    First of all, is there a reason that you're using the C shell? It's not particularly common: most people these days use Bash, with some people moving to zsh.

    Having said that, here's the basic procedure you want to follow:

    Given a start directory, check its contents.
    - Is it empty? Return true.
    - Does it contain any directories? If not, return false.
    Otherwise, add all of its directories to a queue, take the first element of the queue, make it the new start directory, and repeat.

    Does that make sense?
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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