How to go to home directory in Linux using cd command

One of the most essential commands in Linux is the change directory command or cd command. This is how you will navigate to different directories throughout your system. Using this command will change your current working directory to a different one you specify.

Since this is such a common command for every Linux user, it comes with a few convenient shortcuts baked in. One such shortcut is the ability to return to the present user’s home directory in very few keystrokes.

In this tutorial, you will see several different ways to return to the user’s home directory with the cd command in Linux. We’ll also throw in another bonus tip to make your life using the command line a little easier.

In this tutorial you will learn:

  • How to go to home directory in Linux with cd command
  • How to go back to previous directory in Linux with cd command
How to go to home directory in Linux using cd command
How to go to home directory in Linux using cd command
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to go to home directory in Linux using cd command




Any of the following methods can be used to return to the present user’s home directory:

  1. This is the simplest. Just use the cd command and no further options.
    $ cd
    
  2. As you may know, ~ also represents the user’s home directory. Therefore you can use this command to cd into the home directory.
    $ cd ~
    
  3. It is also possible to use the system’s $HOME environment variable to accomplish the same task.
    $ cd $HOME
    
    WHERE IS MY HOME DIRECTORY?
    The $HOME is a shell environmental variable containing a full path to user directory. The $HOME variable is set automatically by the system upon its installation and is usually set to /home/username. However, it is possible to set the $HOME variable to any custom path as required. To see a full path to your home directory execute the following command echo $HOME from your shell terminal.
  4. Bonus tip: What if we need to go directly back to the directory where we just were? In that case, you can use a dash, like so:
    $ cd -
    

    This is particularly handy if you need to navigate to the home directory for something, but then want to return right back to where you were originally to continue with some other work.

Closing Thoughts

As you can see, the cd command has a few tricks that make your life a lot easier. For Linux admins and power users that spend a lot of time in the command line, this saves us a lot of time and carpal tunnel syndrome.



Comments and Discussions
Linux Forum