Renaming the current directory from a shell - possible?

Yes, but you have to refer to the directory by name, not by using the . notation. You can use a relative path, it just has to end with something other than . or ..:

/tmp/test$ mv ../test ../test2
/tmp/test$ pwd
/tmp/test
/tmp/test$ pwd -P
/tmp/test2

You can use an absolute path:

/tmp/test$ cd -P .
/tmp/test2$ mv "$PWD" "${PWD%/*}/test3"
/tmp/test2$ 

Similarly, rmdir . won't ever work, but rmdir "$PWD" does.


As in @Gilles answer but using brace expansion for brevity:

mv ../{test,test2}

Tags:

Shell

Rename