Linux / Linux Basic / Understanding Linux commands
Linux Basic

Understanding Linux commands

The ls command — short for list — is the first command most people learn on Linux. It shows you what’s inside a directory. This guide takes you from the basics all the way to exploring the root filesystem and /etc/ with real simulated terminal output.

Command Line File System ls Linux Basics

What is ls?

ls stands for list. It prints the names of files and directories inside a folder. Run it with no arguments and it lists your current working directory. Pass a path and it lists that path instead.

Basic syntax
ls                  # list current directory
ls /path/to/dir     # list a specific path
ls ~                # list your home directory (~ = home)
Try it now: Open a terminal and type ls followed by Enter. You’ll see the contents of wherever you are right now.

Key Flags & Options

Flags change how ls behaves. You can combine them freely. Here are the most important ones:

FlagLong formWhat it does
-a–allShow hidden files (names starting with .)
-lLong format — permissions, owner, size, date
-h–human-readableHuman-readable sizes (4.0K, 12M) — requires -l
-1One entry per line (the number 1, not letter L)
-tSort by modification time, newest first
-r–reverseReverse the sort order
-R–recursiveList all subdirectories recursively
-SSort by file size, largest first
-F–classifyAppend type indicators (/ for dirs, * for executables)
-i–inodeShow inode numbers
-d–directoryList directories themselves, not their contents

Popular Combinations

Most-used ls combos
ls -la     # long format + show hidden files
ls -lh     # long format + human-readable sizes
ls -ltr    # long format + sorted by time, oldest first
ls -lAh    # long format + all (except . and ..) + human sizes
ls -1      # one item per line, clean for piping

Pro Tips

Many Linux systems define shell aliases so you don’t have to type the full flags every time:

Common ls aliases (often in ~/.bashrc)
alias ll='ls -lh'        # long + human-readable
alias la='ls -lAh'       # long + all hidden + human-readable
alias l='ls -1'          # one per line
Read the manual: Run man ls for the complete reference. Press q to exit. You can also combine ls with pipes: ls /etc | grep ssh

Exploring the Root Filesystem with ls /

The root directory / is the top of the entire Linux filesystem. Everything lives inside it. Running ls / gives you the Filesystem Hierarchy Standard (FHS) — the standardised layout used by all major Linux distributions.

List the root filesystem
$ ls /
bin   boot  dev  etc  home  lib  lib64  media  mnt  opt
proc  root  run  sbin  srv  sys  tmp  usr  var

Here is what each top-level directory does:

DirectoryPurpose
/binEssential user binaries (ls, cp, mv, bash, etc.)
/sbinSystem administration binaries (only root typically uses these)
/etcSystem-wide configuration files — the most important directory
/homePersonal directories for each user (/home/username)
/varVariable data — logs (/var/log), databases, mail spools
/devDevice files (hard drives, USB, terminals — everything is a file)
/procVirtual filesystem — live kernel and process information
/sysVirtual filesystem — hardware and kernel subsystem info
/tmpTemporary files, cleared on reboot
/bootBootloader and kernel images
/usrUser programs, libraries, and documentation
/rootHome directory for the root user (not /home/root)
/runRuntime data since last boot (PIDs, sockets)
/libShared libraries needed by /bin and /sbin
/mntMount point for temporarily mounted filesystems
/optOptional/add-on software packages

Navigate to root and explore

Change into root and confirm location
$ cd /
$ pwd
/

Now run ls -lh from here to see the root directory in long format with human-readable sizes:

ls -lh from /
$ ls -lh
total 72K
lrwxrwxrwx   1 root root    7 Apr  1  2024 bin -> usr/bin
drwxr-xr-x   4 root root 4.0K Jan 15 08:22 boot
drwxr-xr-x  19 root root 3.8K Apr  3 10:01 dev
drwxr-xr-x 133 root root  12K Apr  3 09:55 etc
drwxr-xr-x   3 root root 4.0K Mar 29 18:42 home
lrwxrwxrwx   1 root root    7 Apr  1  2024 lib -> usr/lib
drwx------   2 root root  16K Mar 28 11:00 lost+found
drwxr-xr-x   2 root root 4.0K Mar 28 11:00 media
drwxr-xr-x   2 root root 4.0K Mar 28 11:00 mnt
drwxr-xr-x   5 root root 4.0K Apr  1 10:35 opt
dr-xr-xr-x 220 root root    0 Apr  3 10:01 proc
drwx------   5 root root 4.0K Apr  3 11:30 root
drwxr-xr-x  30 root root  840 Apr  3 10:01 run
lrwxrwxrwx   1 root root    8 Apr  1  2024 sbin -> usr/sbin
drwxr-xr-x   2 root root 4.0K Apr  1  2024 srv
dr-xr-xr-x  13 root root    0 Apr  3 10:01 sys
drwxrwxrwt  12 root root 4.0K Apr  3 11:28 tmp
drwxr-xr-x  14 root root 4.0K Apr  1  2024 usr
drwxr-xr-x  12 root root 4.0K Apr  1 10:35 var
Navigation shortcuts: cd ~ takes you back to your home directory. cd - takes you back to the previous directory. pwd always shows you where you are.

Testing ls Flag Variations in /

Now that you are in /, let’s experiment with different flag combinations. This is where most beginners learn what each flag actually does by seeing real output.

ls -1 — one entry per line

ls -1 (number one, not letter L)
$ ls -1
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

The -1 flag (the digit 1) forces one item per line — clean and easy to pipe into grep, wc, or other tools.

ls -1 -h — does -h work without -l?

ls -1 -h in /
$ ls -1 -h
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
Important: The -h flag (human-readable sizes) has no effect without -l. Sizes only appear in long format. To see sizes, use ls -1lh instead.

ls -a and ls –all — hidden files

ls -a in /
$ ls -a
.   ..   bin   boot   dev   etc   home   lib   lib64
media   mnt   opt   proc   root   run   sbin   srv
sys   tmp   usr   var

The -a flag reveals hidden items — those whose names begin with a dot. Every directory has . (current directory) and .. (parent directory) as special hidden entries. The real / on most systems has almost no other hidden files, but home directories have many (like .bashrc, .ssh/, .gitconfig).

–all is the same as -a
$ ls --all
.   ..   bin   boot   dev   etc   home   lib   lib64
media   mnt   opt   proc   root   run   sbin   srv
sys   tmp   usr   var
Long vs short flags: -a and --all are identical. Short flags are faster to type; long flags are more readable in scripts.

Diving into /etc/ — System Configuration

/etc/ is the most important configuration directory on a Linux system. Every major service — networking, SSH, DNS, package management, user accounts — stores its configuration files here.

ls -1 /etc/ — full listing

List /etc/ one entry per line
$ ls -1 /etc/
adduser.conf
alternatives/
apt/
bash.bashrc
ca-certificates.conf
cron.d/
cron.daily/
cron.hourly/
cron.monthly/
cron.weekly/
crontab
default/
environment
fstab
grub.d/
group
gshadow
hostname
hosts
init.d/
inputrc
issue
locale.gen
logrotate.conf
logrotate.d/
lsb-release
machine-id
motd
network/
nsswitch.conf
os-release
pam.d/
passwd
profile
profile.d/
protocols
resolv.conf
security/
services
shadow
shells
ssh/
ssl/
sudoers
sudoers.d/
sysctl.conf
sysctl.d/
systemd/
timezone
udev/
vim/
X11/

Here are the most important files and directories in /etc/:

PathPurpose
/etc/passwdUser account database (username, UID, home, shell)
/etc/shadowEncrypted user passwords (root-readable only)
/etc/groupGroup definitions
/etc/sudoersWho can run sudo and with what permissions
/etc/fstabFilesystem mount table — auto-mounts at boot
/etc/hostnameThe machine’s hostname
/etc/hostsStatic hostname-to-IP mappings
/etc/resolv.confDNS resolver settings
/etc/ssh/SSH server and client configuration
/etc/systemd/Systemd service definitions and overrides
/etc/apt/APT package manager configuration (Debian/Ubuntu)
/etc/cron.d/System cron jobs
/etc/profileSystem-wide shell environment settings
/etc/os-releaseOS identity (name, version, ID)

Why ls -1 /etc/ -h has no effect

Remember: -h only affects the size column in -l (long format). Without -l, there is no size column to format, so -h silently does nothing. Use ls -lh /etc/ to see sizes.

Useful /etc/ exploration commands

Practical /etc/ commands
ls -la /etc/          # full details including hidden files
ls /etc/ | grep ssh   # find SSH-related configs
ls -lh /etc/ssh/      # detailed view of SSH config dir
cat /etc/os-release   # show current OS version
cat /etc/hostname     # show the machine hostname
Next steps: Try ls -lh /etc/ssh/ to see SSH configs, ls /etc/apt/ for package manager settings, or ls -la ~ to see all the hidden dot-files in your home directory.