• ln command cheatsheet.

View

Set up:

$ echo 'Hello' > my-target.txt
$ cd my-dir
$ ln -s my-symlink ../my-target.txt
$ ln -s ~/.local/virtualenvs/daylio-csv-parser venv

Use cat

This will show the contents of the target of the symlink.

$ cat my-symlink
Hello

Use ls

$ ls -l
...       my-symlink -> ../my-target
$ ls -l
...       venv -> /Users/mcurrin/.local/virtualenvs/daylio-csv-parser

Use realpath

Get the absolute path. Use on a normal object but especially useful for evaluatin where a symlink points to.

$ realpath PATH

e.g.

$ realpath venv
/Users/mcurrin/.local/virtualenvs/daylio-csv-parser
$ mkdir my-dir
$ cd my-dir
$ ln -s ../test.txt my-symlink
$ cd ..
$ realpath my-dir/my-symlink
/home/test.txt

Use -n to remove trailing newline.

     readlink, stat -- display file status

     readlink [-n] [file ...]
$ readlink SYMLINK

e.g.

$ readlink venv
/Users/mcurrin/.local/virtualenvs/daylio-csv-parser