What the Linux "ls" Command is Telling You About Links

 

What the Linux ls Command is Telling You About Links

The link is made... now what?

So you’ve just run ln or ln -s on your Raspberry Pi. Congrats! You’ve made a link. But how can you tell that it worked? Linux doesn’t always throw confetti. Instead, it leaves quiet little footprints in your terminal—especially in the output of the ls command.

To a beginner, ls just lists files. But with the right flags, it becomes a microscope. And once you know what to look for, you’ll start seeing everything from inode twins to symbolic arrows.

Let’s walk through how ls helps you verify and understand what links are really doing under the hood.

Using ls -li: Inode detective mode

When you create a hard link, both filenames point to the same inode — the same chunk of data on the disk. You can verify that with:

ls -li

This shows the inode number at the beginning of each line. Try it with this experiment:

echo "Pi power!" > alpha.txt
ln alpha.txt beta.txt
ls -li

You’ll see something like:

1234567 -rw-r--r-- 2 pi pi 9 Apr 6 20:47 alpha.txt
1234567 -rw-r--r-- 2 pi pi 9 Apr 6 20:47 beta.txt

That 1234567? It’s the inode number—and it’s the same for both files. That proves they’re two names for the same exact file. Also notice the 2 after the permissions. That’s the link count, showing how many filenames point to this inode.

Delete one, and the other remains. But the inode lives on as long as at least one name is pointing to it.

Using ls -l: Following the arrows

Now try a symbolic link:

ln -s alpha.txt shortcut.txt
ls -l

You’ll get something like:

lrwxrwxrwx 1 pi pi 9 Apr 6 20:50 shortcut.txt -> alpha.txt

The first character, l, tells you it’s a symlink. And see the arrow? That tells you exactly where the symlink is pointing. Unlike hard links, symlinks don’t share inodes—they just reference the name of another file.

If alpha.txt is deleted, shortcut.txt still shows up in ls, but it’s broken. Try opening it and you’ll get a “No such file or directory” message. The signpost remains, but the destination is gone.

Bonus: Try stat for deeper file details

Want more info? Try this:

stat alpha.txt
stat beta.txt
stat shortcut.txt

You’ll see inode numbers, link counts, sizes, and even file types. It’s like an x-ray for your files — especially handy when you’re trying to figure out what’s really going on beneath the surface.

Need Raspberry Pi Expertise?

We’d love to help you with your Raspberry Pi projects. Feel free to reach out! Contact: info@pacificw.com.

Aaron Rose

Written by Aaron Rose

Software engineer and technology blogger

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

The Reasoning Chain in DeepSeek R1: A Glimpse into AI’s Thought Process