The distinction between ~ and /home is that ~ is a dynamic, user-specific shortcut for the current user's home directory, whereas /home is a static, system-wide directory that contains the home directories for most regular users.
For example, if the username is "alice," then:
~expands to/home/alice./homeis the parent directory that contains/home/aliceand other users' home directories.
Here's an extensive breakdown of the differences.
~ (Tilde): A dynamic shell expansion
The tilde (~) is a powerful shortcut expanded by your command-line shell (e.g., Bash) to point to the current user's home directory. This means its value changes depending on who is logged in.
Key characteristics of ~:
- User-specific: If user "bob" types
cd ~, they will be taken to/home/bob. If user "susan" does the same, they go to/home/susan. - A shell feature: The tilde is not part of the Linux filesystem itself. It's a convenience feature of the shell that translates into an absolute path before the command is executed.
- Variable-based: The shell determines the tilde's value from the
$HOMEenvironment variable, which is set when a user logs in. If$HOMEis changed, the tilde's destination changes as well. - Works with other users: You can also use the tilde with another user's name to specify their home directory (e.g.,
cd ~susanwill take you to/home/susan, provided you have the correct permissions). - Usage in paths: The tilde is commonly used to access subdirectories and files within the home directory (e.g.,
~/Documentsis the same as/home/username/Documents).
/home: A static, system-level directory
The /home directory is a standard part of the Linux filesystem hierarchy, as defined by the Filesystem Hierarchy Standard (FHS). It is the designated location for storing the personal directories of non-privileged users.
Key characteristics of /home:
- Centralized location: It acts as a central storage point for all standard user home directories on the system.
- Filesystem structure:
/homeis a real, static directory within the overall filesystem, unlike~, which is a dynamic shortcut. - Permissions: The
/homedirectory itself is typically owned by the root user, with permissions that prevent regular users from creating files or directories directly inside it. Each subdirectory (e.g.,/home/alice) is owned by its respective user. - Not universal for all users: While it holds the home directories for most regular users, it does not hold the home directory for the superuser,
root. Therootuser's home directory is typically/root. - Separable partition: For security and convenience, system administrators can place
/homeon a separate disk partition. This allows user data to be preserved if the main system needs to be reinstalled.
Comparison at a glance
| Feature | ~ (Tilde) |
/home |
|---|---|---|
| Type | A shell shortcut or expansion. | A physical, top-level directory in the filesystem. |
| Scope | Expands to the current user's personal home directory. | Contains the home directories for all regular users. |
| Location | It represents a specific user's home directory. For a user named "john," this is /home/john. |
It is the parent directory for all standard user directories. |
| Usage | Used for navigation and scripting to reference the current user's files easily (e.g., cd ~/Documents). |
The fixed, full path to the directory, used for system administration and managing all user accounts. |
| User context | Dynamic, changes based on which user is logged in. | Static, its location is fixed in the filesystem. |
Practical examples
To illustrate the difference, imagine you have a Linux system with two users: "neo" and "trinity."
Scenario: User "neo" is logged in
pwd(print working directory) would likely show:/home/neoecho $HOMEwould show:/home/neocd ~would take "neo" to:/home/neocd /homewould take "neo" to: the/homedirectory, where they could see the directories for "neo" and "trinity" (depending on permissions).cd ~trinitywould take "neo" to:/home/trinity(permissions permitting).
Scenario: User "trinity" is logged in
pwdwould likely show:/home/trinityecho $HOMEwould show:/home/trinitycd ~would take "trinity" to:/home/trinitycd /homewould take "trinity" to: the/homedirectory, where they could see the directories for "neo" and "trinity".cd ~neowould take "trinity" to:/home/neo(permissions permitting).
As these examples show, ~ is a relative, flexible symbol, while /home is an absolute, fixed directory in the Linux file hierarchy.