(QuickTip) Navigating large file trees (1)
Going back and forth between a bunch of different directories/folders in a large tree can be taxing, especially when looking through large numbers of directories for different files.
Sometimes, it’s helpful to be able to go back to a specific directory with a single command, without having to use pwd and note down where you were.
The following alias can be added to your ~/.bashrc file, which is loaded whenever you start a new shell or use the command . ~/.bashrc.
alias anchor='goback=$(pwd); alias goback="cd $goback; unset goback";'
Now, whenever you want to set the directory that you want to come back to, just use anchor.
When you’re done rummaging through the filesystem and want to go back to it, using goback will send you back to the correct directory and unset the anchor.
For example:
username:~$ cd /mnt/username/USB_stick_1/Backups/archive/Steam/2020/June
username:June$ anchor
username:June$ cd ~
username:~$ cd .steam
username:.steam$ cd bin
username:bin$ cd ..
username:.steam$ cd root
username:root$ cd steamapps
username:steamapps$ cd common
username:common$ pwd
/home/username/.steam/root/steamapps/common
username:common$ goback
username:June$ cp -r /home/username/.steam/root/steamapps/common/* .