0

I'm looking for shortcuts that would help me to navigate directories quickly and efficiently.

5
  • 1
    Your question is a bit vague but in Bash and zsh you can define an alias like this: alias xyz='cd /dir/I/always/work/on/'
    – Devon
    Apr 8, 2020 at 6:08
  • Sorry! I should've elaborated on my question. Right, aliases will solve my problem. Thank you! Apr 8, 2020 at 6:28
  • 1
    What operating system? And What shell? Apr 8, 2020 at 6:41
  • Pop OS 19.10. Bash shell. Apr 8, 2020 at 6:46
  • 1
    You can also just run new terminals from another terminal that's already in the directory you want it to open in, terminals open in the current directory of the parent process.
    – Dagelf
    Apr 8, 2020 at 7:05

2 Answers 2

1

You might add a short alias to your shell's login script file (e.g. ~/.bashrc if you are using the common default bash shell):

alias w='cd /full/path/to/the/dir/I/always/work/on`

When this alias is in effect, you can just type w and press Enter in the command prompt to switch into the pre-determined directory.

Setting up a GUI shortcut to open a terminal in a specific directory automatically can be tricky, depending on whether or not your Linux distribution starts individual terminal windows as equivalent to independent login sessions or not. If it does, the terminal emulator may not be able to override the directory the new login session starts in.

If the new terminal window is started as a sub-shell of the main GUI session, then it might be possible if a) your shell startup scripts (both system-wide and your personal one) don't include any commands like cd $HOME and b) your terminal emulator allows specifying a directory to start in. In the best case, it might be as simple as making a copy of the .desktop file that is used to start your terminal window normally, and adding a line to the [Desktop Entry] section of the copy:

Path=/full/path/to/the/dir/I/always/work/on
1
  • Thank you! That was helpful. Apr 8, 2020 at 6:29
1

If you mean "easily cd to that directory from anywhere", you can try CDPATH. This is a shell variable that contains a colon separated paths of directories under which to look for directories to cd into. For example, if the directory you want to have quick access to is /a/b/c/interesting_dir, then you'd put in $HOME/.bashrc:

CDPATH=.:/a/b/c

Then no matter what your current working directory can do cd int<TAB> to do tab completion on interesting_dir, then when you hit ENTER you'll wind up in /a/b/c/interesting_dir

1
  • Thank you for reaching out! I appreciate the help. Apr 8, 2020 at 6:30

Not the answer you're looking for? Browse other questions tagged .