- How do I cd into a directory in the home folder?
- 3 Answers 3
- Linux Home Directory
- How Linux Home Directory Command Works?
- Examples to Implement Linux Home Directory
- 1. Home Directory
- 2. Home Directory with cd Command
- 3. Home Directory with Tilde Option
- 4. Home Directory with HOME Variable
- Conclusion
- Recommended Articles
How do I cd into a directory in the home folder?
How do I change directories to downloads, from the home folder, in the latest version Ubuntu 12.10? I tried cd /downloads , but it gave an error saying that there is no such directory.
3 Answers 3
Remember: Linux is case sensitive, so Downloads and downloads are different directories.
~ is a «shortcut» to the home directory. Another one would be $HOME . If you’re already in your home directory you can just cd Downloads .
From the Downloads directory, you can quickly return to your home directory by simply typing cd at the prompt. cd ~ does the same thing.
There two basic ways to get around in BASH:
Absolute pathnames start at the root directory, denoted by a leading / , and can be used from anywhere. To use the absolute path to go to Downloads , you can run:
where is replaced with your username. You can also replace it with the environment variable $USER which usually expands to the username of the user currently running the shell. You can also replace /home/ with $HOME , which will usually expand to the absolute path of the home directory of the user running the shell.
A useful shortcut for this is
The tilde character ( ~ ) takes the place of /home/ — it expands to the home directory of the user currently running the shell. Note that this expansion will not be performed if the tilde character is in double or single quotes.
Relative pathnames start at the working directory (the one you’re in). So if you know what directory you’re in, you can use some shortcuts to get around. For example
- . (dot) refers to the current working directory
- .. (dot)(dot) refers to the parents directory of the current working directory
when you are in your Home folder and type cd Downloads you could also type ./Downloads The ./ is implied when you just type cd Downloads (working directory is implied if you don’t include a pathname).
When you are in the Downloads directory, you could also use cd .. to return to the parent directory /home/ . In this case it is easiest to just type cd , because that changes the working directory your home directory immediately wherever you are. However, the .. becomes very useful when you are navigating around nested directory structures or other locations on the system.
Linux Home Directory
In the Linux ecosystem, the home directory is also called as the home directory. It is the primary entry point of the user when they are login into the Linux environment. It is responsible to store files, folders, data, and software on /home directory with the respective individual user profile.
Web development, programming languages, Software testing & others
Syntax of Home Directory
- /home: We can use the /home as the default path for Linux Home Directory. It is the primary or starting path for entering the individual user profile.
- USER NAME: We need to pass the user name in the “/home” path. It will help to enter in the individual user profile path (in terms of the file system).
How Linux Home Directory Command Works?
When we are creating any user in the Linux system. While creating the user 5 different steps will happen. The user directory creation it comes under the same 5 different steps. When any user will be added in the Linux operating system, by default, the user directory will create in the “/home” path with the same user name.
The user directory is also known as the user home directory. It will provide the basic environment of shell and bash. It will help to execute the shell or some application-level jobs.
By default, the list of files will create in the user “/home” directory.
- bash_logout: The file is responsible to perform any action when the user or the terminal will logout.
- bash_profile: The file is responsible to perform any action when the user profile will load the in the Linux environment.
- Bashrc: The file is responsible for the necessary kinds of stuff in it. It will help to the bash or shell or other applications. We can put functions, alias, shell or bash options etc.
As we have seen, the default home directory path will present in the “/home” path. But is not mandatory that, it will always be present over there. As per the requirement, we can change the home directory for the individual user. We can change the default home directory with the help of “usermod” command (as per user level).
Examples to Implement Linux Home Directory
Following are the examples are given below:
1. Home Directory
When we are creating any user on the Linux level, the user home directory will automatically create in the “/home” path with the same user name.
Explanation: As per the above command, we are able to list out the number of user home directories. Before adding any user, there is no home directory available in the environment (refer to screenshot 1 (a)). When we are adding the user in the Linux environment. The home directory will create in “/home” path. The home directory name is similar to the user name only (refer to screenshot 1 (a)). The user can use the same directory to store the number of files, folders, data, etc. It is having the necessary permissions on the files system to store or retrieve the data from the home directory.
As discussed earlier, when any user or home directory will create in the “/home” path. It will create default 3 files in the same working directory i.e. bash_logout, bash_profile and bashrc.
2. Home Directory with cd Command
In the Linux environment, we are having the functionality to come directly in the home directory. For that, we just need to run the simple “cd” command in the shell prompt.
Command:
Explanation: As per the above command, we are simply using the “cd” command. It is a simple command but usable command in the Linux environment. When we are working in any current directory and we need to move from the current working directory to the home directory. We just simply use the “cd” command. As per the below screenshot 2 (a), we are login with the “user1” user and the current working directory is “/home/user1/data”. Now I need to move or go back to the home directory. I have just used the “cd” command in the shell window (refer to screenshot 2 (b)).
3. Home Directory with Tilde Option
We can use the “cd” command to come in the home directory from any location. Similarly, we can achieve the same functionality via the “tilde (~)” option.
Explanation: As have seen the “cd” command concept in the home directory. Similarly, we can see the concept with a tilde sign or option. As per the below screenshot 3 (a), the current working directory is “/home/user1/data”. No matter, in which location we are. If we would need to move from the current working directory to the home directory. We can use the tilde sign with the cd command. As per the above command, we are moving from the current working directory to the home directory (refer to screenshot 3 (b)).
4. Home Directory with HOME Variable
In the Linux environment, we are having the functionality to use the environment variables. With the help of the “HOME” variable, we can directly able to go the home directory.
Note: It will help to call the home directly in different shell jobs or other applications.
Explanation: In Linux, there are lots of global variables. The “#HOME” variable is one of the global variables present in the Linux operating system. As per the above command, we are able to move from any working directory to the home directory. As per the below screenshot 4 (a), we are in “/home/user1/data” directory. As per the current working directory, we are able to move from “/home/user1/data” directory to the home directory (refer screenshot 4 (b)).
Conclusion
We have seen the uncut concept of “Linux Home Directory Command” with the proper example, explanation and command with different outputs. The home directory will define the proper skeleton of the structure. It is the primary authorized storage for the Linux user. When any user will add in the Linux operating system. By default, the home directory will allocate to that user.
Recommended Articles
We hope that this EDUCBA information on “Linux Home Directory” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
502+ Hours of HD Videos
54 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
57+ Hours of HD Videos
15 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5