LogicLooking
LogicLooking

Reputation: 928

Deleting directories in bash

This is a simple command: rm -rf dir But i have an interesting problem to solve. My bash script calls composer install on a composer script, this then makes vendor/app-name/ in the directory the composer install was run in. which is fine, the problem is I am now doing something like:

cp -R /vendor/ . 
# I believe this is correct for copying everything 
# out out of vendor and into root

to copy everything from vendor. Ok that's define, but there could be 300 app-name folders in there (obviously all with different names other then app-name), each might have a .gitignore, .git directory or a documentation Directory. I want to say:

Walk through each of the folders, looking for .git/, .gitignore or Documentation and delete them if found.

How can I do this in bash?

note: All the packages that are being pulled down are pulled down via git, how ever the user may choose to add additional ones pulled down from composer package land. the same concepts should still apply.

Upvotes: 0

Views: 3630

Answers (2)

Малъ Скрылевъ
Малъ Скрылевъ

Reputation: 16505

To remove all of .git/, .gitignore, or Documentation you can try:

find \( -name ".git" -o -name ".gitignore" -o -name "Documentation" \) -exec rm -rf "{}" \;

Upvotes: 5

Nikolaos Georgiou
Nikolaos Georgiou

Reputation: 2874

Probably there's a better way, but off the top of my head I would do this:

find . -type d -iname .git | xargs rm -rf
find . -type f -iname .gitignore | xargs rm
find . -type d -iname Documentation | xargs rm -rf

First line deletes all folders named .git, second line all files named .gitignore, third line all folders named Documentation.

Upvotes: 3

Related Questions