Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I cd to a directory, is there a quick way to delete the directory I am in and move to the top directory? Usually I cd to a directory, ls it and then cd .. then delete the folder. I want to be able to cd to it and ls. Then if I just want to delete it from there.

Basically is there a rm operator that equates rm -r $(pwd); cd ..

Also, how come if I do not add ; cd .. bash will still believe it is in the directory that doesn't exist?

michaelxu@michaelxu-server:~/Desktop$ mkdir test
michaelxu@michaelxu-server:~/Desktop$ cd test
michaelxu@michaelxu-server:~/Desktop/test$ touch test
michaelxu@michaelxu-server:~/Desktop/test$ ls
michaelxu@michaelxu-server:~/Desktop/test$ rm -r $(pwd)
michaelxu@michaelxu-server:~/Desktop/test$ pwd
michaelxu@michaelxu-server:~/Desktop/test$ touch test
touch: cannot touch `test': No such file or directory
michaelxu@michaelxu-server:~/Desktop/test$ cd ..
michaelxu@michaelxu-server:~/Desktop$ cd test
-bash: cd: test: No such file or directory
share|improve this question
It behaves like it's in a directory that doesn't exist because that's exactly what is happening. It still has a pointer to that directory, but that pointer is no longer valid. bash doesn't know that the directory has been deleted. – Darth Android May 14 '13 at 21:13
Part of what’s happening is that bash probably doesn’t check to see what directory it’s in after every command, but only after every cd, pushd, and popd. It depends on exactly how you have defined PS1. For example, try cd test and then mv ../test ../quiz (or (cd ..; mv test quiz)). The prompt will probably still say Desktop/test, because bash has no reason to check whether the directory name has changed. // P.S. May I suggest that you don’t use the same name (test) for two different things in your examples? – Scott May 14 '13 at 23:25

Under bash:

rm -rf "$(pwd -P)" && cd ..
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .