Which of the following commands changes the current directory in which you are working?
Introduction Show
Many Linux commands, such as the ls command, affect the current working directory. The current working directory is the directory your terminal window or command prompt is working in. Linux treats the Home directory as the default working directory. Using the In this tutorial, we will explain the Prerequisites
Linux CD Command SyntaxThe
In the command above:
For instance, to move to the Desktop directory, run:
If the command executes successfully, the current working directory is indicated in the terminal interface: If the terminal interface does not indicate the current working
directory, using the
The
The Linux Note: The Changing DirectoryTo change to a new working directory, use the
For instance, moving to Example_Directory, located in the Home directory:
Change Directory and List ContentAppend the
Using the previous example:
Changing Directory Using an Absolute PathUsing an absolute path to the directory means that the path starts from the root directory. For instance, changing to the Downloads directory using its absolute path:
Changing Directory Using a Relative PathA relative path is a path to a directory relative to the current working directory. A relative path is best used when changing to a subdirectory of the current working directory. In the example above, the Downloads directory is a subdirectory of Home. In this case, a relative path is a result of omitting the path to the current directory from the path to the new working directory:
Since the path to the current directory is /home/phoenixnap, omitting that part of the absolute path to the Downloads directory (/home/phoenixnap/Downloads) results in a relative path (Downloads). Changing to the Previous DirectoryAdding a dash symbol (
Changing to Parent DirectoryTo change to the parent of the current directory, add two period symbols ( For example, to move from Example01 to its parent directory Example_Directory:
Changing to the Root DirectoryAdd the
slash symbol (
Changing Back to the Home DirectoryIn Linux, the Home directory represents the default working directory. Using the
The absence of the current working directory path indicates that you are in the default working directory: Another way to do this is to add the tilde symbol (
Changing to Another User's Home DirectoryChange to another user's Home directory by adding the tilde symbol (
For instance, changing to the Home directory of a user named alex:
Changing to a Directory with Spaces in the NameIf the directory name contains blank spaces, change to it by surrounding the name with single quotation marks (
For example, changing to a directory named This is a directory:
Autocomplete Directory NameIf you don't know the name of the directory you are trying to move to, the Linux terminal offers an autocomplete feature. After you start typing the directory name, press the Tab button on your keyboard to get autocomplete suggestions. For instance, if you know that the name of the directory starts with an X (for instance, XYZ), type:
Conclusion After reading this tutorial, you should be able to use the Linux
Learn more about other Linux commands in our Linux commands cheat sheet. What is the command to change the current directory?Use the cd command to move from your present directory to another directory. You must have execute (search) permission in the specified directory.
What command will change the current working directory to the previous working directory?In the shell, the command cd - is a special case that changes the current working directory to the previous working directory by exchanging the values of the variables PWD and OLDPWD.
Which command is used to make directory in working directory?The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md .
What command would you type to change the current working directory to your desktop?cd - Changing Directories
You can use the cd command, which stands for Change Directory. From within ~ , our home directory, at our prompt $ , we type cd Desktop . Our terminal will change the directory and enter our Desktop folder and our prompt will now indicate that our working directory is ~/Desktop .
|