In this article, we cover how to change current working directory to previous working directory with cd command. Usually, we switch to previous working directory manually.
For instance, if the present working directory is /home/techpiezo/Downloads/ and the previous working directory was – /home/techpiezo/
Then, we issue following command to move to previous working directory –
So, this would take us to the previous working directory – /home/techpiezo/
Though switching back to the previous directory through above command would seem pretty easy. But, what if the directory names are long and confusing?
There is nothing wrong with the approach though. But, there is much easier and faster way to get this done where we don’t have to enter the directory name or scroll the history to get back to previous working directory.
Change to previous working directory with cd command in Linux
Just issue the following command in terminal to get back to previous directory –
Let’s understand it with the help of an example. The current working directory is – /home/techpiezo/Downloads/ and we assume that our previous working directory in the terminal was – /dev/shm/
We can issue the following command to confirm our current working directory –
This would return with the following –
Now, we want to move from our present working directory to the previous directory i.e. /dev/shm. Then, issue the following in terminal –
And, check for current working directory again –
This time around it would return with –
In conclusion, we have covered how to change to previous working directory with cd command in Linux.