Linux for CG – “easily goto directories, even if they don’t exist yet”

Quick little tidbit. This tests to see if a specific directory exists, if it does it goes to that directory, otherwise it creates the directory and then goes to it.

alias makeshot 'test -d /prj/$PROJECT/$SHOT/ && cd /prj/$PROJECT/$SHOT || mkdir -p /prj/$PROJECT/$SHOT; cd /prj/$PROJECT/$SHOT'

The first part ‘test -d’ checks if the directory exists, the command after && runs what happens if that check is true, the command after || runs if the check is false.

1 thought on “Linux for CG – “easily goto directories, even if they don’t exist yet””

  1. Another way to reference a directory is using a “relative” path. This will look for a directory relative to the directory that you are currently in. These directory specifications don’t start with a slash.

Leave a Reply

Your email address will not be published. Required fields are marked *