0
0
Linux CLIscripting~5 mins

Home directory (~) and shortcuts in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
The home directory is where your personal files and settings live on a Linux system. The tilde (~) is a shortcut that quickly points to this home directory, saving you time when typing commands.
When you want to quickly navigate to your personal folder without typing the full path.
When you need to reference files inside your home directory in scripts or commands.
When you want to move or copy files to or from your home directory easily.
When you want to check your current directory and understand where you are in the file system.
When you want to use shortcuts to save typing and avoid mistakes in paths.
Commands
This command moves you to your home directory using the tilde shortcut.
Terminal
cd ~
Expected OutputExpected
No output (command runs silently)
Prints the current directory path to confirm you are in your home directory.
Terminal
pwd
Expected OutputExpected
/home/username
Lists the files inside the Documents folder located in your home directory using the tilde shortcut.
Terminal
ls ~/Documents
Expected OutputExpected
file1.txt file2.pdf notes.docx
Copies a file named file.txt from your home directory to the current directory.
Terminal
cp ~/file.txt ./
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else, remember that ~ always means your home directory and saves you from typing the full path.

Common Mistakes
Typing ~ without quotes in a script that does not expand it.
Some scripts or commands do not expand ~ to the home directory, causing errors.
Use $HOME environment variable or full path in scripts instead of ~.
Using ~ to refer to another user's home directory without the username.
~ alone only refers to your own home directory, not others'.
Use ~username to refer to another user's home directory.
Summary
Use cd ~ to quickly go to your home directory.
Use ~ as a shortcut in commands to refer to your home directory path.
Check your current directory with pwd to confirm your location.