4

I used this one to copy file in every dir:

find -type d -maxdepth 1 -print0 | xargs -0 -n1 cp .htaccess

Now i need to do reverse one and delete file with matching name from every sub directory of one i am currently in

3 Answers 3

4

If I understand your description correctly, you want to remove .htaccess from subdirectories of the current directory, but not from their subdirectories. In other words, you want to remove foo/.htaccess but not foo/bar/.htaccess. Then it's simple:

rm */.htaccess

You could have done without find for your initial command. find is mostly useful when you want to traverse a directory recursively, i.e. apply to the subdirectories and subsubdirectories and so on.

for d in */; do cp -p .htaccess "$d"; done
1
  • Wow! the */ is new for me, thanks! BTW I am quite sure the author just want to roll back the initial find. Maybe we should ask? Commented Nov 4, 2011 at 20:46
0
find /path/to/dir -name .htaccess -delete
3
  • For the current directory, you can say find . … Commented Nov 4, 2011 at 18:45
  • Yes, but ... oh. I overlooked that statement. This is more general anyway. Commented Nov 4, 2011 at 18:50
  • This traverses the directory recursively, I don't think that was meant (given the -maxdepth 1 in the question, there's no implied recursivity). Commented Nov 4, 2011 at 20:12
0

The following assumes you previously run the find -type d -maxdepth 1 -print0 | xargs -0 -n1 cp .htaccess from the same directory you will run this one:

find . -maxdepth 2 -type f -name .htaccess -exec rm -v {} \;

The -v (verbose) option is optional but it helps to see what files are actually deleted.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.