How to go back in directory history with the bash command and other tricks.

Posted: March 15, 2017. At: 12:40 PM. This was 12 months ago. Post ID: 10361
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

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

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.

No comments have been made. Use this form to start the conversation :)

Leave a Reply