GNU/Linux >> Tutoriales Linux >  >> Linux

¿Extraña diferencia entre Pwd y /bin/pwd?

Agregué un enlace simbólico al directorio actual con ln -s . aa . Si ejecuto cd aa , y luego ejecuté pwd , la respuesta es /home/sim/aa .

Pero si ejecuto /bin/pwd imprime /home/sim (el directorio actual no ha cambiado).

¿De dónde viene esta diferencia?

Respuesta aceptada:

En la mayoría de los shells, incluido bash, pwd es un shell incorporado:

$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

Si usa /bin/pwd , debe utilizar -L opción para obtener el mismo resultado que el pwd incorporado :

$ ln -s . test
$ cd test && pwd
/home/cuonglm/test
$ /bin/pwd
/home/cuonglm
$ /bin/pwd -L
/home/cuonglm/test

De forma predeterminada, /bin/pwd ignora los enlaces simbólicos e imprime el directorio real.

Desde info pwd :

`-L'
`--logical'
     If the contents of the environment variable `PWD' provide an
     absolute name of the current directory with no `.' or `..'
     components, but possibly with symbolic links, then output those
     contents.  Otherwise, fall back to default `-P' handling.

`-P'
`--physical'
     Print a fully resolved name for the current directory.  That is,
     all components of the printed name will be actual directory
     names--none will be symbolic links.

El pwd incorporado incluye enlace simbólico de forma predeterminada, excepto que -P se utiliza la opción, o -o physical el conjunto integrado está habilitado.

De man bash :

pwd [-LP]
              Print the absolute pathname of the  current  working  directory.
              The pathname printed contains no symbolic links if the -P option
              is supplied or the -o physical option to the set builtin command
              is  enabled.  If the -L option is used, the pathname printed may
              contain symbolic links.  The return status is 0 unless an  error
              occurs  while  reading  the  name of the current directory or an
              invalid option is supplied.

Linux
  1. Linux:¿Diferencia entre /dev/console, /dev/tty y /dev/tty0?

  2. ¿Diferencia entre 2>&-, 2>/dev/null, |&, &>/dev/null y>/dev/null 2>&1?

  3. ¿Se permite espacio entre #! ¿Y /bin/bash en Shebang?

  4. ¿La diferencia entre /opt y /usr/local?

  5. La diferencia entre '$ . Foo' y '$ ./foo'??

¿Cuándo debo usar /dev/shm/ y cuándo debo usar /tmp/?

Diferencia entre /etc/crontab y crontab -e

¿Cuándo debo usar #!/bin/bash y cuándo #!/bin/sh?

Diferencia entre /bin y /usr/bin

¿Cuál es la diferencia entre /tmp y /run?

Diferencia entre /etc/hosts y /etc/resolv.conf