Development & DevOps Commands

This blog is your go-to resource for essential commands across multiple tools and technologies, including Docker ,NPM, Git, Shell Scripting, and SonarQube. Whether you're a beginner looking to get started or a seasoned professional wanting a quick reference guide, this blog covers the most crucial commands you need to streamline your workflow.

Docker Commands
docker --version
Check the installed Docker version.
docker pull <image_name>
Download an image from a registry (e.g., docker pull nginx).
docker images
List all locally available Docker images.
docker rmi <image_id>
Remove a specific Docker image.
docker build -t <image_name>:<tag> .
Build a Docker image from a Dockerfile in the current directory.
docker run <image_name>
Create and start a container from an image.
docker run -d <image_name>
Run a container in detached mode (background).
docker run -it <image_name> /bin/bash
Run a container interactively with a shell.
docker ps
List running containers.
docker ps -a
List all containers (running and stopped).
docker start <container_id>
Start a stopped container.
docker stop <container_id>
Stop a running container.
docker restart <container_id>
Restart a container.
docker rm <container_id>
Remove a stopped container.
docker exec -it <container_id> /bin/bash
Open a shell inside a running container.
docker logs <container_id>
View logs of a container.
docker inspect <container_id>
Display detailed information about a container.
docker network ls
List all Docker networks.
docker volume ls
List all Docker volumes.
docker-compose up
Start containers defined in a docker-compose.yml file.
docker-compose down
Stop and remove containers, networks, and volumes defined in docker-compose.yml.
docker system prune
Remove all unused containers, networks, images, and volumes.
docker stats
Display live resource usage statistics for containers.
docker login
Log in to a Docker registry (e.g., Docker Hub).
docker push <image_name>
Push an image to a Docker registry.
  Essential npm Commands
Initialize a Project
npm init
Creates a package.json file interactively.
npm init -y
Skips the prompts and creates a default package.json.
Install Dependencies
npm install
Installs a package and adds it to dependencies in package.json.
npm install --save-dev
Installs a package as a development dependency.
npm install
Installs all dependencies listed in package.json.
Uninstall a Package
npm uninstall
Removes a package and updates package.json.
Update Dependencies
npm update
Updates all installed dependencies to the latest compatible versions.
npm update
Updates a specific package.
Check Outdated Packages
npm outdated
Lists outdated packages with available updates.
Run Scripts from package.json
npm run
Executes scripts defined in package.json under the "scripts" section.
npm run start
Commonly used to start an application.
Run a Package Without Installing It Globally
npx
Executes a package directly without installing it globally.
Install a Package Globally
npm install -g
Installs a package globally, making it available system-wide. Uninstall a Global Package
npm uninstall -g
Removes a globally installed package.
List Installed Packages
npm list
Shows installed dependencies in the current project.
npm list -g --depth=0
Lists globally installed packages.
Clear npm Cache
npm cache clean --force
Clears the cache to fix potential issues.
Check the npm Version
npm -v
Displays the installed npm version.
npm --version
Alternative command for checking the version.
Upgrade npm
npm install -g npm
Updates npm to the latest version.
GIT Commands
Initialize a Git Repository
git init
Clone a Repository
git clone
Check Repository Status
git status
Add Files to Staging
git add .
Commit Changes
git commit -m "Your commit message"
View Commit History
git log
Switch Branches
git checkout
Pull Latest Changes
git pull origin
Push Changes to Remote Repository
git push origin
Undo the Last Commit
git revert
Shell Scripting Commands
#!/bin/bash
Specify the script should run in Bash.
echo "text"
Print text or variables to the terminal.
read variable_name
Read user input and store it in a variable.
if [ condition ]; then ... fi
Conditional statement for decision-making.
for i in {1..10}; do ... done
Loop through a range of values.
while [ condition ]; do ... done
Execute a block of code repeatedly while a condition is true.
case $variable in pattern) ... ;; esac
Multi-way conditional statement.
grep "pattern" file.txt
Search for a pattern in a file.
awk '{print $1}' file.txt
Extract specific columns or data from a file.
sed 's/old/new/g' file.txt
Stream editor for text substitution and manipulation.
chmod +x script.sh
Make a script executable.
./script.sh
Execute a shell script.
export VARIABLE=value
Set an environment variable.
tar -czvf archive.tar.gz folder/
Compress files or directories into a tarball.
ssh user@host
Connect to a remote server via SSH.
SonarQube/SonarCloud Commands
sonar-scanner
Run the SonarQube scanner to analyze code.
sonar-scanner -Dsonar.projectKey=my_project
Specify a project key for analysis.
sonar-scanner -Dsonar.sources=.
Analyze the current directory as the source code.
sonar-scanner -Dsonar.host.url=http://localhost:9000
Specify the SonarQube server URL.
sonar-scanner -Dsonar.login=your_token
Authenticate using a SonarQube token.
sonar-scanner -Dsonar.exclusions=**/test/**,**/node_modules/**
Exclude specific directories from analysis.
sonar-scanner -Dsonar.coverageReportPaths=coverage.xml
Specify the path to the coverage report.
sonar-scanner -Dsonar.language=java
Specify the programming language for analysis.
sonar-scanner -Dsonar.branch.name=feature-branch
Analyze a specific branch.
sonar-scanner -Dsonar.qualitygate.wait=true
Wait for the Quality Gate status after analysis.
sonar-scanner -Dsonar.java.binaries=target/classes
Specify Java binaries for analysis.
sonar-scanner -Dsonar.tests=src/test
Specify the directory containing test files.
sonar-scanner -Dsonar.sourceEncoding=UTF-8 Set the source code encoding. sonar-scanner -Dsonar.verbose=true
Enable verbose logging for debugging.
sonar-scanner -Dsonar.scm.provider=git
Specify the SCM provider (e.g., Git).

In today' s digital world, having a website is just the beginning—getting it indexed on Google is the real game-changer!.