FactorPad
Build a Better Process

Linux ln Command Summary with Examples

Linux ln allows you to make file or directory links.
  1. Purpose - Learn what ln is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with ln.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux ln, 21 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / ln-command.html


An ad-free and cookie-free website.


Examples of the Linux ln Command

Beginner

Learn to make file or directory links at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux ln Command Summary with Examples (3:57)

Video Script

The Command and Why You Need It

Our twenty-first word, or command to memorize is ln from the category System.

ln allows you to make file or directory links.

Common Linux ln Options
-options description
--help Print help screen
-s, --symbolic Set up a symbolic link instead of a hard link

Recall from the last video (tutorial) we saw a connection between the command nano to pico and here we'll sort that out.

Before we start, it helps to think about commands as mini programs and most follow this structure: command -option(s) argument(s).

The ln command has 16 options and there are typically two arguments, the target file and the link name, which is the pointer.

Like most commands, help is available, here with double-dash --help.

Because the concept of links can be difficult, for now I'd just like to draw your attention to the -s option, for symbolic links.

So why is ln an important command? Well, ln is widely used on your system already, and you will need to establish links. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, using the echo command from video 19, let's "make up words", create a file >, and put it in the directory one above here ../, giving it a ridiculouslylongfilename.txt.

$ echo "make up words" > ../ridiculouslylongfilename.txt

So to avoid typing that and wasting time, let's make a symbolic link, using ln -s, the target ../ridiculouslylongfilename.txt, then the link name video21.txt.

$ ln -s ../ridiculouslylongfilename.txt video21.txt

List files ls.

$ ls video11.txt video16.txt video19.txt video20.txt video21.txt video5.txt

There it is, in a different color (bold here), and use cat from video 10 to view (the symbolic link).

$ cat video21.txt make up words

And last, let's revisit the nano/pico topic from earlier. Let's do a whatis on the commands.

$ whatis pico nano pico (1) - Nano's ANOther editor, an enhanced free Pico clone nano (1) - Nano's ANOther editor, an enhanced free Pico clone

Basically, behind the scenes is a (symbolic) link pointing pico to open nano and this is where my system does that.

$ ls -og /etc/alternatives/pico lrwxrwxrwx 1 9 Oct 6 06:24 /etc/alternatives/pico -> /bin/nano

Again, links are very common, so we'll revisit the topic again later.

A Final Tip

Okay now you know how to use ln. And you know the syntax for commands, options and arguments.

One last tip about the ln command. The two link types: symbolic (soft) and hard, are worth knowing, so please read the help file.

Okay, great, thanks for visiting today. I hope this was a fun introduction to the ln command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Reach out to us with questions and comments at YouTube. Subscribe and follow @twitter for new content announcements.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / ln-command.html


linux ln command
symbolic link linux
symlink linux
create symbolic link
create symbolic link linux
softlink in linux
linux soft link
create symlink linux
man ln
linux remove symbolic link
how to create a soft link in linux
ln command tutorial
ln command examples
symbolic link directory
linux ln command summary
ln options
ln tutorial
create soft link

A newly-updated free resource. Connect and refer a friend today.