Navigating the File System in Git Bash
Listing Files and Directories
In Git Bash, you can use the ls
command to list the contents of the current directory. For example:
$ ls
Documents Downloads Music Pictures Public Templates Videos
To list the contents of a specific directory, you can provide the directory path as an argument to the ls
command:
$ ls /home/user/Documents
file1.txt file2.pdf project_folder
Changing Directories
To change the current working directory, you can use the cd
(change directory) command. For example, to navigate to the Documents
directory:
$ cd Documents
$ pwd
/home/user/Documents
The pwd
command can be used to display the current working directory.
You can also navigate to a directory relative to the current working directory:
$ cd project_folder
$ pwd
/home/user/Documents/project_folder
To go back to the parent directory, use cd ..
:
$ cd ..
$ pwd
/home/user/Documents
Absolute and Relative Paths
In Git Bash, you can use both absolute and relative paths to navigate the file system.
An absolute path is a complete path from the root directory (denoted by /
) to the target directory or file. For example, /home/user/Documents/file1.txt
is an absolute path.
A relative path is a path that is relative to the current working directory. For example, if you are in the /home/user/Documents
directory, project_folder/file1.txt
is a relative path.
Using relative paths can make your navigation more efficient, as you don't need to type the full absolute path every time.