Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

James Page
James Page
9,621 Points

Why rm and not rmdir?

I tried using rmdir -r .git, but was told it was wrong. I went with rm -r .git in the end, but I'm wondering why rmdir is not valid?

2 Answers

Zuhayr Elahi
Zuhayr Elahi
2,582 Points

I do believe its because rmdir only removes an empty directory. If you run the command 'man rmdir', it will open up a page describing what rmdir does and it also lists the commands present when running rmdir. when you open the page, there is no '-r' option.

Now why you have to use 'rm -r'. Rm as we know removes files. In the end a directory is a file to store other files. (In fact for fun, you can use vi to open the directory).

Therefore this is why rmdir doesn't work.

There is no -r option It only works for empty directories. I hope this helps. Let me know if you need anything else

James Page
James Page
9,621 Points

Thanks - presumably .git isn't an empty directory, then (this was my assumption). I should go and look for myself...

Zuhayr Elahi
Zuhayr Elahi
2,582 Points

Nope haha. Actually git is really interesting. I was reading about about it from a book I found called the Architecture of Open Source Systems. Here is a link to it if you want to read for yourself: http://aosabook.org/en/git.html

its actually really interesting.

And your .git folder is the real repository . So that's why you don't want to delete it. I hope this helps and that's a good resource I would suggest reading if you have time =)

James Page
James Page
9,621 Points

Thank you. Another item added to my Pocket reading list!