Hacker News new | ask | show | jobs
by yjftsjthsd-h 587 days ago
A symlink can point to anything, including a file that doesn't exist:

  [~] 0 $ mkdir tmp/demo
  [~] 0 $ cd tmp/demo
  [demo] 0 $ ln -s foo bar
  [demo] 0 $ ls -l
  total 1
  lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
  [demo] 0 $ cat bar
  cat: bar: No such file or directory
  [demo] 1 $ echo foo > foo
  [demo] 0 $ ls -l
  total 2
  lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
  -rw-r--r-- 1 user users 4 Nov 15 12:14 foo
  [demo] 0 $ cat bar
  foo
  [demo] 0 $ rm foo
  [demo] 0 $ cat bar
  cat: bar: No such file or directory
  [demo] 1 $ ls -l
  total 1
  lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
  [demo] 0 $
What you can't see because this is flat text is that in my terminal the first and last "bar -> foo" are red because ls is warning me that that link points to a file that doesn't exist.