5 votes

Level1Techs explains the bash directory stack

Tags: linux, bash

2 comments

  1. hungariantoast
    Link
    I do think other tools like zsh-z are more powerful, especially when combined with stuff like fzf and fzf-tab, but I never knew about this, and it seems like a nice alternative to just using cd on...

    I do think other tools like zsh-z are more powerful, especially when combined with stuff like fzf and fzf-tab, but I never knew about this, and it seems like a nice alternative to just using cd on an unmodified system.

    Specifically, I think zsh-z is more powerful because it only requires you to cd into directories in order to add them to its index, such as cd ~/Downloads, and then in order to get back to the Downloads directory after going somewhere else, all I have to type is something like z Dow. I don't have to type the entire directory name, I don't have to be in any specific directory to get there, it just works.

    1 vote
  2. DMBuce
    Link
    Another way to approach this is to use the cd - command to flip between two directories (in Bash at least, not sure about other shells). Not as powerful as a full directory stack, but personally I...

    Another way to approach this is to use the cd - command to flip between two directories (in Bash at least, not sure about other shells). Not as powerful as a full directory stack, but personally I rarely need to quickly jump between three or more directories in a given shell session.

    Maybe that's a quirk of how I use the shell, though. In a directory structure like this:

    [root@server01 ~]# cd /usr/share/tomcat/
    [root@server01 tomcat]# ll
    total 8
    drwxr-xr-x. 2 root   root   4096 Jan 27 13:51 bin
    lrwxrwxrwx. 1 root   tomcat   11 Jan 27 13:51 conf -> /etc/tomcat
    lrwxrwxrwx. 1 root   tomcat   22 Jan 27 13:51 lib -> /usr/share/java/tomcat
    lrwxrwxrwx. 1 root   tomcat   15 Jan 27 13:51 logs -> /var/log/tomcat
    lrwxrwxrwx. 1 root   tomcat   22 Jan 27 13:51 temp -> /var/cache/tomcat/temp
    lrwxrwxrwx. 1 root   tomcat   23 Jan 27 13:51 webapps -> /var/lib/tomcat/webapps
    lrwxrwxrwx. 1 root   tomcat   22 Jan 27 13:51 work -> /var/cache/tomcat/work
    

    I've noticed that a lot of people will do something like e.g. cd webapps; ls; cd ..; cd logs; view catalina.out in order to look at what's in the webapps directory and then look at the logs in catalina.out. There's even one person I know who wouldn't trust the symlinks and does cd /var/lib/tomcat/webapps and cd /var/log/tomcat instead of those cd commands (actually it's more like cd /var; ls; cd lib; ls; cd tomcat; ls; cd webapps and so on).

    Whereas I would just do ls webapps/; view logs/catalina.out , relying on tab completion so that I don't have to type all of those paths out. That way my shell history is less cluttered and if I need to, say, look at the Apache configs on the same server, I can cd /etc/httpd; view conf*/*.conf and then flip back and forth with cd - from there.

    Anyway, sorry for the overly long explanation. Not saying that this way of doing things is superior or anything, there are of course many ways to skin this particular cat. Just presenting an alternative that works well enough for my needs.

    1 vote