Filesystem and Basic Commands
Introduction
Linux organizes everything as files under a single tree starting at /. Paths are case-sensitive and use forward slashes. This chapter maps important directories, then practices the commands you use every day: ls, cd, cp, mv, rm, and simple search.
Prerequisites
- Linux learning environment
- Access to a bash terminal (local or SSH)
Directory Layout (FHS Overview)
| Path | Typical contents |
|---|---|
/ | Root of the whole tree |
/home/username | Your personal files (~) |
/etc | System and app configuration |
/var | Logs, databases, variable data |
/tmp | Temporary files (may clear on reboot) |
/usr | Installed programs and libraries |
/opt | Optional third-party bundles |
/root | Home directory for root user |
There is no C: drive—one filesystem tree, possibly spanning multiple disks mounted at folders like /data.
Paths: Absolute, Relative, and Special Names
| Form | Meaning |
|---|---|
/etc/ssh/sshd_config | Absolute from root |
docs/readme.md | Relative to current directory |
~ or $HOME | Your home directory |
. | Current directory |
.. | Parent directory |
# Print current directory
pwd
# Go to home
cd ~
cd
# Go to parent
cd ..
# Go to absolute path
cd /var/logWarning
README.md and readme.md are different files on Linux. Watch capitalization in Git and deploy scripts.
List and Navigate
# Long listing with hidden dotfiles
ls -la
# List /etc (system configs — look, rarely edit without reason)
ls /etcUseful ls options:
| Option | Effect |
|---|---|
-l | Long format (permissions, size, date) |
-a | Include hidden names starting with . |
-h | Human-readable sizes with -l |
Create, Copy, Move, Delete
Warning
rm -rf deletes recursively without confirmation. Double-check paths. A typo like rm -rf / tmp/foo can destroy a system—there is no Recycle Bin.
View File Contents
# Whole small file
cat /etc/os-release
# Page through large file
less /var/log/syslog
# First/last lines
head -n 20 /var/log/syslog
tail -n 20 /var/log/syslog
# Follow log live (Ctrl+C to stop)
tail -f /var/log/syslogFind Files
# Find by name under home (max depth feel with time on big trees)
find ~ -name "*.md" 2>/dev/null
# Find directories named logs
find /var -type d -name "log*" 2>/dev/null | headlocate is faster but uses a database updated by updatedb—optional on servers.
Symbolic Links (Concept)
# Create symlink
ln -s /var/log ~/logs
# List shows arrow to target
ls -l ~/logsSymlinks are pointers—similar to Windows shortcuts. Hard links are advanced and rare in daily dev work.
Compare with Windows Habits
| Windows | Linux |
|---|---|
dir | ls |
copy | cp |
move | mv |
del | rm |
type file | cat file |
Explorer path C:\Users\... | /home/user/... |
Mini Example: Project Folder Layout
Mirror a small Java-style tree by hand:
# Build tree under home
mkdir -p ~/hello-linux/src/main/java
mkdir -p ~/hello-linux/src/test/java
# Create a marker file
touch ~/hello-linux/src/main/java/.gitkeep
# Show tree (install tree package optional: sudo apt install tree)
find ~/hello-linuxLater, Maven or Gradle generate similar layouts automatically.
FAQ
How do I open the current folder in a GUI file manager?
On desktop Ubuntu: xdg-open . Servers often have no GUI—use SFTP/VS Code Remote SSH instead.
Tab completion?
Press Tab to complete paths and commands; Tab Tab shows choices.
Deleted file recovery?
Assume gone unless you use snapshots/backups. Be careful with rm.