In Linux, the Home directory (also called the “Login Directory”) is the default directory of a user. It contains the specific user’s files, data, and programs. Generally, it is the first workplace when the user logs in to the Linux system. Keeping this in view, this post provides a deep insight into the “home” directory.
The outline of this post is as typed below:
What is the Purpose of a Home Directory, and Where is it Located?
The main purpose of the home directory is also referred to as the personal workspace of a Linux user. Suppose the system has three users “itslinuxfoss”, “anna”, and “milton”. These users have the home directories like “/home/itslinuxfoss”, “/home/anna”, and “/home/milton”.
It is also used to store application configuration files, allowing users to customize their own environment and settings.
The “home” directory is generally present in the “root” directory. The “root” directory is the top-level directory that contains all the subdirectories, directories, and files present in the system. The “root” directory is denoted by the “(forward) slash (/)”.
The “home” directory is followed by the “~tilde” slash as shown below:
It denotes the “home” directory of logged-in user “itslinuxfoss”.
How to Access the Home Directory?
The user can easily access the home directory in the following ways:
- Using cd /home Command
- Using cd $HOME
- Using cd “~(tilde)” Slash
Example 1: Access Home Directory Using cd /home Command
Suppose the logged-in “itslinuxfoss” user is in the “test ” directory as shown in the screenshot:
$ pwd
Execute the “cd(change directory)” command followed by the “/home” to move into the “home” directory:
$ cd /home
The output shows that the “test” directory has been changed to “home” directory.
Example 2: Using cd $HOME
The user can also switch to the “home” directory by using the “$HOME” shell environment variable with the “cd” command in the following way:
$ cd $HOME
The “$HOME” variable contains the full path of the particular user directory. In this case, it changed the “Downloads” directory to the “home” directory, which is verified by the “pwd” command.
Example 3: Using cd “~(tilde)” Slash
The “~(tilde)” slash is another way to access the “home” directory followed by the “cd” command. Now the “itslinuxfoss” user is in the “New2” present working directory:
$ cd $HOME
Type the following “cd” command to access the “home” directory:
$ cd ~
How to Check the Home Directory Permissions?
Each file and directory available in the Linux system has three types of permissions “r(read)”, “w(write)”, and “x(execute)”. These permissions are usually assigned by default and can also be modified per requirements.
To check the “home” directory permissions, use the following “ls” command with the combination of argument “l(list)” and “d(directory)”:
$ ls -ld /home/itslinuxfoss
The output shows that the “itslniuxfoss” owner of the “home” directory has all the permissions (rwx). Whereas its associated group “itslinuxfoss” only has the “x(execute)” permission.
These default permissions are better for security as only the “itslinuxfoss” user can read, write and execute files in the “home” directory.
Conclusion
Linux “home” directory is the subdirectory/next-level of the “root” directory denoted by the “~(tilde)” slash. It also refers to the “Login Directory”, which contains the specific user files, directories, and subdirectories. Its default permissions are “750”, meaning only its owner has full rights. This post has briefly described all about the Linux “home” directory.