This README contains commands that I find useful, particularly on UNIX-like operating systems.
conda create -n <env_name> [<package>...] [-y]
<package>...
: List of packages to install in the environment.
-y
: Answer "yes" to any confirmations automatically.
Example:
conda create -n ml python=3.9 numpy -y
conda activate <env_name>
Example:
conda activate ml
conda deactivate <env_name>
Example:
conda deactivate ml
conda clean -a
docker images
docker ps -a [--size]
--size
: Show the size of each container.
docker pull <repo>[:<tag>]
:<tag>
: Specify tag <tag>
, which defaults to latest
, from repository <repo>
.
Example:
docker pull nvidia/cuda:11.8.0-devel-ubuntu22.04
docker run \
[--gpus all] \
[-p <host_port>:<container_port>] \
[-v <host_dir>:<container_dir>] \
[{-d, -it}] \
[--rm] \
[--name <container_name>] \
{<repo>[:<tag>], <image_id>} \
[<arg>...]
--gpus all
: Access all available GPUs.
-p <host_port>:<container_port>
: Map <container_port>
on the container to <host_port>
on the host.
-v <host_dir>:<container_dir>
: Mount <host_dir>
on the host to <container_dir>
inside the container.
-d
: Run the container in background (i.e., detached mode).
-it
: Keep STDIN open even if not attached (i.e., interactive mode).
--rm
: Automatically remove the container when it exits.
--name <container_name>
: Assign name <container_name>
to the container.
<arg>...
: Arguments passed to ENTRYPOINT
(if any, in Dockerfile
).
Example:
docker run -it --name deeplearning nvidia/cuda:11.8.0-devel-ubuntu22.04
Press Ctrl
+ p
, then Ctrl
+ q
.
docker attach <container_name_or_id>
Example:
docker attach deeplearning
docker {stop, kill} <container_name_or_id>
stop
: Stop gracefully.
kill
: Stop immediately.
Example:
docker stop deeplearning
docker start [-i] <container_name_or_id>
-i
: Attach to container's STDIN (i.e., interactive mode).
Example:
docker start -i deeplearning
docker cp <local_source> <container_name_or_id>:<container_destination>
Example:
docker cp ./training_scripts/ deeplearning:/
docker cp <container_name_or_id>:<container_source> <local_destination>
Example:
docker cp deeplearning:/models/model_final.pth ./models/
docker exec -it <container_name_or_id> <command>
Example:
docker exec -it deeplearning /bin/bash
docker rm <container_name_or_id>
Example:
docker rm deeplearning
docker image rm {<repo>[:<tag>], <image_id>}
docker build \
[--platform <arch>] \
[--build-arg <arg>=<value>] \
[--no-cache] \
[-t <repo>[:<tag>]] \
<path/to/Dockerfile>
--platform <arch>
: Set build platform/architecture to <arch>
.
--build-arg <arg>=<value>
: Set build-time variable <arg>
to <value>
. If you want to set multiple build-time variables, use multiple --build-arg
s.
--no-cache
: Do not use cache when building the image.
-t <repo>[:<tag>]
: Assign repository name <repo>
to the image. Optionally, assign tag <tag>
to the image, which defaults to latest
.
Example:
docker build -t my-image .
docker commit <container_name_or_id> [<repo>[:<tag>]]
docker save -o <output_file>.tar {<repo>[:tag], <image_id>}
docker load -i <input_file>.tar
docker builder prune [-a]
-a
: Remove all unused build cache, not just dangling ones.
git config [--global] user.email <email>
--global
: Set the commit email for every repository on the computer.
git config [--global] user.name "<username>"
--global
: Set the commit username for every repository on the computer.
git clone {<repo_url>, <username>/<repo_name>}
git clone https://<pat>@github.com/<username>/<repo_name>.git
For more information on how to generate Personal Access Token (PAT), visit How to clone a private repository from GitHub.
git status
git diff
git add <file>...
Example:
git add .
git restore <file>...
git commit -m "<message>"
git push
git pull
python -m pip install [--no-deps] \
[--no-cache-dir] [-q] [-U] \
{<package>..., -r <path/to/requirements>}
--no-deps
: Do not install package dependencies.
--no-cache-dir
: Disable caching.
-q
: Give less output.
-U
: Upgrade <package>...
to the newest available version.
-r <path/to/requirements>
: Install from <path/to/requirements>
.
python -m pip install git+https://github.com/<username>/<repo_name>.git[@<branch>]
@<branch>
: Select desired branch.
Example:
python -m pip install git+https://github.com/anson416/python-utilities.git
python -m pip install git+https://<pat>@github.com/<username>/<repo_name>.git[@<branch>]
python -m pip freeze > requirements.py
python -m pip cache purge
top
lscpu
free -h
htop
watch -n 1 nvidia-smi
df -h
du -h <dir>
Example:
du -h datasets/
wget [-P <dir>] <urls>
-P
: Set download directory to <dir>
, which defaults to .
(i.e., current directory).
zip -r ./<zip_name>.zip <file>... [-x <exclude>...]