File & Directory Management
Module 2 · Files, Text & Permissions

File & Directory Management

Creating, copying, moving, and linking files, plus the two text editors every Linux+ candidate needs on their fingertips: vim and nano.

Core File Operations

TaskCommand
Create an empty file / update its timestamp to nowtouch file
Copy a filecp source dest
Move or rename a filemv source dest
Remove filesrm file
Remove exactly one file at a time (prompt-free, no globbing surprises)rm -- file
Create a directorymkdir dirname
Create a directory and any missing parent directoriesmkdir -p a/b/c
Remove an empty directoryrmdir dirname
Remove a directory and everything in itrm -r dirname
⚠️ Common Pitfall: mkdir Fails Silently on Missing Parents

mkdir a/b/c fails with “No such file or directory” if a/b doesn’t already exist. mkdir -p a/b/c creates every missing directory in the chain in one shot — the flag Linux+ scenario questions expect when a script needs to guarantee a nested path exists.


ln file1 file2 creates a hard link — a second directory entry pointing at the exact same inode (same data on disk). ln -s file1 file2 creates a symbolic (soft) link — a small file that just points at another path by name.

Hard linkSymbolic link
Points toAn inode directlyA path (by name)
Crosses filesystems?NoYes
Links to a directory?No (with rare exceptions)Yes
Survives the original being deleted?Yes — data persists until the last link is removedNo — becomes a “dangling” link

Text Editors: vim and nano

nano is the beginner-friendly editor — what you’re typing is what gets saved, and the shortcuts are always listed at the bottom of the screen (^O write out, ^X exit).

vim is modal, faster once learned, and the editor Linux+ scenario questions assume you know. It has three core modes:

ModeHow you get thereWhat it’s for
NormalEsc (the default mode on open)Navigation and running commands
Inserti, a, o from Normal modeTyping text directly into the file
Command-line (Ex): from Normal modeSave, quit, search-and-replace, and other line commands

Common Execute-mode commands (typed after :):

CommandEffect
:wWrite (save) the file
:qQuit
:wq or :xWrite and quit
:q!Quit without saving, discarding changes
:%s/old/new/gReplace every occurrence of old with new in the file

Motions move the cursor without switching modes: h j k l (left/down/up/right), w/b (next/previous word), 0/$ (start/end of line), gg/G (top/bottom of file).

Editing operators combine with motions to act on text: d (delete), c (change — delete and enter Insert mode), y (yank/copy). So dw deletes to the end of the word, and d$ deletes to the end of the line.

⚠️ Common Pitfall: Stuck in vim? Everyone Has Been There

If a scenario question describes a user “stuck” in an editor, the fix is almost always Esc followed by :q! — return to Normal mode, then quit without saving. It’s a running joke in the Linux world for a reason: it happens to everyone at least once.


🧠 Knowledge Check

1. You need to create the directory /data/reports/2024, but neither /data nor /data/reports exists yet. Which command creates the whole path in one step?

2. What happens to a symbolic link when the file it points to is deleted?

3. In vim, you're in Insert mode and need to save and exit. What's the fastest correct sequence?


What’s Next

Files rarely stand alone — Lesson 2 covers reading, filtering, and transforming their contents from the command line.