Skip to main content


If you're new to the Unix or Linux command line, I just want you to know:

Me and all my colleagues with years of experience

Still get confused between `ln -s` and `ln` daily.

in reply to nixCraft 🐧

And which way the arguments go. Target first or target last? I never get it on the first try.
in reply to nixCraft 🐧

Naaaa, it's quite easy, if I may:

Use -s if you want a symbolic link (else use nothing),
and the order is always <from> <to>

So, some kind of spell to use:
link (ln) symbolic (-s) from to

or for hard links
link (ln) from to

After a few times you never forget this again.

Bonus:

if you want to replace or create a symbolic link (in a script for example), replace -s with -nsf

Easy going πŸ˜‰
Be happy and SCNR 😎

This entry was edited (1 week ago)
in reply to nixCraft 🐧

This struck me as odd for a few reasons.

1. The main confusion with ln is not the "-s", it's the order of the two names, i.e., does "ln a b" link a to b or b to a?

2. I couldn't get confused about this daily because I don't use it anywhere near daily.

3. Seriously I can't remember ever using ln without the "-s". I do find "ln -s" sometimes handy.

in reply to nixCraft 🐧

I always have to remember the options for `ln`, and I've been using it for 20 years.
in reply to nixCraft 🐧

remember that if you dont give a second argument, it will link with the same name. So the first argument is the target, otherwise you couldnt run the command at all.
in reply to nixCraft 🐧

hmmm, always use ln -s and you're safe - no confusion, no "oopsie I deleted a file I didn't expect to"
This entry was edited (1 week ago)
in reply to nixCraft 🐧

my muscle memory always adds the ' -s' to ln. If the result is not what I expected, then it's time to read the man page 😁
in reply to nixCraft 🐧

I will never be able to remember the order of parameters for `ln`
I have tldr installed and I always use that before ln
in reply to nixCraft 🐧

I ALWAYS have to precede an actual `ln` command with `ln --help` 🀯
in reply to nixCraft 🐧

omg, so true. I think I need to add whoever wrote it to the list of "people that deserve a special place in hell" along the inventors of XML and sendmail config files.
in reply to nixCraft 🐧

alias softlink="ln -s"
alias hardlink-like-i-mean-it="ln"

Prevents errors on my desk.

in reply to nixCraft 🐧

Many of the Linux shell commands are syntactically disorganized, unstructured and unrelated, forming no cohesive pattern. Over the years I developed my own set of aliases to overcome problems like the one you mentioned.
in reply to nixCraft 🐧

I know "-s" means "soft" but I always think of it as "source" so it helps me remember the order of the arguments.
in reply to nixCraft 🐧

"recursive":

chmod and chown: -R
cp: -r or -R
scp: -r

🀬🀬🀬

in reply to nixCraft 🐧

I settled many years ago on β€œjust use `ln -s` and if it doesn't work it wasn't meant to be”
in reply to nixCraft 🐧

Simple solution: Always use -s

It is not like you should have to use hardlinks to save filesystem storage space these days.

in reply to nixCraft 🐧

25+ years of using Unix and Linux and I have never once used ln without -s. I don't even know what a hard link is useful for.
in reply to nixCraft 🐧

@nixCraft 🐧

You make hard links and symbolic links daily? πŸ˜‰

or where you refering to ls versus ln?

⇧