Change directory

2 snippets across 2 stacks — Bash & Linux, Docker

SHBash & Linux

Change Directory

SH · Navigation & Files
syntax
cd [directory]
example
cd /var/log
cd ~
cd ..
cd -

Note cd with no argument returns to your home directory. cd - switches to the previous directory you were in, which is great for toggling between two locations.

DKDocker

WORKDIR — Set Working Directory

DK · Dockerfile
syntax
WORKDIR /path/to/dir
example
WORKDIR /app
COPY . .
RUN npm ci

Note All subsequent RUN, CMD, COPY, and ENTRYPOINT instructions use this directory. WORKDIR creates the directory if it does not exist. Avoid using RUN cd /app — it only affects that single RUN layer.