cd command in Linux is very important, When working in the terminal, all commands are bound to the current folder. Files will be created in it if the exact address has not been specified, temporary files can be created in it. And it is much more convenient to address files to a team from the current folder just by specifying the file name, and not the full path in the file system.
What does the cd command do in linux?
By default, the home folder is used as the current folder, but for more convenience we often have to change it to another. For this there is a command cd linux. In this short article we will look at how to use this command and what features it has.
linux cd command
Before we get to work with the utility, let’s look at its syntax and basic options. Strictly speaking, this is generally not a utility. It is not in the file system. This is a built-in Bash command and changes the current folder only for the shell in which it is executed. Here is the basic command syntax:
$ cd options_folder options
There are only two options, these are -P and -L. They influence how the return symbols to the previous directory and symbolic links will be handled:
- -P – allows you to follow symbolic links before all the “..” transitions are processed;
- -L – follows symbolic links only after “..” has been processed;
- -e – if the folder in which you want to go could not be found – gives an error.
Next you need to specify the directory in which to go. If this is not done, but call cd without parameters, then your home directory will be selected as the working folder. And now let’s look at a few examples of working with cd linux.
How to use cd command in linux
I will not describe here what are the ways in Linux . We considered this topic in a separate article. By default, the user’s home folder is used as the working directory. Let’s first go to one of the subfolders Folder name Kalitut:
The home folder is denoted as ~ /. Therefore, the following command will perform the same action:
True, there is an advantage. In the first command, the relative path is used, while the second is correctly executed from any folder. Now let’s move to the / usr / lib folder relative to the root:
Using the dash “-” character, you can return to the previous folder:
Using the double dot “..” you can go to the parent directory:
You can use several blocks with points to move up several levels:
As already mentioned, if you do not pass the folder to which you want to go, the home folder will be opened:
A similar result will be issued by the command:
You can use the asterisk symbol to simplify folder navigation. True, auto-completion will work only if only one folder will be started for the specified characters.
In addition to cd, there are two additional commands, pushd and popd. It can be said that a simple stack implementation for working directories. When you pushd, the current working directory is stored in memory, and the following is set in its place:
Now type popd to return to the previous directory:
This is an implementation of the stack, so the number of directories in memory is not limited to two. You can navigate through as many folders as you need.
Now you know why you need the Linux cd command, and how to use it as efficiently as possible when working in a terminal. Hope this information was helpful to you. If you have any questions, ask in the comments!
Leave a Reply