FactorPad
Faster Learning Tutorials

Linux ln command summary with examples

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.
Paul Alan Davis, CFA, October 13, 2016
Updated: July 30, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / ln command


The Linux ln command

Beginner

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

Video Tutorial

Linux ln command summary with examples (3:57)

Videos can also be accessed from the YouTube Playlist.

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.

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 pico (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.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the nano command, hit Back.
  • To shift to navigational topics and tutorial #22 on mkdir, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / ln command



 
 
Keywords:
linux ln command
create symbolic link linux
linux soft link files
symbolic link directory
create soft link
symlink linux
hard link linux
create symlink linux
linux remove symbolic link
how to create a soft link in linux
ln command tutorial
linux ln command summary
ln options
linux ln tutorial