To undo the cd command if you typed it by accident, enter this command.
~$ cd -
This will take you back in the directory history. A very useful trick.
Typing this is another good trick.
~$ cd --
This seems to take the user back two steps. Another useful way to navigate the bash shell.
Another way to navigate the directory structure is this command.
jason@DESKTOP-G1QN8C6:/home$ pushd ~ ~ /home ~
The pushd command does the same thing as cd and allows the user to change directory. In the case above, I am changing directory to ~, which is the home directory of my user.
[email protected]:~$ pwd /home/jason
The pwd command will print the working directory of the shell. This is the current directory you are in.
[email protected]:~$ du -ack `pwd` 1 /home/jason/.bash_history 0 /home/jason/.bash_logout 4 /home/jason/.bashrc 4 /home/jason/.profile 0 /home/jason/.sudo_as_admin_successful 13 /home/jason 13 total
As can be seen above, the pwd command can be used within another command to allow us to see all of the files taking up disk space in the home directory of our user.
More useful Linux shell tricks.