pushd [drive] path
- When `pushd` command is used without any drive and path then the list of previously pushed directory path will display.
- When `pushd` command is used with path only then the current working directory information will store in the stack.
- When `pushd` command is used with driver and path then the driver information will store in the stack.
Example-1: Using pushd with path and without path
Run the following commands to get the current directory information and retrieve any previously stored directory information. If no `pushd` command is executed before then “no other directory” message will print for the first command. When` pushd` command will execute with “Videos” then two entries will store in the stack. These are Videos and home directory(~). if `pushd` command will execute again then the entries of the stack information will display and the directory will change by the last entry of the stack that is home directory.
$ pushd Videos
The similar output will appear after running the above commands.
Example-2: Using `pushd` with drive and path
`pushd` command can be used with the full path of any directory. The first command `pwd` will print the current working directory information. The second command will push the “Pictures” directory by using full path of this directory with `pushd` command and the current directory will be changed to “Pictures” folder.
$ pushd /home/Fahmida/Pictures
Example-3: Check `pushed` directory list
The following commands are used to display the directory information from the stack those are inserted by `pushd` command. `dirs.` command displays the inserted directory name of the stack and `dirs –v` command displays the directory name of the stack with index value.
$ dirs -v
Example-4: Use `pushd` with positive and negative directory index
The directory information can be pushed by using positive or negative index value with `pushd` command. This example shows the use of index in `pushd` command. The following command is used here to show the current stack information with index value.
The following command will change the current directory to the folder that exist in the index 1 of the stack. Here, Videos folder exists at the index 1. After executing the command, the current directory will Videos and the index order will be changed.
The following command will count the index value from the right and change the current directory to home directory according to the index value.
If the user pushes the directory to the stack by using `pushd` command then the user doesn’t need to re-type the directory information multiple times to switch from one directory to another. Hope, the reader will able to use `pushd` command properly after reading this tutorial.