0

I want to know how I can include the current working directory (output of pwd) to the commands stored in .bash_history file.

I want this because sometimes same command is executed from different directories. It's really helpful to know from which directory a particular instance of a command was executed.

Anwar
  • 76,649

2 Answers2

0

Add this command to your .bash_rc:

alias pwd='pwd | tee -a ~/.bash_history' 
0

As other have suggested, writing your current directory to your .bash_history can get you back to it.

But on the fly, see if pushing the current directory on to the stack and poping back to it later might be what you need.

 pushd . 
 cd /else/where/
 popd

you can also push as many directories. Poping them one at a time will revert the working directory back in the pushed order.

  • pushd . saves the current directory (don't forget the dot .),
  • cd changes working directory,
  • popd brings you back to the last pushed (saved) directory.

These commands will also show you the folder you have saved in their respective order every time you push or pop. and when entering the command history, you will be able to track back the changes made in each directory afterwards.