+3 votes
287 views
How to use the CD command in Linux

in Linux / Unix by (552k points)
reopened | 287 views

1 Answer

+4 votes
Best answer

1. How to change from the current directory to a new directory with cd command in Linux
2. How to change to a new directory using the full path with Linux cd command
3. How to return to the previous directory in which we were previously working with cd command in Linux
4. How to change the current directory to the parent directory with Linux cd command
5. How to deploy the last working directory before going to the current one with cd command in Linux
6. How to move to the home directory with cd command in Linux
7. How to move two directories up from our current location with cd command in Linux
8. How to change the working directory to the current working directory with cd command in Linux
9. How to change directory using the Tab key with cd command in Linux
10. How to detect directories with cd command in Linux
11. How to list the contents of a directory with cd command in Linux

Many times we get scared when we are in front of a Linux terminal because of the number of commands available there, but we must really understand that each command has a fundamental role and is, depending on the type, to display information, access directories, manage files and many tasks. plus..

There are some complex commands but others that are simple and very useful for the daily tasks to be performed on Linux and one of them is the cd command, which we will analyze in detail through this TechnoWikis tutorial.

What is the cd command?

The cd (change directory) command has been developed with the essential objective of changing the directory in which we are working to go to another as needed. This cd command is a system integrated command, that is, no external program or app is required, since it is executed directly by the Linux Shell. The cd command is available in all current Linux distributions.

Its use syntax is:

 cd [-L | -P [-e]] directory 

The available usage parameters are:

-L
This parameter forces symbolic links that cd must follow, that is, when we move to another directory, a symbolic link to that directory is created, which is the default value of the cd command.
-P
This option makes use of the physical directory structure without the need to follow the symbolic links.
-and
If the -P parameter is used and it is not possible to determine the current working directory, this option will tell the cd command to generate an error. If we do not use the -P parameter with this option, -e will have no effect on the result generated.

The cd command is essentially work oriented in Linux directories. Recall that the file system has special files called directories with which the integral organization of information is sought based on its function or purpose in Linux..

All Linux files and directories depend on a main directory, which is known as root directory, so any directory that is inside another directory will be called a subdirectory. In Linux, when we open the terminal and use the command line, by default we will be in the home directory.

The directories in Linux are separated by a slash (/). Next we will see how to work with the cd command in Linux..


1. How to change from the current directory to a new directory with cd command in Linux

For this it is enough to run cd plus the new desired directory, for example:

 cd / usr / local 
image

We can see that the new directory will be highlighted in a new color.


2. How to change to a new directory using the full path with Linux cd command


It is normal that when we access directories, especially operating system directories, they have more subdirectories within it. For example, we can go directly to the path / usr / local / lib by running:
 cd / usr / local / lib 
image

3. How to return to the previous directory in which we were previously working with cd command in Linux


This is practical since many times we must go to a directory only for a certain query and then we must return again to the initial working directory. In this case we must execute the following:
 cd - 
image

4. How to change the current directory to the parent directory with Linux cd command


To perform this process, back to the main directory, we will use the following line:
 cd .. 
image

5. How to deploy the last working directory before going to the current one with cd command in Linux


If we want to know what was the directory in which we were before accessing others, we will execute the following:
 cd - 
image

6. How to move to the home directory with cd command in Linux


To return directly to the Linux home directory we have one of the following options:
 CD cd ~ 
image

7. How to move two directories up from our current location with cd command in Linux


If you are in a directory that contains multiple subdirectories and want to go up two levels, we will execute the following.
 cd ../ ../ 
image

8. How to change the working directory to the current working directory with cd command in Linux


For this action we have the following options:
 cd. cd ./ 
image

9. How to change directory using the Tab key with cd command in Linux


The use of the Tab key is ideal for changing directly to a directory. For this we must be in the directory that contains the path where we are going, in this case for example we are in the path / var / www and we will go to the HTML directory, for this we enter each initial of the directory and the Tab key if:
 / var / www $ cd / v <TAB> / w <TAB> / h <TAB> v: var w: www h: HTML var / www / html 
image

10. How to detect directories with cd command in Linux


In case of forgetting the name of a directory we can execute the following:
 cd / etc / f * 
This will display the results that start with that letter.

11. How to list the contents of a directory with cd command in Linux


For this we must go to the desired directory and use the ls command:
 cd Downloads ls 
image

We can see how the cd command is useful for accessing directories within the entire Linux structure in a secure and completely reliable way.


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Nov 9, 2019 in Linux / Unix by backtothefuture (552k points) | 303 views
+3 votes
1 answer
+4 votes
1 answer
asked Oct 4, 2019 in Linux / Unix by backtothefuture (552k points) | 404 views
+3 votes
1 answer
asked Oct 20, 2020 in Linux / Unix by backtothefuture (552k points) | 240 views
+4 votes
1 answer
asked Sep 22, 2020 in Linux / Unix by backtothefuture (552k points) | 333 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users