0

I just started learning about the Linux command line with the book "The Linux Command Line". I was trying to create a hard link by following instructions from the book and typing this command: ln fun fun-hard. But I kept getting this result

ln: fun: hard link not allowed for directory

After doing some research, I found that hard links can't be created in directories. But if this is correct, why does the book include instructions for creating a hard link in a directory? Thanks for your help.

chaos
  • 48,171

1 Answers1

0

You tried to create a hardlink to a directory

root@rpiserver:~# mkdir fun
root@rpiserver:~# ln fun fun_hard
ln: fun: hard link not allowed for directory
root@rpiserver:~#

According to ln --help this is not possible

  -d, -F, --directory         allow the superuser to attempt to hard link
                            directories (note: will probably fail due to
                            system restrictions, even for the superuser)

Even as superuser with -d this failes here:

root@rpiserver:~# ln -d fun fun_hard
ln: failed to create hard link 'fun_hard' => 'fun': Operation not permitted

(All of this was tested here on a raspberry pi, using ext4 as file system)

Bonsi
  • 141
  • This is the failed system call: linkat(AT_FDCWD, "fun", AT_FDCWD, "fun_hard", 0) = -1 EPERM (Operation not permitted) – Bonsi Aug 27 '21 at 04:25