Changing directories is easy as long as you know where you are (your current directory) and how that relates to where you want to go. Show To change directories, use the cd command. This command by itself will always return you to your home directory; moving to any other directory requires a pathname. You can use absolute or relative pathnames. Absolute paths start at the top with / (referred to as root) and then look down for the requested directory; relative paths look down from your current directory, wherever that may be. The tree below is used only as an example for the purpose of explaining cd. / directory1 directory2 directory3 If you are currently in directory3 and you want to switch to directory1, you need to move up in the directory tree. Executing the command while you are in directory3, will present you with an error message explaining that there is no such directory. This is because there is no directory1 below directory3. To move up to directory1, type: This is an example of an absolute path. It tells Linux to start at the top (/) and look down until it finds directory1. A path is absolute if the first character is a /. Otherwise, it is a relative path. Absolute paths will take you to any directory, from any directory. Relative paths will only take you to directories below your current one. Use the following exercise to test what you have learned so far regarding absolute and relative paths. From your home directory, type the relative path: The command cd .. tells your system to go up to the directory immediately above the one in which you are currently working. cd ../.. tells it to go up two directories. After using the full command in the example, you should be in the directory /X11, which is where you will find configuration files and directories related to the X Window System. Take a look at your last cd command. You told your system to:
Conversely, using an absolute path would get you to the /etc/X11 directory more quickly. For example:
Table 11-1. cd Options
Now that you are starting to understand how to change directories, see what happens when you change to root's login directory (the superuser account). Type: If you are not logged in as root, you are denied permission to access that directory. Denying access to the root and other users' accounts (or login directories) is one way your Linux system prevents accidental or malicious tampering. See the Section called Ownership and Permissions. To change to the root login and root directory, use the su command. For example: [sam@halloween sam]$su Password:your root password [root@halloween sam]#cd /root [root@halloween /root]#
As soon as you give the root password, you will see the changes in your command prompt to show your new, superuser status, the root account designation at the front of the prompt and "#" at the end (as shown in the prior example). When you are done working as root, type exit at the prompt and you will return to your user account. [root@halloween /root]#exit exit [sam@halloween sam]$ What is the command to go back to home directory?You can return to your home directory from anywhere in the directory structure by typing cd on its own. Remember to include the dollar sign in the command line: without it, the echo(C) command will simply return the word ``HOME''.
How do I go back to home in Linux?How to change directory in Linux terminal. To return to the home directory immediately, use cd ~ OR cd.. To change into the root directory of Linux file system, use cd / .. To go into the root user directory, run cd /root/ as root user.. To navigate up one directory level up, use cd ... How do I go back to previous directory?Steps:. pushd . (Keep old folder path on the stack). cd .. \.. (Move to the folder whare you like to). popd (Pop it from the stack. Meaning, Come back to the old folder). What is home directory command?Your home directory has the same name as your user-name, for example, ee91ab, and it is where your personal files and subdirectories are saved. To find out what is in your home directory, type. % ls. The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory.
|