Single command to delete a directory

Use and complete the template provided. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Write a command that will delete the john directory, and all of its contents. The problem I can't firgure out is how to create a absoute path to the john directory. I'm in the paul working directory which is cd ../john away, so the paul and john directorys are children directorys to the home directory

  1. Relevant commands, code, scripts, algorithms:

rm -r john

  1. The attempts at a solution (include all code and scripts):

rm -r john ../john

  1. School (University) and Course Number:UWM Into to unix

Hi.

You are close, but need to force it (as well as simply recursing it)

Do you need to specify the absolute path? ../john would be enough if you're in the paul directory, and they're both in the home directory.

$ pwd
/home/paul
$ ls -d ../john
drwxr-xr-x 4 john students     4096 Aug 28 12:18 john

I tried that I prolly didnt explain it very well I'm in the Paul directory so I have to go up one to the home directory than down one to the John directory and delete it, with all its contents

Going back to your original question, an absolute path is one which starts with / (the root directory)

If your directory is /home/paul and john is ../john from where you are, then john is in /home/paul/../john.

/home/paul # pwd
/home/paul
/home/paul # cd /home/paul/../john
/home/john # pwd
/home/john

.. means parent, therefore john is in the parent of paul, which is /home

i.e /home/john

It's probably best if you delete john from /home instead of /home/john

cd /home
rm -rf john

or as you have to move up one (..)

cd ..
rm -rf john

If we decide to start handing out medals for who can explain things stupidly, I must be a contender!

It has to be all in one command so I cant cd.. than rm -r john

Then don't

cd ..
rm -rf john

is the same as

rm -rf ../john

Or if you have to use an absolute path, given what you know

rm -rf /home/john

(but I should add, that only root would normally be allowed to remove john!)