File and Directory Paths in Linux
A file path is the human-readable representation of a file or directory location on a computer system. On Linux, this system is organized as a hierarchical tree of directories, starting at the root directory, indicated by a single forward slash /
.
Path Syntax
Linux uses forward slashes /
to separate directories in a path (unlike Windows, which uses backslashes \
). Example:
Each forward slash indicates that one item is located inside the one before it.
Linux is case-sensitive, meaning Subject1.jpg
and subject1.JPG
are different files. This differs from Windows and can cause naming issues when transferring files across systems.
All Files in a Single Hierarchy
On Linux, all files — even on remote shares — are part of a single directory tree. This differs from Windows, where each file system is accessed via a separate drive letter (e.g., C:
).
Whitespace in File Names
Avoid using spaces in file and folder names. If you must use them, handle them properly with quotes or escape characters:
Wildcards
Wildcards allow you to reference multiple files easily:
Wildcard | Description | Example |
---|---|---|
* |
Any number of characters | *.txt |
? |
A single character | file?.txt |
[abc] |
One of the listed chars | file[1-3].txt |
Example commands:
Further reading: The Grymoire – Bash Wildcards
Home Directory Shortcut ~/
~
(tilde) refers to the current user’s home directory.
Note: ~
will not expand inside quotes.
Tab Completion
The Tab key autocompletes file names and paths in the terminal. It saves typing and reduces errors.
If multiple matches exist, press Tab again to list them. For environment variables like $FSLDIR
, you may need:
- Press
ESC
- Then
Ctrl + Shift + E
To expand and enable tab completion.
Special Characters and Quotes
Special characters (like space, $
, or !
) can change how Bash interprets a command. Use quotes to handle names or strings with special characters.
- Single Quotes
' '
preserve everything literally. -
Cannot contain another single quote.
-
Double Quotes
" "
preserve most characters but allow variable expansion like$USER
.