114
votes
Tips for remembering the order of parameters for ln?
I go by "ln is like cp. The 'source' needs to come first."
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
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 [...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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/...
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 ...
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 ...
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 ...
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 ...
5
votes
ln -s with a path relative to pwd
To save some typing, you can do
ln -s "$PWD"/foo ~/bin/foo_link
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).
...
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*" -...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible