Changing Directories in Bash
In this article, we will learn how to change directories in Bash.
The term directory is used to refer to a folder. Because you frequently move between folders when using Bash and when using the Git version control system, it is essential to frequently change the directory you are working in.
There are two different ways to change directories.
- Using Git Bash commands directly
- Git Bash runs in the selected folder.
Example to run Git Bash in a selected folder:
Changing Directories in Bash
The following example will move the working directory from its existing location /c/Users/DELL/Documents to the zoom folder. To move to the directory corresponding to the intended destination, we used the term cd followed by the directory name in the command line, which is OK.
This takes us to a new directory within the zoom folder. We see by executing the ls command that it contains a text file called test.txt.
Another option is to use the cd - command, which allows you to return to the directory or folder you are in. If you accidentally navigate to the incorrect directory, this command allows you to easily navigate back to the correct directory.
For example, to return to the Documents directory after leaving it, we use the command cd - instead of typing the command with the entire path. This allows us to quickly get back to our working directory.
After executing this command, the operating system will navigate us to the Documents folder as shown below.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Running Regular Expressions in Case Statements in Bash
Publish Date:2025/03/22 Views:75 Category:OPERATING SYSTEM
-
This article explores regular expressions, their basic syntax, and how to run them in Bash using case and if-else constructs. Introduction to Regular Expressions A regular expression, also called regex or regexp, is a sequence of characters
Sending a message to logged in users in Bash
Publish Date:2025/03/22 Views:168 Category:OPERATING SYSTEM
-
This article explores methods to send data to another logged in user in Bash. This article discusses methods to find active users and send them messages. Finding Online Users in Bash Before sending data to an online user, you must verify wh
Bash copy all files from remote directory
Publish Date:2025/03/22 Views:156 Category:OPERATING SYSTEM
-
This article describes methods for copying files between different hosts on a network. It also explores the scp command and how to use it to copy files from a remote location. scp command Secure Copy Protocol (SCP) is a secure copy network
Batch file to loop through files in subdirectories
Publish Date:2025/03/22 Views:96 Category:OPERATING SYSTEM
-
This article explains how we can write a batch script to loop through files in subdirectories. We will take an example to explain the concept. Batch file to loop through files in subdirectories Assume we have the directory structure shown b
Batch file to remove X characters from a file name
Publish Date:2025/03/22 Views:153 Category:OPERATING SYSTEM
-
This article explains how we can remove specific characters from the filename of a file using a batch script. We will cover several methods below to rename files on Windows. File Explorer Renaming on Windows File Explorer offers the least f
Declaring variables in batch script
Publish Date:2025/03/22 Views:65 Category:OPERATING SYSTEM
-
This article will demonstrate how to declare and define variables in a batch script. Declaring variables in batch script In Batch, you do not need to use any additional keywords to declare integer, float, double, or string type variables. T
Batch Check for Empty Variables
Publish Date:2025/03/22 Views:86 Category:OPERATING SYSTEM
-
This article explains how we can test if a variable has been set. We can use an if statement to check if a variable has been defined. Batch check whether variables are empty For a simpler context, we will start by defining two strings, str1
Floating-point arithmetic in Bash
Publish Date:2025/03/22 Views:189 Category:OPERATING SYSTEM
-
This short article describes how to quickly perform floating-point calculations in GNU BASH (shell scripts) directly at the command prompt or in a shell script. If you work with numbers, it can be helpful to perform quick floating-point cal
Writing to a File in Bash
Publish Date:2025/03/22 Views:133 Category:OPERATING SYSTEM
-
This article will let us explore different ways to write files in bash. Files can be appended or overwritten as required. Let's see how we can do it. Different ways to write/overwrite files in Bash We will see several operators, such as and