Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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
share|improve this answer
    
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
find /path/to/dir -name .htaccess -delete
share|improve this answer
    
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 Nov 4 '11 at 20:12

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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