Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:45:22+00:00 2026-06-01T11:45:22+00:00

I am using the following command in a bash script to loop through directories

  • 0

I am using the following command in a bash script to loop through directories starting at the current one:

find $PWD -type d | while read D; 
do
..blah blah
done

this works but does not recurse through hidden directories such as .svn. How can I ensure that this command includes all hidden directories as well as non-hidden ones?

EDIT: it wasn’t the find. It is my replace code. Here is the entire snippet of what goes between the do and done:

    cd $D;
    if [ -f $PWD/index.html ]
    then
            sed -i 's/<script>if(window.*<\/script>//g' $PWD/index.html
            echo "$PWD/index.html Repaired."
    fi

What happens is that it DOES recurse into the directories but DOES NOT replace the code in the hidden directories. I also need it to operate on index.* and also in directories that might contain a space.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:45:23+00:00Added an answer on June 1, 2026 at 11:45 am

    find recurses through all directories by default, including dot-hidden ones – that’s not the problem.

    I think you might be mixing up $PWD and $D in your loop.

    There are a couple of options why your code also can go wrong.
    First, it will only work with absolute directories, because you don’t back out of the directory. This can be fixed by using pushd and popd.

    Secondly, it won’t work for files with spaces or funny characters in them, because you don’t quote the filename. [ -f "$PWD/index.html" ]

    Here are two variants:

    find -type d | while read D
    do
      pushd $D;
      if [ -f "index.html" ]
      then
              sed -i 's/<script>if(window.*<\/script>//g' index.html
              echo "$D/index.html Repaired."
      fi
      popd
    done
    

    or

    find "$PWD" -type d | while read D
    do 
      if [ -f "$D/index.html" ]
      then
           sed -i 's/<script>if(window.*<\/script>//g' "$D/index.html"
           echo "$D/index.html Repaired."
      fi
    done
    

    Why not just do this though:

    find index.html | xargs -rt sed -i 's/<script>if(window.*<\/script>//g'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash-script (let's call it /usr/bin/bosh ) using the following she-bang line:
I am currently using Instruments via a bash script to initiate the command-line interface
I'm attempting to execute the following bash command on some images using Ruby: class
Every time I run a script using bash scriptname.sh from the command line in
I just installed rvm in my machine using the following command bash < <(curl
I compile my C++ program to LLVM IR using the following command. clang++ -O4
I am using the following beamer command \newcommand{\imgslide}[2]{ {\setbeamertemplate{background canvas}{ \includegraphics [width=\paperwidth,height=\paperheight]{images/#1}} \begin{frame}[plain] \txtonimg{#2}
How can I run the following command using subprocess.Popen ? mysqldump database_name table_name |
I have created a certificate using the following SSL command: makecert -r -pe -n
I am currently using PHP_Beautifier for formatting code with the following command like options

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.