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!

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 Console Foundations Getting Started with the Console Moving and Deleting Files

I entered mkdir -p dirname/dirname2/dirname3 to make a new directory. now -p is listed as a dir, how can i delete?

i was following along with the tutorial and mkdir dirname/dirname2/dirname3 gives an error : no such file or directory, because none had been created yet. using the -p flag I was able to do this all in one line instead of 3 different commands: mkdir dirname, mkdir dirname2, mkdir dirname3. Now, -p is listed as a directory, i cannot cd into that dir nor can I rm that dir to remove it. Looking for help as to why it created this dir and how I can remove it. I have removed all the associated directories regarding that initial input(mkdir -p dirname/dirname2/dirname3

2 Answers

Kris Phelps
Kris Phelps
7,609 Points

Is there anything in the -p directory? If so you'll need to recursively delete the directory. (rm -r directory_name).

have you tried renaming it was well? You may need to do that before trying to delete it. That's about all I can think of.

I cannot open it as it isn't really a directory. I cannot rename it as well. I've attached a screenshot to show kind of what is happening. It's listed like it's a directory but it can't be deleted, renamed, opened or modified in any way.

Kevins-MacBook-Pro:~ kevinwatke$ mv -p test mv: illegal option -- p usage: mv [-f | -i | -n] [-v] source target mv [-f | -i | -n] [-v] source ... directory Kevins-MacBook-Pro:~ kevinwatke$ rm -r -p rm: illegal option -- p usage: rm [-f | -i] [-dPRrvW] file ... unlink file Kevins-MacBook-Pro:~ kevinwatke$ ls -p Downloads Music eclipse personal Desktop Library Pictures java_projects Documents Movies Public myphotos Kevins-MacBook-Pro:~ kevinwatke$

I have solved this issue with rm -r -- -p, it was my error when i entered the command i mistakenly put a / in front of the first directory as an admin and created an illegal file that unix thought was a directory. Thank you for the assistance.

Kris Phelps
Kris Phelps
7,609 Points

You're welcome, glad I could help :-)