46 votes

Pourquoi créer un lien comme celui-ci : ln -nsf ?

À quoi cela sert-il ?

ln -nsf

Je sais que ln -s crée un lien symbolique, et non un lien dur, ce qui signifie que vous pouvez l'effacer sans que la pensée vers laquelle il pointe ne soit supprimée. Mais que signifient les autres éléments (-nf) ?

Mise à jour : Ok...je me suis souvenu qu'on peut trouver ce genre de choses à partir de la ligne de commande. Voici ce que j'ai trouvé en tapant ln --help :

-f, --force                 remove existing destination files
-n, --no-dereference        treat destination that is a symlink to a
                            directory as if it were a normal file

Mais je ne vois toujours pas très bien quelles sont les implications de tout cela. Pourquoi voudrais-je créer un lien soft/sym comme celui-ci ?

46voto

Nate Kohari Points 1748

Extrait de la page de manuel BSD :

 -f    If the target file already exists, then unlink it so that the link
           may occur.  (The -f option overrides any previous -i options.)

 -n    If the target_file or target_dir is a symbolic link, do not follow
           it.  This is most useful with the -f option, to replace a symlink
           which may point to a directory.

42voto

Marian Theisen Points 651

Les -n (avec l'option -f ) forces ln pour mettre à jour un lien symbolique vers un répertoire. qu'est-ce que cela signifie ?

Supposons que vous ayez 2 répertoires

  • foo
  • bar

et un lien symbolique existant

  • baz -> bar

vous souhaitez maintenant mettre à jour baz pour pointer vers foo à la place. Si vous ne faites que

ln -sf foo baz

vous obtiendrez

  • baz/foo -> foo
  • baz -> bar (inchangé), et donc
  • bar/foo -> foo

si vous ajoutez -n

ln -sfn foo baz

vous obtenez ce que vous voulez.

  • baz -> foo

C'est ce que signifie l'expression "pas de référence" : ne pas résoudre un lien existant et placer le nouveau lien dans ce répertoire, mais simplement le mettre à jour.

2voto

Rich Rousseau Points 179

Voici toutes les options de ln. Vous y trouverez les options -n et -f.

 -F    If the target file already exists and is a directory, then remove
       it so that the link may occur.
       The -F option should be used with either -f or -i options.  If
       none is specified, -f is implied.
       The -F option is a no-op unless -s option is specified.

 -h    If the target_file or target_dir is a symbolic link, do not
       follow it.  This is most useful with the -f option, to replace 
       a symlink which may point to a directory.

 -f    If the target file already exists, then unlink it so that the
       link may occur.  (The -f option overrides any previous -i options.)

 -i    Cause ln to write a prompt to standard error if the target file
       exists.  If the response from the standard input begins with the
       character `y' or `Y', then unlink the target file so that the link
       may occur.  Otherwise, do not attempt the link.  (The -i option
       overrides any previous -f options.)

 -n    Same as -h, for compatibility with other ln implementations.

 -s    Create a symbolic link.

 -v    Cause ln to be verbose, showing files as they are processed.

-1voto

DragonCrafted87 Points 93

Vous pouvez taper "man ln" pour trouver ce genre de choses :

   -f, --force
          remove existing destination files

   -n, --no-dereference
          treat destination that is a symlink to a directory as if it were
          a normal file

-1voto

Mark T Points 1276

- supprimer les fichiers de destination existants

- traite la destination qui est un lien symbolique vers un répertoire comme s'il s'agissait d'un fichier normal

SistemesEz.com

SystemesEZ est une communauté de sysadmins où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres sysadmins, poser vos propres questions ou résoudre celles des autres.

Powered by:

X