Terminal Commands Reference
A comprehensive reference of all terminal commands used across your DevOps labs.
Git Commands
| Command | Explanation |
|---|---|
git init |
Initializes a new Git repository in the current directory, creating a hidden .git folder to track changes. |
git add . |
Stages all new and modified files in the current directory for the next commit. |
git add README.md |
Stages a specific file (README.md) for the next commit. |
git commit -m "message" |
Saves a snapshot of all staged changes with a descriptive message. |
git status |
Shows the current branch, staged changes, unstaged changes, and untracked files. |
git push origin main |
Uploads commits from your local main branch to the remote repository on GitHub. |
git push origin feature-branch |
Uploads a specific branch to the remote repository. |
git push |
Uploads commits to the remote repository for the currently tracked branch. |
git pull origin main |
Downloads and merges changes from the remote main branch into your current local branch. |
git pull |
Downloads and merges changes from the remote for the currently tracked branch. |
git clone https://github.com/username/repo.git |
Downloads a full copy of a remote repository to your local machine, including all history. |
git clone git@github.com:username/repo.git |
Clones a repository using SSH authentication instead of HTTPS. |
git remote add origin https://github.com/username/repo.git |
Links your local repository to a remote GitHub repository so you can push and pull. |
git branch feature-branch |
Creates a new branch called feature-branch without switching to it. |
git checkout feature-branch |
Switches to an existing branch named feature-branch. |
git checkout master |
Switches back to the master (or main) branch. |
git switch feature-branch |
Modern alternative to git checkout for switching branches. |
git merge feature-branch |
Merges the specified branch into the currently active branch. |
git log |
Displays the commit history for the current branch. |
ssh-keygen -t rsa -b 4096 -C your_email@example.com |
Generates a new RSA SSH key pair (public and private) used for authenticating with GitHub or other servers. |
eval "$(ssh-agent -s)" |
Starts the SSH authentication agent in the background so it can manage your keys. |
ssh-add ~/.ssh/id_rsa |
Adds your private SSH key to the running SSH agent so it can be used for authentication. |
cat ~/.ssh/id_rsa.pub |
Prints the contents of your public SSH key to the terminal — copy this to add to GitHub. |
ssh -T git@github.com |
Tests whether your SSH key is correctly authenticated with GitHub. |
git config --global user.name "Your Name" |
Sets your name globally in Git, which appears on all commits you make. |
git config --global user.email "you@email.com" |
Sets your email globally in Git, which must match your GitHub account for contributions to be attributed correctly. |
Docker Commands
| Command | Explanation |
|---|---|
docker pull mysql:latest |
Downloads the latest MySQL image from DockerHub to your local machine without running it. |
docker pull mysql:8.0 |
Downloads a specific version (8.0) of the MySQL image from DockerHub. |
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=student99 -d mysql:latest |
Creates and starts a MySQL container named mysql-server, running in the background (-d) with the root password set via an environment variable (-e). |
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=student99 -v mysql-data:/var/lib/mysql -d mysql:latest |
Same as above, but also maps the mysql-data volume to persist database files across container restarts or deletions. |
docker run -d -p 8080:80 --name nginx-server -v nginx-data:/usr/share/nginx/html nginx |
Runs an nginx container in the background, maps host port 8080 to container port 80, names it nginx-server, and mounts a volume for the web files. |
docker ps |
Lists all currently running containers, showing their IDs, images, status, and port mappings. |
docker ps -a |
Lists all containers, including those that are stopped. |
docker stop mysql-server |
Gracefully stops a running container named mysql-server. |
docker rm mysql-server |
Removes a stopped container named mysql-server. The container must be stopped first. |
docker exec -it mysql-server mysql -uroot -p |
Opens an interactive MySQL session inside the running mysql-server container, logging in as root and prompting for a password. |
docker exec -it nginx-server bash |
Opens an interactive bash shell inside the running nginx-server container. |
docker exec -it nginx-server sh |
Opens an interactive sh shell — used for containers that do not include bash (common in lightweight images). |
docker volume create mysql-data |
Creates a named Docker volume called mysql-data for persisting data outside of containers. |
docker volume rm nginx-data |
Deletes the named volume nginx-data. The volume must not be in use by any container. |
docker container inspect mysql-server |
Displays detailed configuration and networking information for the mysql-server container, including its IP address. |
docker compose up -d |
Reads the docker-compose.yml file in the current directory and starts all defined services in the background. |
docker compose down |
Stops and removes all containers, networks, and (by default) volumes defined in the docker-compose.yml file. |
Docker Compose File Structure
The following is a reference template. Replace values in < > brackets with your own.
services:
<service-name>:
image: <image-name:version>
container_name: <container-name>
ports:
- "<host-port>:<container-port>"
volumes:
- <volume-or-path>:<container-path>
environment:
- VARIABLE=value
networks:
- <network-name>
restart: unless-stopped
depends_on:
- <other-service-name>
networks:
<network-name>:
driver: bridge
volumes:
<volume-name>:
driver: local
SQL Commands (Inside MySQL Container)
| Command | Explanation |
|---|---|
show databases; |
Lists all databases on the connected MySQL server. |
use mysql; |
Switches the active database to the one named mysql. |
show tables; |
Lists all tables in the currently selected database. |
select * from tables_priv; |
Returns all rows from the tables_priv table in the current database. |
create database wordpress; |
Creates a new database named wordpress. |
exit; |
Closes the MySQL connection and returns to the container shell. |
Linux File System & Navigation
| Command | Explanation |
|---|---|
pwd |
Prints the full path of the current working directory. |
ls |
Lists files and directories in the current directory. |
ls -la |
Lists all files (including hidden) with detailed info: permissions, owner, size, and modification date. |
cd /etc |
Changes the current directory to /etc (absolute path). |
cd ~ |
Changes to the current user's home directory regardless of where you are in the filesystem. |
cd .. |
Moves up one level to the parent directory. |
cd lab03 |
Changes to a subdirectory called lab03 within the current directory (relative path). |
mkdir devops_practice |
Creates a new directory named devops_practice in the current location. |
mkdir -p newfolder/subfolder |
Creates both the parent and child directories at once, without error if they already exist. |
touch filename.txt |
Creates a new empty file named filename.txt without opening it. |
cp file1 file2 |
Copies the contents of file1 into a new file named file2. |
cp folderA/file* folderB/ |
Copies all files starting with "file" from folderA into folderB using a wildcard. |
cp -r A/SubFolder* C |
Recursively copies all folders matching the pattern from A into C. |
mv file2 fileB |
Renames file2 to fileB (move within the same directory acts as a rename). |
rm file1 |
Permanently deletes file1 with no confirmation prompt. |
rm -d folderA |
Removes an empty directory named folderA. |
rm -rf folderB |
Forcefully and recursively deletes folderB and all its contents without any prompts. Use with caution. |
cat /etc/passwd |
Prints the contents of /etc/passwd to the terminal — useful for viewing user account info. |
tree |
Displays the directory structure in a visual tree format. Must be installed first. |
vi newfile.txt |
Opens newfile.txt in the vi text editor. Press i to insert, ESC to exit insert mode, :wq to save and quit. |
vim index.html |
Opens index.html in the improved vi editor (vim). Same key commands as vi. |
Linux User & Permission Management
| Command | Explanation |
|---|---|
sudo useradd devops_user -c "DevOps User" |
Creates a new system user named devops_user with the full name "DevOps User" stored in the account info. |
sudo passwd devops_user |
Prompts you to set or change the password for devops_user. |
sudo groupadd devops |
Creates a new group named devops. |
sudo usermod devops_user -aG devops |
Appends (-a) devops_user to the devops group (-G) without removing them from other groups. |
sudo chmod 740 A |
Sets folder A permissions: owner has read/write/execute (7), group has read only (4), others have no access (0). |
sudo chmod u+rx devops_practice |
Adds read and execute permissions for the file owner without changing group or other permissions. |
sudo chmod g=rx foldername |
Sets the group permissions to read and execute only, leaving user and other permissions unchanged. |
sudo chown devops_user devops_practice |
Changes the owner of the devops_practice directory to devops_user. |
sudo chgrp devops devops_practice |
Changes the group ownership of devops_practice to the devops group. |
ls -la |
Shows permissions, ownership, size, and modification date for all files including hidden ones. |
Permission Reference Chart:
| Octal | Binary | Meaning |
|---|---|---|
| 7 | rwx | Read, Write, Execute |
| 6 | rw- | Read, Write |
| 5 | r-x | Read, Execute |
| 4 | r-- | Read only |
| 0 | --- | No permissions |
Example: chmod 754 = owner rwx (7), group r-x (5), others r-- (4)
Linux Networking
| Command | Explanation |
|---|---|
ip addr |
Displays all network interfaces and their assigned IP addresses. |
ifconfig |
Older command for displaying network interface configuration. May need to be installed. |
ping google.com |
Sends ICMP packets to google.com to test network connectivity. Press CTRL+C to stop. |
ping 172.17.0.2 |
Pings a specific IP address — useful for testing container-to-container connectivity. |
wget https://example.com/file.tar.gz |
Downloads a file from the given URL directly to the current directory. |
curl https://example.com/file |
Transfers data from a URL. More flexible than wget — can send and receive data. |
netstat |
Displays active network connections, routing tables, and interface statistics. |
ss |
Modern replacement for netstat — shows socket statistics and active connections. |
Linux Package Management (Red Hat / RHEL / Amazon Linux)
| Command | Explanation |
|---|---|
sudo dnf update |
Updates the local package index with the latest available package versions. |
sudo dnf upgrade |
Installs all available upgrades to currently installed packages. |
sudo dnf -y update |
Updates the package index and automatically answers yes (-y) to all prompts. |
sudo dnf install nginx |
Installs the nginx web server package. |
sudo dnf -y install tree |
Installs the tree utility, automatically confirming the install. |
sudo dnf install -y stress |
Installs the stress tool for generating CPU/memory load. |
sudo yum install httpd |
Installs the Apache HTTP server using yum (used on older Amazon Linux versions). |
sudo yum install -y epel-release |
Installs the EPEL repository, expanding the available package list. |
sudo amazon-linux-extras enable epel |
Enables the EPEL extra repository on Amazon Linux instances. |
apt update |
Updates the package index on Debian/Ubuntu-based systems. |
apt install -y vim |
Installs vim on Debian/Ubuntu-based systems, auto-confirming the install. |
Linux Service Management (systemctl)
| Command | Explanation |
|---|---|
sudo systemctl enable nginx |
Configures nginx to start automatically on system boot. |
sudo systemctl start nginx |
Starts the nginx service immediately. |
sudo systemctl status nginx |
Displays the current running status of the nginx service, including recent log output. |
sudo systemctl start httpd |
Starts the Apache HTTP server (httpd) service. |
sudo service httpd start |
Older-style command to start the httpd service — equivalent to systemctl start on supported systems. |
Linux Monitoring & System Info
| Command | Explanation |
|---|---|
uname -a |
Prints detailed system information: kernel name, version, hostname, architecture, and OS. |
df -h |
Shows disk space usage for all mounted filesystems in human-readable format (KB, MB, GB). |
ps |
Lists processes running in the current shell session. |
top |
Displays a real-time, continuously updating list of running processes and resource usage. |
sudo stress --cpu 1 --timeout 120 |
Runs a CPU stress test using 1 core for 120 seconds — used to generate load and test CloudWatch alarms. |
sudo poweroff |
Shuts down the Linux system immediately. |
SSH Commands
| Command | Explanation |
|---|---|
ssh -l ec2-user -i ~/.ssh/Western-Student ec2-XX-XX.compute-1.amazonaws.com |
Connects via SSH to an AWS EC2 instance using a specific username (-l) and private key file (-i). |
ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@hostname |
Connects via SSH while skipping the host key verification prompt — used in automated scripts. |
AWS CLI / Workflow Commands
| Command | Explanation |
|---|---|
git push |
In a CI/CD context, pushing code to the main branch triggers the GitHub Actions workflow automatically. |
aws s3 sync . s3://bucket-name --exclude ".git/*" |
Syncs local files to an S3 bucket, excluding the .git directory — used in deployment pipelines. |
tar -xzvf wordpress-6.7.1.tar.gz |
Extracts a compressed .tar.gz archive, showing each file as it is extracted (-v for verbose). |
npm test |
Runs the test script defined in package.json — in a CI/CD pipeline this must pass before deployment. |
chmod 600 private_key.pem |
Sets the private key file to owner-read-only permissions, required by SSH before using the key. |
Node.js / npm Commands
| Command | Explanation |
|---|---|
npm test |
Executes the test script defined in the scripts section of package.json. |
node test.js |
Runs the test.js file directly using Node.js. |