Unable to delete my test directory in the terminal

Hey there. I’m currently learning the command line basics and created the directory “test”. Now I want to delete it again, but if I type in rm test while I’m in the same directory as the test directory, it just says rm test “rm: test: is a directory”

Can anyone tell me what I’m doing wrong?

Thanks in advance:)

1 Like

rm -d dirname will remove an empty directory. rm -r dirname will remove a directory that has files in it. When you created “test” did you use the touch or mkdir command?


Hey, thank you so much:)) I used the mkdir command

You’re very welcome. I started using Linux a couple of months ago when I started and I still have to look up how to do things I don’t use very often. :slight_smile:

I’m just going thru the command line basics, and had the same problem (couldn’t delete test dir), and “rm -r test” worked!

Would you guys know what the “-r” here denotes?
I’m a bit confused, because elsewhere in the command line basics article, it denotes “-r” as being used to reverse-sort the listing command.
[e.g. “ls -lr” to display the file list in reverse-alphabetical order.]

Also, didn’t know the “touch” command could create directories - off to try that now!

@stumble_crawl, I’m also interested why would you use “rm -d $dirname” to delete an empty directory, instead of “rmdir $dirname”?

I’m pretty sure I just made a typo there. Sorry about that! The “-r” is for “recursive”, I believe, meaning “delete this directory and all it contains.” Flags like -a, -r, -f, etc. whenever they are used can change based on the command being given. If you’re ever in doubt, check the “man page” for the command you want to know more about. On the command line just type "man ", i.e. “man ls” or “man rm”, and it will give you answers to most of your questions.

I can’t check the exact phrasing of -r for rm right now because I’m not on my Linux machine, but I do seem to remember it being for “recursive” with that particular command.

1 Like

Ah, recursive makes sense. :slight_smile:
Yea, I’m learning that the flags seem to work contextually with each command - I think I’m just not at a stage yet where that’s intuitive.
And thanks for highlighting the manual - that’s really helpful!