Skip to main content
114 votes

Tips for remembering the order of parameters for ln?

I go by "ln is like cp. The 'source' needs to come first."
Hermann's user avatar
  • 6,914
49 votes
Accepted

Tips for remembering the order of parameters for ln?

I use the following: ln has a one-argument form (2nd form listed in the manpage) in which only the target is required (because how could ln work at all without knowing the target) and ln creates the ...
gary's user avatar
  • 744
23 votes
Accepted

Why I can't create a hard link from device file in other than /dev directory?

But I could only create a hard link in the /dev directory and it was not possible in other directories. As shown by the error message, it is not possible to create a hard link across different ...
dr_'s user avatar
  • 32.4k
22 votes

Why are symbolic links more common than hard links in Unix/Linux?

Aside from the limitations of the hard link, which you already touch upon: Note that they simply do different things, you cannot supplant one for the other in most cases. A symbolic link really ...
Marcus Müller's user avatar
20 votes
Accepted

How can i create symbolic link for directory

You have your ln -s command backwards. The first operand is where you want the link to point, and the second is what you want to call the symbolic link itself. You can remember the order of the ...
Kusalananda's user avatar
  • 356k
18 votes
Accepted

How to create a folder symlink that has a different name?

You already have a directory at ~/.pm2/logs. Since that directory exists, the symbolic link is put inside it. Would you want that ~/.pm2/logs is a symbolic link rather than a directory, then you ...
Kusalananda's user avatar
  • 356k
17 votes

Create a symbolic link relative to the current directory

ln's behavior with relative paths is unintuitive. To restore sanity, use the -r flag. cd /run/media/name/exhdd ln -sr Data/ ~/Data Explanation: -r, --relative create symbolic links ...
Aleksandr Dubinsky's user avatar
16 votes
Accepted

What is `ln --no-dereference` supposed to do?

Without -n, both your ln commands would create links inside dir2: if LINK_NAME exists and is a directory or a symlink to a directory, the link is created inside the directory (if possible). That’s ...
Stephen Kitt's user avatar
14 votes

Too many levels of symbolic links

Use the absolute path instead of the relative path, then it will work. Eg: ln -s /home/user/test/src /home/user/test/firefox
JISHNU T U's user avatar
14 votes

Tips for remembering the order of parameters for ln?

Most Unices document the ln command as ln source target (I'm omitting options etc. here) Examples: The POSIX standard ln [-fs] [-L|-P] source_file target_file OpenBSD: ln [-fhLnPs] source [...
Kusalananda's user avatar
  • 356k
12 votes

Why I can't create a hard link from device file in other than /dev directory?

A hard link cannot be used to achieve what you want, because hard links do not work between file systems. However, you can achieve what you want with the mknod command. Run ls -l /dev/devicefile. You ...
wizzwizz4's user avatar
  • 722
12 votes

Tips for remembering the order of parameters for ln?

I recently heard a great way to remember this particular thing: a rhyme Something old, something new, something borrowed, something blue, and a sixpence in her shoe. The first verse is what the ...
loa_in_'s user avatar
  • 408
12 votes

Why are symbolic links more common than hard links in Unix/Linux?

Pros for hard links and when they are better: if you need two names for the same file, but one of them might be deleted or renamed If the purpose of the linking is to save space and/or reduce ...
user10489's user avatar
  • 10.9k
11 votes
Accepted

Is there a way to create a symlink to a non-existent target?

When you run ln -s nonexistenttarget link ln doesn’t check whether nonexistenttarget exists, it creates the link, unless link already exists. -f works around the last part by deleting link if ...
Stephen Kitt's user avatar
11 votes

Why are symbolic links more common than hard links in Unix/Linux?

To give input on the question asked in the Title: Why are symbolic links more common than hard links in Unix/LINUX? 1. Because hard links can't traverse different filesystems, and that's the most ...
Sotto Voce's user avatar
  • 7,201
10 votes
Accepted

ln: create symlink using another symlink

-L only works with hard links; as specified in POSIX: If the -s option is specified, the -L and -P options shall be silently ignored. If you have readlink you can use that: ln -s -- "$(readlink ...
Stephen Kitt's user avatar
9 votes
Accepted

What is the meaning of 'ln -sT' in Linux?

ln’s synopsis is as follows: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) ln [OPTION]... TARGET (2nd form) ln [OPTION]... TARGET... DIRECTORY (3rd form) ln [OPTION]... -t ...
Stephen Kitt's user avatar
8 votes

Rm hardlink without removing file/directory itself

$ echo 'hello' >name $ ln name othername $ ls -l total 4 -rw-r--r-- 2 kk wheel 6 Jun 25 09:45 name -rw-r--r-- 2 kk wheel 6 Jun 25 09:45 othername $ cat othername hello $ rm name $ ls -l total ...
Kusalananda's user avatar
  • 356k
8 votes

How to create a folder symlink that has a different name?

As other answers say, there is already a directory there. To avoid this and instead get an error-message, use the -T option, unfortunately I don't think this is Posix (it is GNU). From the Gnu ln ...
ctrl-alt-delor's user avatar
8 votes

Why are symbolic links more common than hard links in Unix/Linux?

In short, the problem with hard links is that they expose the fact that the "identity" of a file, on the technical level, is the inode. While a great many users might consider the file name ...
ilkkachu's user avatar
  • 148k
7 votes

Making a link using ln -s

A shell will typically break a ln -s /Backup files/ /link 1 command line into these words: ln -s /Backup files/ /link 1 From the first word, it will derive the command to execute (something like /bin/...
Stéphane Chazelas's user avatar
7 votes

How to create a link (ln -s) with an absolute path?

Okay, I found one way to make it work easily: ln -s `realpath ../dir2/file` link #not perfect It's not perfect - $( ... ) is preferred to `...` for command substitution, and there's a ...
Peter Kay's user avatar
  • 131
7 votes

Tips for remembering the order of parameters for ln?

In case this helps anyone: I've gotten used to thinking of it as "ln what where", which helps me remember that the first argument ("what") is the existing file, the second ("where") is the place to ...
David Z's user avatar
  • 1,105
7 votes
Accepted

What does "ln -t" do

The -T (--no-target-directory) option to GNU ln provides a safety feature that may be useful in scripts. Suppose that you want to create a new name, $newname, for a file $filename, where the new name ...
Kusalananda's user avatar
  • 356k
6 votes
Accepted

ln fails to create link

Your ian user seems to have defined an ln alias, which is used instead of the ln command you expect. Try \ln ~/bin/gpioreadall.py ~/bin/gpioreadall which will ignore aliases. If that works, look ...
Stephen Kitt's user avatar
5 votes

ln -s with a path relative to pwd

To save some typing, you can do ln -s "$PWD"/foo ~/bin/foo_link
cosine's user avatar
  • 86
5 votes

ln: create symlink using another symlink

You can use cp -P to make a copy of a symlink: cp -P symlink2 symlink3 (assuming symlink3 doesn't already exist as a directory or symlink to directory, see the -T option with GNU cp for those cases). ...
Stéphane Chazelas's user avatar
5 votes

Recursively "find" file names containing string and symlink files in another directory

If you already have the necessary directories created in the target location, then with the GNU implementations of find and xargs, it's not too difficult: find ~/path/to/src -name "*stringtomatch*" -...
wurtel's user avatar
  • 16.5k
5 votes
Accepted

Why permission denied upon symbolic link update to new target with permissions OK?

It appears as if the GNU ln implementation on Linux uses the stat() function to determine whether the target exists or not. This function is required to resolve symbolic links, so when the target of ...
Kusalananda's user avatar
  • 356k
5 votes
Accepted

What does `ln /path/to/file -i` do in a setuid'ed script?

The code ln /etc/setuid_script -i is intended to create a hardlink to a file called -i in the current directory. You might need to say ln -- /etc/setuid_script -i to make this work if you are using ...
icarus's user avatar
  • 19.1k

Only top scored, non community-wiki answers of a minimum length are eligible