ln command

From the man page the ln command "make links between files" (like shortcuts in Windows)

the most simple usage is

ln can be used to softlink files

$ echo "hello world" > file1
$ ln -s file1 file2
$ ls -l | grep file
-rw-rw-r-- 1 user user 12 Jun 1 16:35 file1
lrwxrwxrwx 1 user user 5 Jun 1 16:35 file2 -> file1

or hardlink (same inodes)

$ echo "hi" > file3
$ ln file3 file4
$ ls -li | grep file
131901 -rw-rw-r-- 1 user user 12 Jun 1 16:35 file1
132234 lrwxrwxrwx 1 user user 5 Jun 1 16:35 file2 -> file1
132277 -rw-rw-r-- 2 user user 3 Jun 1 16:37 file3
132277 -rw-rw-r-- 2 user user 3 Jun 1 16:37 file4

note you can only really link files, directories cannot be linked (there is ls -F but the man page says this "allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)"

 

to find symbolic links on your system etc folder run

find /etc/ -type l

for an example of where symbolic links are used in Linux

# pwd
/etc/rc.d
# find /etc/rc.d/ -type l | xargs ls -l | grep smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc0.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc1.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc2.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc3.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc4.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc5.d/K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 16 Aug 8 14:04 /etc/rc.d/rc6.d/K01smartd -> ../init.d/smartd

this allows linux to reuse the same code in multiple places rather than having 7 copies of the same file. (keeping control of these could be very hard)
So when the machine

to find hard linked files, use ls -li to find the inode

# ls -li test1
1163763 -rw-r--r-- 2 root root 4 Oct 30 10:57 test1

and then use find to see other files with the same inode

# find -inum 1163763 | xargs ls -l
-rw-r--r-- 2 root root 4 Oct 30 10:57 ./test1
-rw-r--r-- 2 root root 4 Oct 30 10:57 ./test3

there is a really good write up @ https://www.lifewire.com/create-symbolic-links-ln-command-4059723 & at https://www.nixtutor.com/freebsd/understanding-symbolic-links/