~
Reference current user's home directory
TLDR
List the current user's home directory contents
List the home directory contents of another user
List the contents of the previous directory you were in
SYNOPSIS
~
DESCRIPTION
The ~ character in Linux represents the current user's home directory. It's a convenient shorthand notation used in command-line interfaces (shells) to avoid typing the full path to the home directory, which can vary depending on the user and system configuration.
Using ~ allows you to easily navigate to or specify files and directories within your home directory without needing to know its absolute path. The shell automatically expands ~ to the full path before executing the command.
For example, if your username is 'john' and your home directory is '/home/john', then '~/Documents' is equivalent to '/home/john/Documents'.
CAVEATS
The ~ character only represents the home directory of the current user executing the command. To specify another user's home directory, you can use ~username (e.g., ~jane would refer to Jane's home directory). However, access to other user's home directories is subject to file permissions.
USAGE EXAMPLES
- cd ~: Changes the current directory to the user's home directory.
- ls ~/Documents: Lists the contents of the 'Documents' directory within the user's home directory.
- cp file.txt ~/backup/: Copies 'file.txt' to the 'backup' directory within the user's home directory.
- echo $HOME: Prints the full path of the current users home directory.
HISTORY
The use of ~ as a shorthand for the home directory dates back to the early days of Unix. It was a practical solution to simplify file system navigation and command usage, especially in environments where users frequently worked within their personal directories. Its continued presence in modern Linux distributions highlights its enduring utility and ease of use.