Skip to content

Day 4: Paths, File Types, Links, Manual Pages, the Vim Editor, and Shell Variables

Course: RHCSA Section: Core Command-Line Skills Topic: Absolute and relative paths, file types, hard and soft links, the man command, Vim, and shell variables Audience: Linux beginners through RHCSA exam candidates


1. Topic Introduction

This section covers five skills that appear in almost every administration task:

  1. Paths: describing where a file or directory is located.
  2. File types and links: recognizing what kind of object you are looking at, and giving one file more than one name.
  3. Manual pages: finding authoritative documentation for a command from within the system.
  4. Vim: editing configuration files and scripts in the terminal.
  5. Shell variables: storing values for the current session or making them permanent.

A system administrator works at the command line, usually on servers without a graphical editor and sometimes without internet access. Being able to navigate by path, understand what a link is, look up an option in the manual, edit a file in Vim, and set an environment variable correctly lets you complete real tasks without leaving the terminal.

Where this is used in practice

  • Pointing a stable name such as current at a versioned directory with a symbolic link.
  • Looking up the options of an unfamiliar command with man.
  • Editing /etc configuration files in Vim over SSH.
  • Setting an environment variable so that a service account or every user gets the same value.

2. Learning Objectives

After completing this section, you will be able to:

  • Distinguish absolute and relative paths and choose between them.
  • Identify a file's type from the first character of ls -l output.
  • Create hard and soft links, and explain how they differ in inode, directory support, and behavior after the original is deleted.
  • Read inode numbers and link counts.
  • Open a manual page, search inside it, navigate it, and search by keyword.
  • Open, edit, save, and quit a file in Vim using its modes.
  • Use Vim to insert, delete, copy, paste, undo, select, search, show line numbers, and split windows.
  • Create shell and environment variables, and make them persistent for one user or for all users.
  • Explain why a variable may not be visible in another shell or after a reboot.

3. Core Concepts

3.1 Absolute and relative paths

Absolute path Relative path
Starts from The root directory / Your current working directory
Begins with / Anything except /
Works from any location Yes No, it depends on where you are
Example /root/earth/asia/india earth/asia/india (when you are in /root)

Analogy: An absolute path is a full postal address. A relative path is directions from where you are standing ("two doors down").

Special path names

Name Meaning
. The current directory
.. The parent directory
~ Your home directory
/ The root of the file system

Why it matters: When you are unsure where your shell is, an absolute path works wherever you are. Relative paths are shorter when you are already near the target.

Common misunderstanding: A relative path is relative to your current working directory, not to the file's real location or to your home directory.

3.2 File types

The first character of the ls -l line shows the type.

Character Type
- Regular file
d Directory
l Symbolic link
b Block device (for example a disk)
c Character device (for example a terminal)
s Socket
p Named pipe (FIFO)

Regular files and directories are the types you use most. The rest (links, block and character devices, sockets, pipes) are often grouped as special files.

Inode: A file system record that stores a file's metadata (owner, permissions, size, timestamps) and the location of its data. A directory entry (a file name) points to an inode.

Link: An additional name for a file. Linux has two kinds.

  • Another directory entry that points to the same inode.
  • Every name is equally "original", and they cannot be told apart by looking at the inode.
  • Editing through one name changes the data for all names, since the data is shared.
  • Deleting one name removes only that name. The data remains while at least one name (and no more references) exist.
  • Normally cannot point to a directory.
  • Must be on the same file system as the target.
  • Does not consume extra data space. It adds only a directory entry.
  • A small, separate file with its own inode that stores a path to the target.
  • Can point to a directory and can cross file systems.
  • If the target is deleted or moved, the link breaks (a dangling link).
  • A relative target is interpreted relative to the link's own directory, not to your current directory.

Comparison

Hard link Soft link
Inode Same as the target Its own
Can link a directory No Yes
After the original is deleted Still works Breaks
Can cross file systems No Yes
Command ln source name ln -s target name

Common misunderstandings

  • "Hard links use extra storage." They do not use extra data space.
  • "A soft link depends on a hard link." It does not. A soft link can point at any path.
  • "Deleting a link deletes the target." Removing a link removes the name only (for soft links, the target is untouched).

3.4 Manual pages

man displays the documentation installed with most commands. A manual page typically contains NAME, SYNOPSIS, DESCRIPTION, OPTIONS, FILES, EXAMPLES, SEE ALSO, and sometimes AUTHOR and BUGS.

Sections: Pages are grouped into numbered sections. Commonly used ones are:

Section Content
1 User commands
5 File formats and configuration files
8 System administration commands

The same name can exist in more than one section, for example the passwd command and the passwd file format. Choose a section with man 5 passwd.

Why it matters: Manual pages are available on the system without internet access, so they are the quickest way to confirm an option.

Verify: Many study guides say system documentation is available during Red Hat exams. Confirm this for your exam on Red Hat's official EX200 page before relying on it.

3.5 The Vim editor

Vim is the standard terminal text editor on RHEL (vi is available even on minimal systems). It is modal: the same key does different things depending on the current mode.

Mode Purpose How to enter
Command (normal) Move, delete, copy, paste, undo Default when a file opens; press Esc to return
Insert Type text i, a, o and similar
Visual Select text v (characters), V (lines), Ctrl+V (block)
Extended command (ex) Save, quit, settings, search : from command mode

Packages: vi is provided by vim-minimal (a small core). vim comes from vim-enhanced. For daily editing they behave alike.

Common misunderstanding: Beginners type text immediately after opening a file. The editor starts in command mode, so letters are treated as commands. Press i first.

3.6 Shell variables

A variable is a named value. Names are case-sensitive, may contain letters, digits, and underscores, and cannot start with a digit. By convention, environment variables use uppercase names.

Kind Scope
Shell variable Exists only in the current shell
Environment variable Exported, so it is also passed to programs and shells started from the current shell (child processes)

Lifetime: A variable you set at the prompt is lost when that shell exits (and therefore after a reboot). It also does not appear in other terminals.

Making a variable permanent means placing the assignment in a file that the shell (or login process) reads at startup.


4. Commands and Syntax

Commands: pwd, cd, ls

pwd                       # print the current directory
cd /path/to/dir           # absolute path
cd relative/dir           # relative path
cd ..                     # up one level
cd -                      # previous directory
cd ~                      # home directory
ls -l                     # long listing; first character is the file type

Command: file

Purpose: Report what kind of data a file contains.

file /etc/passwd
file /bin/ls
file /dev/null

Explanation: file examines contents and type, while ls -l shows the file-system type in its first character.


Command: ln

Purpose: Create hard or soft links.

Syntax:

ln source linkname          # hard link
ln -s target linkname       # soft (symbolic) link

Examples:

echo "data" > original.txt
ln original.txt hard1                     # hard link
ln -s /root/original.txt soft1            # soft link with an absolute target
ln -s ../other/file.txt soft2             # soft link with a relative target

Important points

  • The first argument is what you are linking to, and the second is the new name.
  • For a soft link with a relative target, the path is read from the directory that contains the link.

Common errors

Message (approximate) Cause Resolution
hard link not allowed for directory Tried to hard-link a directory Use ln -s
Invalid cross-device link Hard link across different file systems Use ln -s
File exists The link name is already used Choose another name, or remove the old one

Command: ls -i, ls -li, stat

Purpose: Show inode numbers and link counts.

ls -li original.txt hard1 soft1
stat original.txt

Interpreting ls -li

<inode> <type/permissions> <link-count> <owner> <group> <size> <date> <name>
  • Names with the same inode number are hard links to the same data.
  • The link count (third column) is the number of hard-link names. It increases when you add a hard link.
  • A soft link starts with l in the permissions field and shows name -> target.

Purpose: Show where a symbolic link points.

readlink soft1          # the stored target
readlink -f soft1       # the resolved absolute path

Command: man

Purpose: Open manual pages.

Syntax:

man [section] name
man -k keyword          # search names and short descriptions (same as apropos)
man -f name             # one-line description (same as whatis)
whatis name
apropos keyword

Keys inside a manual page

Key Action
Space / b Page down / page up
/word then Enter Search forward
n / N Next / previous match
g / G Start / end of the page
h Help for the viewer
q Quit

Examples:

man ls
man 5 passwd
man -k password
whatis ls

Interpreting results: man -k lists matching page names with a short summary and the section in parentheses. It does not show the options. Open the page with man <name> to read them.

Common errors

Symptom Cause Resolution
man -k returns nothing appropriate The manual page index is not built or is out of date Run sudo mandb, then retry
No manual entry for x No page by that name, or the package providing it is not installed Check spelling, try man -k, install the package

Commands: vi and vim

Purpose: Edit text files.

vim filename
vi filename

Navigation (command mode)

Key Action
h j k l Left, down, up, right
gg / G First line / last line
/word then Enter Search forward
n / N Next / previous match

Insert keys

Key Typing starts
i At the cursor
I At the beginning of the line
a After the cursor
A At the end of the line
o On a new line below
O On a new line above

Press Esc to return to command mode.

Editing (command mode)

Key Action
x Delete the character under the cursor
dd Delete (cut) the current line
yy Copy (yank) the current line
p Paste after the cursor or below the line
u Undo
Ctrl+r Redo

Visual mode: press v, V, or Ctrl+V, move to extend the selection, then use y to copy or d to delete. Press Esc to leave visual mode.

Extended commands

Command Meaning
:set nu Show line numbers
:set nonu Hide line numbers
:w Save
:q Quit (refuses if there are unsaved changes)
:wq Save and quit
:q! Quit and discard changes
:wq! Save and quit, forcing the write
ZZ Save and quit (command mode shortcut)

Search and replace (related, optional): :%s/old/new/g replaces every occurrence of old with new in the file. Check the result before saving.

Split windows from the command line

vim -o file1 file2      # windows stacked top and bottom
vim -O file1 file2      # windows side by side

Quit each window with :q.

Encrypting a file in Vim

  1. Open the file and type :X. Enter a password twice, then save with :wq.
  2. Reopening the file asks for the password.
  3. To remove encryption, run :X, enter an empty password, and save.

Warning: If you forget the password, the content cannot be recovered. Vim's encryption method varies by version. Check it with :set cryptmethod?. Treat this as a convenience, not strong security.

Copy and paste with the terminal

  • In PuTTY and PowerShell over SSH, selecting text copies it and right-click pastes.
  • Paste while in insert mode. If the pasted text gets indented oddly, run :set paste first, then :set nopaste afterwards.
  • In some hosted lab consoles you can paste into the console but not copy out of it.

Commands: variables

Create and read

name="Laxmi"            # no spaces around =
echo $name
echo "${name}_lab"      # braces mark where the name ends

Export

export name             # export an existing variable
export city=Hyderabad   # create and export in one step

Inspect

env | grep city
printenv city

Remove

unset name

Reload a configuration file in the current shell

source ~/.bashrc
. ~/.bashrc             # same thing

Common errors

Symptom Cause Resolution
name: command not found after name = "x" Spaces around = Write name="x"
Variable empty in a new terminal It was set only in another shell Put it in a startup file
Edited ~/.bashrc but echo $name shows the old value The file was not reloaded Run source ~/.bashrc
Variable empty in a child shell or script It was not exported Use export

5. Configuration Files and System Paths

Variable and shell startup files

File When it is read Typical use
~/.bashrc Interactive non-login shells; usually also read by login shells through ~/.bash_profile Per-user variables, aliases
~/.bash_profile Login shells for that user Per-user login settings (on RHEL it normally includes ~/.bashrc)
/etc/profile Login shells, all users System-wide login settings
/etc/profile.d/*.sh Read by /etc/profile at login Drop-in scripts that set variables for all users
/etc/environment At login, by the PAM environment module Simple NAME=value lines

Rules for /etc/environment: It is not a shell script. Use plain NAME=value lines with no spaces around =, no export, and no variable expansion or commands.

Verify: Which login methods read /etc/environment depends on your PAM configuration. Test it on your own system, for example with su - user -c 'echo $NAME' and a fresh SSH login.

Back up before editing

cp ~/.bashrc ~/.bashrc.bak

Validating a change: Reload with source ~/.bashrc and check the value with echo. For global files, log in again (or use su - otheruser) to see the effect.

Vim settings

File Purpose
~/.vimrc Per-user Vim settings that persist, for example a line containing set number

Manual page locations

Path Purpose
/usr/share/man Installed manual pages

6. Step-by-Step Administration Procedures

Procedure 1: Practice absolute and relative paths

Goal: Reach the same directory using both kinds of path.

  1. Create a tree: bash mkdir -p ~/earth/asia/india
  2. Go there with an absolute path and confirm: bash cd /root/earth/asia/india # use your home path if you are not root pwd
  3. Go up three levels with a relative path: bash cd ../../.. pwd
  4. Go back down with a relative path: bash cd earth/asia/india pwd

Verification: pwd shows the expected location each time. Cleanup: cd ~ && rm -r ~/earth (a directory you created).


Goal: Observe the behavior of both link types.

  1. Create a file: bash cd ~ mkdir links-lab && cd links-lab echo "original data" > original.txt
  2. Create links: bash ln original.txt hard1 ln original.txt hard2 ln -s "$PWD/original.txt" soft1 ln -s original.txt soft2
  3. Compare: bash ls -li original.txt, hard1, and hard2 show the same inode and a link count of 3. soft1 and soft2 show different inodes and ->.
  4. Edit through a hard link and read through all names: bash echo "added through hard2" >> hard2 cat original.txt hard1 soft1 soft2
  5. Link a directory: bash mkdir realdir ln realdir hdir # expected to be refused ln -s realdir sdir # works ls -l
  6. Delete the original and test everything: bash rm original.txt cat hard1 hard2 # still works cat soft1 # fails: No such file or directory ls -l soft1 soft2 # still listed, now dangling

Verification: Hard links still show the data. Soft links no longer work. Cleanup: cd ~ && rm -r ~/links-lab


Procedure 3: Find information in the manual

Goal: Locate a command and an option without the internet.

  1. Find a command by keyword: bash man -k "change password" If nothing appropriate appears, run sudo mandb and retry.
  2. Open the page and search for an option: bash man passwd Type /expire, press Enter, press n for further matches, and q to quit.
  3. Compare sections: bash man 5 passwd

Verification: You can name a command that changes passwords and one of its options, found in the page.


Procedure 4: Edit a file in Vim

Goal: Use the main modes and commands.

  1. Create a file and open it: bash seq 1 5 > ~/edit.txt vim ~/edit.txt
  2. In command mode, press o, type inserted, then Esc. A new line appears after line 1.
  3. Move down with j to the line containing 3 and press dd to delete it.
  4. Press G to go to the last line, then yy and p to duplicate it.
  5. Type :set nu and press Enter to show line numbers.
  6. Save and quit with :wq.
  7. Check: bash cat ~/edit.txt

Expected result: 1, inserted, 2, 4, 5, 5. Rollback: In Vim, u undoes the last change, and :q! quits without saving. Cleanup: rm ~/edit.txt


Procedure 5: Persist a variable for one user

Goal: Make PROJECT available in every new shell for your user.

  1. Back up and edit: bash cp ~/.bashrc ~/.bashrc.bak echo 'export PROJECT=alpha' >> ~/.bashrc
  2. Reload and test: bash source ~/.bashrc echo $PROJECT
  3. Test a new login-style shell: bash bash -l -c 'echo $PROJECT'

Verification: Both commands print alpha. Rollback: cp ~/.bashrc.bak ~/.bashrc and unset PROJECT


Procedure 6: Make a variable available to all users

Goal: Set LAB_ENV for every user at login.

Prerequisites: root or sudo, and a test user (<user>).

  1. Create a drop-in script: bash echo 'export LAB_ENV=practice' | sudo tee /etc/profile.d/lab-env.sh
  2. Test as another user with a fresh login shell: bash su - <user> -c 'echo $LAB_ENV'

Verification: The command prints practice. Rollback: sudo rm /etc/profile.d/lab-env.sh

Alternative: Add LAB_ENV=practice as a plain line to /etc/environment (no export, no spaces around =), then test with a fresh login. See the notes in section 5 about which login methods read it.


7. Practical Examples

Example 1: A stable name for a versioned directory

mkdir -p ~/apps/app-1.0 ~/apps/app-1.1
ln -s app-1.1 ~/apps/current
ls -l ~/apps

Scripts can always use ~/apps/current. To upgrade, switch the link:

ln -sfn app-1.0 ~/apps/current

-f replaces the existing link and -n treats the existing link as a file instead of following it into the directory. The target app-1.0 is relative to ~/apps, which is where the link lives.

Example 2: Backup that survives accidental deletion

echo "important" > report.txt
ln report.txt report.hardlink
rm report.txt
cat report.hardlink

Why it works: A second hard link keeps the data alive when the first name is removed. This is not a real backup, because both names point at the same data. If the data is corrupted, both change.

Example 3: Finding a configuration file format

You need to know the format of /etc/passwd.

man -k passwd
man 5 passwd

Why: Section 5 describes file formats, whereas man passwd describes the command.

Example 4: A variable for a shared lab setting

echo 'export LAB_ENV=practice' | sudo tee /etc/profile.d/lab-env.sh
su - <user> -c 'echo $LAB_ENV'

Why: A drop-in script under /etc/profile.d/ applies to every login without editing /etc/profile.


8. Verification and Troubleshooting

Symptom Likely cause Diagnostic Resolution
cd says "No such file or directory" Wrong path or relative path from the wrong place pwd, ls Use an absolute path or fix your location
ln refuses to link a directory Hard links to directories are not allowed n/a Use ln -s
Soft link shows red or "No such file" Target deleted or relative target wrong ls -l, readlink -f link Recreate the link with a correct target
Soft link with a relative target does not work Target read from the link's directory, not yours readlink link Use an absolute target, or correct the relative path
man -k shows nothing Index missing sudo mandb Rebuild the index
Typed text acts like commands in Vim You are in command mode Look at the status line Press i first
Cannot quit Vim Unsaved changes n/a :wq to save, :q! to discard
Encrypted file unreadable Missing password n/a Reopen with Vim and give the password
name = "x" fails Spaces around = n/a name="x"
Variable missing in a new terminal Set only in one shell Check startup file Add to ~/.bashrc
Variable missing in a child process Not exported env \| grep name export name
Global variable not seen after a change The user has not logged in again su - user -c 'echo $NAME' Log in again

Persistent versus temporary: Variables set at the prompt are temporary. Lines in ~/.bashrc, /etc/profile.d/*.sh, or /etc/environment persist. Links and edited files persist until changed or deleted.


9. Best Practices and Important Notes

  • Use absolute paths in scripts and in situations where you may not be where you think you are.
  • Prefer soft links for directories and cross-file-system links. Use hard links only when you know why.
  • Always check a link with ls -l or readlink -f after creating it.
  • Use man and whatis before guessing an option.
  • Make a backup copy before editing configuration files, and run a syntax check where one exists.
  • Press Esc first when you are unsure which Vim mode you are in. Use u to undo mistakes.
  • Do not store secrets in plain variables in shared files such as /etc/profile.d.
  • Do not put commands that produce output or ask questions in ~/.bashrc, because they interfere with non-interactive tools.

Common mistakes

  • Reversing the order of ln arguments.
  • Using a relative soft-link target and then moving the link.
  • Forgetting source after editing ~/.bashrc.
  • Using export and spaces inside /etc/environment.

10. RHCSA Exam Preparation

Practical skills practiced in this section

  • Creating, inspecting, and diagnosing hard and soft links.
  • Using absolute paths reliably.
  • Finding option details in manual pages.
  • Editing files efficiently in Vim and saving or quitting correctly.
  • Making environment variables persistent and verifying them in a fresh login.

Habits that help

  • Verify every change with a command (ls -li, readlink, cat, echo, su -).
  • Practice Vim until saving, quitting, undo, copy, and paste are automatic.
  • Know how to find an option in man using /.

Verify: This section lists general administration skills. Whether each skill is a stated exam objective, and whether manual pages are available during the exam, must be confirmed against the current EX200 objectives and exam rules on Red Hat's website.


11. Section Summary

  • Absolute paths begin with / and work anywhere. Relative paths depend on the current directory.
  • The first character of ls -l shows the file type: -, d, l, b, c, s, p.
  • Hard links share an inode, cannot link directories or cross file systems, and survive deletion of the original. Soft links have their own inode, can link directories, and break if the target disappears.
  • man, man -k, whatis, and apropos find documentation. Press / to search inside a page and q to quit.
  • Vim has command, insert, visual, and extended-command modes. Use i to type, Esc to return, :wq to save and quit, and :q! to discard.
  • Variables set at the prompt are temporary. Use export for child processes, and place assignments in startup files for persistence.

12. Quick Revision

Command or key Purpose Notes
pwd, cd, ls -l Navigate and list First character shows the type
file name Identify content
ln src name Hard link Same inode; no directories
ln -s target name Soft link Own inode; can break
ls -li, stat Inodes and link count
readlink -f link Resolve a link
man name, man 5 name Manual page / search, n, q
man -k word, apropos Search descriptions sudo mandb if empty
whatis name One-line description
vim file Edit Starts in command mode
i a o O I A Enter insert mode Esc returns
x dd yy p u Delete, cut, copy, paste, undo Command mode
:wq :q! ZZ Save/quit, discard, shortcut
:set nu Line numbers Persist with ~/.vimrc
vim -o / vim -O Stacked / side-by-side windows
:X Encrypt in Vim Forgotten password is unrecoverable
var=value, echo $var Set and read No spaces around =
export var Pass to child processes
source ~/.bashrc Reload file
/etc/profile.d/*.sh Global variables export lines

13. Knowledge Check

  1. What is the difference between an absolute and a relative path?
  2. Which character at the start of an ls -l line indicates a symbolic link? A directory?
  3. Why do hard links to the same file show the same inode number?
  4. Name two things a soft link can do that a hard link cannot.
  5. What happens to a hard link and a soft link when the original file is deleted?
  6. What does man -k show, and what should you run if it returns nothing?
  7. Which Vim mode do you start in, and how do you begin typing text?
  8. How do you quit Vim without saving changes?
  9. What is the difference between vim -o a b and vim -O a b?
  10. Why might echo $name show an empty value in a new terminal?
  11. What is the difference between name=value and export name=value?
  12. How do you make a variable available to all users at login?

Answer Key

  1. An absolute path starts at / and works from anywhere. A relative path starts at the current directory.
  2. l for a symbolic link and d for a directory.
  3. They are directory entries that point to the same inode, so they refer to the same data.
  4. Any two of: point to a directory, cross file systems, show a clearly different inode (so it is obvious which is the link).
  5. The hard link still works and still shows the data. The soft link breaks (dangling).
  6. man -k lists page names and one-line descriptions matching the keyword. If it shows nothing, run sudo mandb to build the index.
  7. Command mode. Press i (or a, o, and so on) to enter insert mode.
  8. Press Esc, then type :q! and press Enter.
  9. -o stacks the windows (horizontal split). -O places them side by side (vertical split).
  10. The variable was set only in another shell, or was never saved to a startup file.
  11. name=value creates a shell variable visible only in the current shell. export also passes it to child processes.
  12. Put an export line in a script in /etc/profile.d/ (or a plain NAME=value line in /etc/environment), then log in again and test.