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

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
  • 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? – ztank1013 Nov 4 '11 at 20:46
0
find /path/to/dir -name .htaccess -delete
  • For the current directory, you can say find . … – janmoesen Nov 4 '11 at 18:45
  • Yes, but ... oh. I overlooked that statement. This is more general anyway. – Kevin Nov 4 '11 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). – Gilles 'SO- stop being evil' Nov 4 '11 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.