
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
What Does cd do on Linux
cd stands for "change directory" and is used to navigate the file system on a Linux computer. When used with a specific directory path as an argument, cd will change the current working directory to that location. For example, the command cd /home/user/documents will change the current working directory to the "documents" folder located within the "user" folder in the root directory. If you use cd command without any argument it will take you to your home directory.
The Meaning of – With cd
The "-" (dash) symbol is a shortcut that can be used with the cd command to quickly switch between the current directory and the previous directory. For example, if you are currently in the directory /home/user/documents and you run the command cd /home/user/pictures, you can then use the command cd - to quickly switch back to the /home/user/documents directory.
Additionally, it can be used to change the directory to the last directory you were working on. If you are in a directory and you use the command cd - it will change the directory to the last directory you were in.
Some examples of using the cd command in Linux are −
To change to your home directory: cd ~
To change to the parent directory of the current directory: cd ..
To change to a specific directory: cd /path/to/directory
To change to a directory named "documents" within the current directory: cd documents
To change to the last directory you were working on: cd -
To change to the previous directory: cd "$OLDPWD"
It's important to note that when using cd command, it's case sensitive so you should type the directory name correctly. Also, you should have the appropriate permissions to access the directory you're trying to change to.
Equivalent Command to cd –
The equivalent command to cd - is cd "$OLDPWD". The $OLDPWD environment variable is automatically set by the shell to the previous working directory, so using this command will have the same effect as using cd -, which is to change the current working directory to the previous directory.
In other words, you can use cd "$OLDPWD" instead of cd - to change the current working directory to the previous directory, and both will have the same effect.
As I mentioned before, the equivalent command to cd - is cd "$OLDPWD". This command uses the $OLDPWD environment variable, which is automatically set by the shell to the previous working directory.
Here are some examples of using the cd "$OLDPWD" command in Linux −
If you are currently in the directory /home/user/documents and you run the command cd /home/user/pictures, you can then use the command cd "$OLDPWD" to quickly switch back to the /home/user/documents directory.
If you are in a directory /home/user/downloads and you use the command cd /home/user/docs, you can then use the command cd "$OLDPWD" to change the directory back to /home/user/downloads
If you are in a directory /home/user/ and you use the command cd "$OLDPWD" it will change the directory to the last directory you were in.
It's important to note that $OLDPWD is a environment variable that stores the previous working directory, so using cd "$OLDPWD" command ensures that you can move back to previous directory even if you don't remember the path of it.
Conclusion
In conclusion, cd is a command in Linux used to navigate the file system by changing the current working directory. The "-" symbol is a shortcut that can be used with the cd command to quickly switch between the current directory and the previous directory. An equivalent command to cd - is cd "$OLDPWD", which changes the current working directory to the previous directory using the $OLDPWD environment variable.
- Related Articles
- What does opening a file actually do on Linux?
- Does mprotect flush instruction cache on ARM Linux
- What does the @ prefix do on string literals in C#?
- What does opt mean in Linux
- How to do simple Arithmetic on Linux Terminal?
- What Does the // Operator Do?
- What does "print >>" do in python?
- What does the method toArray() do?
- What does calling Tk() actually do?
- What does axes.flat in Matplotlib do?
- What does Tensor.detach() do in PyTorch?
- What does backward() do in PyTorch?
- What does the pandas.series.array attribute do?
- What does the pandas.series.index attribute do?
- What does the pandas.series.values attribute do?
