remove the current directory

Can I remove the current directory?

I used to believe you cannot.

Solaris:


$ uname -s
SunOS
$ mkdir /tmp/bla
$ cd /tmp/bla
$ rm -r /tmp/bla
rm: Cannot remove any directory in the path of the current working directory
/tmp/bla
$

AIX:


$ uname -s
AIX
$ mkdir /tmp/bla
$ cd /tmp/bla
$ rm -r /tmp/bla
rm: Cannot remove the current directory /tmp/bla.
$

Today I did a rm that I expected to fail, but …


$ uname -s
Linux
$ mkdir /tmp/bla
$ cd /tmp/bla
$ rm -r /tmp/bla
$ 

Wait, did it work?


$ cd /tmp/bla
$ pwd
/tmp/bla
$ cd /tmp/bla
$ ls -lad /tmp/bla
ls: /tmp/bla: No such file or directory
$ cd /tmp/bla
$

Somehow I am still there, in /tmp/bla, but /tmp/bla has been removed. What a strange operating system ;)

3 thoughts on “remove the current directory”

  1. don’t see any strange here.

    Do you find the following also “strange” ?

    sokrates > create table tmp( bla int) ;

    Table created.

    sokrates > insert into tmp select 1 from dual union all select 2 from dual;

    2 rows created.

    sokrates > commit;

    Commit complete.

    sokrates > declare
    2 i int;
    3 cursor c is select * from tmp order by bla;
    4 procedure drop_ is
    5 pragma autonomous_transaction;
    6 begin
    7 execute immediate ‘drop table tmp purge';
    8 end drop_;
    9 begin
    10 open c;
    11 fetch c into i;
    12 dbms_output.put_line(‘ i before drop : ‘ || i);
    13 drop_;
    14 fetch c into i;
    15 dbms_output.put_line(‘ i after drop : ‘ || i);
    16 close c;
    17 end;
    18 /
    i before drop : 1
    i after drop : 2

    PL/SQL procedure successfully completed.

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>