In this compilation of sysadmin horrors, one of the authors writes, as a rule of thumb:
Always do a
cd .
before doing anything.
Why would you want to do that?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityIn this compilation of sysadmin horrors, one of the authors writes, as a rule of thumb:
Always do a
cd .
before doing anything.
Why would you want to do that?
You don't.
At least not just like that. The preceding line in the quoted document is of importance:
- Set up your prompt to do a
pwd
everytime you cd.- Always do a
cd .
before doing anything.
This way, you as the operator verify your current working dir before doing anything of importance, as it's printed out with each change. cd .
doesn't make any sense otherwise.
This "verification" is a good thing, and you should adapt a form of it. A more (IMHO) common variation of this theme is to always print out the working dir at the prompt.
cd .
would change the actual underlying directory that you are in.
cd .
but before doing anything else. It just reduces the likelihood of being in the wrong directory, but doesn't solve the general problem. Unless you switch to the real directory using something like cd $(readlink -f .)
given that you actually want to stay there.
If the current working directory of your shell is removed, it is possible to lose data.
For example,
$ pwd
/home/user/test
$ rmdir /home/user/test
$ pwd
/home/user/test
$ some_command | tee command.log
tee: command.log: No such file or directory
<long output>
The output of some_command
was not written to the disk.
Typing cd .
before running a command would reveal the problem.
$ pwd
/home/user/test
$ rmdir /home/user/test
$ cd .
$ pwd
.
If the current working directory directory was removed and re-created, typing cd .
would "refresh" the reference to that directory.
$ ls
foo bar ljz
$ pwd
/home/user/test
$ rmdir /home/user/test
$ mkdir /home/user/test
$ pwd
/home/user/test
$ ls
$ cd .
$ ls
foo bar ljz
I think it's more important to show your current directory.
On every linux server, I modify the prompt in /etc/bashrc
by changing "W" to "w".
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
to
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \w]\\$ "
The effect of this is:
[root@xt include]#
versus
[root@xt /usr/src/spl-0.6.1/include]#
~/.profile
or ~/.bash_profile
as well as updating /etc/skel/.profile