Home Directory (on Linux)

Share

What is a "Home Directory" on Linux?

The home directory on Linux is a directory (a folder) created to contain your user's files when your user was created on the operating system, e.g. when you install Linux Mint, you'll be asked for a username, and then a folder with the filepath /home/your-username will be created—that's your home directory.

Home directories are just normal directories on Linux. They don't have any special attributes. They're merely the default place where one would put their own files for their own user.

The equivalent on Windows is C:\Users\your-username.

Home Directory Alias

In the terminal, in Bash, a tilde character (~) will be substituted by your home directory's filepath by the shell before executing a terminal command, e.g. if you execute ls ~/Downloads, the argument that ls actually gets is /home/your-username/Downloads, they never get to see the tilde.

The home directory is also available as the environment variable $HOME.

Default Folders of a Home Directory

On Linux Mint, a home directory is created with the following default subdirectories:

  • Desktop - for files that appear on your desktop.
  • Documents - for assorted documents.
  • Pictures - the default location for photos and screenshots.
  • Music - for people who have music files instead of listening to it online.
  • Videos - the default location for your videos.
  • Templates - this is used to customize the "new file" context menu on file managers. I have no idea why they don't have a GUI for this.
  • Public - this can be used by Apache to host a website in your computer. I'm honestly not sure why it exists on everyone's PC's. Maybe there is something else that uses it?

Why Home Directories Exist?

At minimum you would have only two users in the system: the root user, which owns the system files, and your user, which owns files you created yourself. Due to how permissions work on Linux, you won't be able to modify files owned by root, and also you can't modify directories owned by root.

If you can't modify a directory, that means you can't create a file inside of it. In other words, you can't create a file anywhere because every directory is owned by root. The only exception is your home directory, which, when created, the ownership is automatically transferred to your own user, which means you can create files and folders in it, and any files and folders you create are owned by you by default.

This is merely a consequence of how the whole system works. You could, for example, change the ownership of your home directory to root. Then your applications wouldn't work anymore because they save your preferences in files in dotfiles (hidden files) inside home directory. This is a reason why you shouldn't use sudo with graphical applications. When you use sudo, by default it doesn't change environment variables like $HOME, which means a graphical application may end up saving configuration files to your $HOME while running as root, and, consequently, they will be owned by root.

What Does Mounting Home on a Different Partition Mean?

By default, when the operating system is installed, the /home directory, where all home directories are, is created in the same partition as the operating system. There is often an option in the installer for mounting it from somewhere else. This is useful, for example, if you are switching Linux distributions, and you want to use a single shared /home for both operating systems.

For example, if you have Fedora installed, and you switch to Linux Mint, you have the option to completely erase Fedora (including your /home), in which case you would need to copy your files to a temporary place first, like a thumb drive, before moving. Alternatively, you could keep Fedora installed in its own partition, and mount the /home of your Fedora partition as the /home of your Linux Mint partition. This is practically the same thing as creating a symlink.

While this is useful, the immediate problem is that now you can't delete Fedora anymore, because it's in the same partition as your /home, so what is recommended to do, instead, if you plan to distro hop a lot, is to have a separate partition just for your /home, and then you can switch and delete operating systems all the time without having to worry about files, because your files are in a separate location, and /home is just a shortcut to that location.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments