Understanding Linux File System: ls -ltr Decoded and Directory Structure Explained

Published: (December 6, 2025 at 03:03 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

The Problem

You run ls and see filenames. But is it a file or folder? Who owns it? Can you even edit it?
On day two with Linux, I learned ls can tell you way more than just names.

The Command: ls -ltr

ls -ltr

What the flags mean

  • -l – Long format (detailed info)
  • -t – Sort by modification time (newest first)
  • -r – Reverse order (newest at the bottom)

Terminal Output Example

drwxr-xr-x  2 ubuntu ubuntu    4096 Dec 01 10:23 documents
-rw-r--r--  1 ubuntu ubuntu     156 Dec 02 14:45 config.txt
lrwxrwxrwx  1 ubuntu ubuntu      15 Dec 03 09:12 link_to_file -> /home/ubuntu/file
-rwxr-xr-x  1 ubuntu ubuntu    8192 Dec 04 16:30 script.sh
drwxr-xr-x  3 root   root      4096 Dec 05 11:20 logs
crw-rw----  1 root   tty     136, 0 Dec 06 08:15 tty0
brw-rw----  1 root   disk      8, 0 Dec 06 10:00 sda
srwxrwxrwx  1 root   root         0 Dec 04 12:30 mysql.sock

Reading the Output

Column 1: File Type + Permissions

drwxr-xr-x
│└────┬────└─── Others (r-x)
│     └──────── Group (r-x)
│           └── Owner (rwx)
└────────────── File Type (d)

First Character – File Type

SymbolTypeDescription
dDirectoryIt’s a folder
-Regular fileNormal file
lSymbolic linkShortcut to another file
cCharacter deviceKeyboard, terminal
bBlock deviceHard drive, USB
sSocketInter‑process communication
pNamed pipeProcess communication

Next 9 Characters – Permissions

  • r – Read
  • w – Write
  • x – Execute
  • - – No permission

Example: rwxr-xr-x

  • Owner: read, write, execute
  • Group: read, execute (no write)
  • Others: read, execute (no write)

Columns 2‑9: The Details

-rw-r--r--  1 ubuntu ubuntu  156 Dec 02 14:45 config.txt
│           │ │      │       │   │            │
│           │ │      │       │   │            └─ Filename
│           │ │      │       │   └────────────── Last modified
│           │ │      │       └────────────────── Size (bytes)
│           │ │      └────────────────────────── Group owner
│           │ └───────────────────────────────── User owner
│           └─────────────────────────────────── Number of links
└─────────────────────────────────────────────── Type + Permissions

File Types in Detail

Regular Files (-)

-rw-r--r--  1 ubuntu ubuntu  156 Dec 02 14:45 config.txt

Typical files: text, images, binaries, scripts.

Directories (d)

drwxr-xr-x  2 ubuntu ubuntu 4096 Dec 01 10:23 documents

Folders. The size shown is metadata, not the total size of contained files.

lrwxrwxrwx  1 ubuntu ubuntu   15 Dec 03 09:12 link -> /home/file

Shortcuts to other files. If the target is removed, the link becomes broken.

Character Devices (c)

crw-rw----  1 root tty  136, 0 Dec 06 08:15 tty0

Transfer data character by character (e.g., terminals, keyboards). Located under /dev/.

Block Devices (b)

brw-rw----  1 root disk  8, 0 Dec 06 10:00 sda

Transfer data in blocks (hard drives, USB drives). Located under /dev/.

Sockets (s)

srwxrwxrwx  1 root root     0 Dec 04 12:30 mysql.sock

Used for inter‑process communication, often found in /var/run/ or /tmp/.

Named Pipes (p)

prw-r--r--  1 ubuntu ubuntu  0 Dec 03 15:20 mypipe

Allow processes to communicate via a FIFO queue. Less common.

Linux Directory Structure

Everything starts from / (root):

/                           Root directory
├── bin/                    Essential commands (ls, cp, cat)
├── boot/                   Bootloader, kernel
├── dev/                    Device files
├── etc/                    Configuration files
├── home/                   User directories
│   └── ubuntu/             Your home directory
├── lib/                    Shared libraries
├── media/                  Removable media mount points
├── mnt/                    Temporary mounts
├── opt/                    Optional software
├── proc/                   Process information (virtual)
├── root/                   Root user's home
├── run/                    Runtime process data
├── sbin/                   System admin commands
├── srv/                    Service data (web, FTP)
├── sys/                    Kernel/hardware info (virtual)
├── tmp/                    Temp files (cleared on reboot)
├── usr/                    User programs
│   ├── bin/                User commands
│   ├── lib/                Program libraries
│   └── local/              Locally installed software
└── var/                    Variable data
    ├── log/                Log files
    ├── www/                Web server files
    └── tmp/                Temp files (preserved on reboot)

Key Directories

DirectoryPurposeExample Use
/home/Your personal files/home/ubuntu/documents/
/etc/System configuration/etc/nginx/nginx.conf
/var/log/Log files/var/log/syslog
/tmp/Temporary files (cleared on reboot)
/dev/Device files/dev/sda (hard drive)
/usr/bin/Programs/usr/bin/python3

Practical Commands

Basic listing

ls -ltr

Include hidden files

ls -ltra   # Shows files starting with . like .bashrc

Human‑readable sizes

ls -ltrh   # Shows 1.5M instead of 1572864

Check a specific directory

ls -ltr /var/log

List only directories

ls -ltrd */

Sort by size

ls -lSrh   # -S = sort by size

Common Mistakes

❌ Mistake #1: Not using -h

ls -ltr
# Output: -rw-r--r-- 1 ubuntu ubuntu 1572864 Dec 06 10:00 file.txt
# Who knows what 1572864 bytes is?

✅ Better:

ls -ltrh
# Output: -rw-r--r-- 1 ubuntu ubuntu 1.5M Dec 06 10:00 file.txt
# Instantly readable

❌ Mistake #2: Missing hidden files

ls -ltr
# Doesn't show .bashrc, .ssh/, .gitconfig

✅ Better:

ls -ltra
# Shows all files including hidden ones

❌ Mistake #3: Looking for logs in the wrong place

ls /tmp/application.log   # Wrong

✅ Better:

ls /var/log/application.log   # Correct

Real‑World Examples

Check who owns a config file

ls -l /etc/nginx/nginx.conf
Back to Blog

Related posts

Read more »

12 Days of Shell

Article URL: https://12days.cmdchallenge.com Comments URL: https://news.ycombinator.com/item?id=46190577 Points: 31 Comments: 8...