close
close

first Drop

Com TW NOw News 2024

Batch Script Command Cheat Sheet :)
news

Batch Script Command Cheat Sheet :)

It is a type of script file used in Microsoft Windows to automate tasks through a series of commands. It is executed by the Command Prompt (cmd.exe) or PowerShell and is widely used for system administration, configuration, and automating repetitive tasks.

Print/Comments

@echo off
echo Only output of the commands are displayed
@echo on
echo Output as well as commands are displayed
echo. //prints blank space
Go to full screen mode

Exit full screen

Batch file title:

title title_of_batch_file
Go to full screen mode

Exit full screen

Create a folder:

mkdir folder_name
Go to full screen mode

Exit full screen

Creating a file:

type nul > filename.txt
Go to full screen mode

Exit full screen

Press any key to connect…

pause
Go to full screen mode

Exit full screen

Escape reserved characters

echo greater than sign ^>
echo lesser than sign ^
Go to full screen mode

Exit full screen

Display the text in the file

type filename.txt
Go to full screen mode

Exit full screen

How do I create a batch file?

1) Open Notepad
2) Type batch script
3) Save in .bat format
4) Open the command prompt
5) Type “filename.bat” in command prompt

MERN Stack Batch File

Please note: In the 2nd step, instead of adding your name,

@echo off
title MERN Stack setup!
echo 1)Git initialization
git init
echo Git initialization is completed
echo Press any key to continue....
pause
echo 2)Backend part
mkdir backend
cd backend
(
echo {
echo   "name": "backend",
echo   "version": "1.0.0",
echo   "description": "Backend part",
echo   "main": "index.js",
echo   "type": "module",
echo   "dependencies": {},
echo   "devDependencies": {},
echo   "scripts": {
echo     "start": "nodemon index.js"
echo   },
echo   "author": "",
echo   "license": "ISC"
echo }
) > package.json
start /wait cmd /c "npm i dotenv express jsonwebtoken body-parser bcrypt cookie-parser mongoose uuid cors cross-env"
start /wait cmd /c "npm i nodemon --save-dev"
echo Backend dependencies installed successfully
echo Press any key to continue....
pause
echo 3)Folder structure
echo Index file creation
type nul > index.js
echo import app from "./app.js"; >> index.js
echo. >> index.js
echo app.listen(4000, ()=^>{ >> index.js
echo     console.log("Started at port: 4000"); >> index.js
echo }); >> index.js
echo Press any key to continue....
pause
echo App file creation
type nul > app.js
echo import cors from "cors"; >> app.js
echo import express from "express"; >> app.js
echo. >> app.js
echo const app=express(); >> app.js
echo. >> app.js
echo app.use(cors({ >> app.js
echo    origin: 'http://localhost:3000', >> app.js
echo    credentials: true, >> app.js
echo    methods: ('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'), >> app.js
echo    allowedHeaders: ('Content-Type', 'Authorization'), >> app.js
echo })); >> app.js
echo. >> app.js
echo export default app; >> app.js
echo Press any key to continue....
pause
echo Folder creation
mkdir models
mkdir routes
mkdir controllers
mkdir config
cd config 
type nul > config.env
cd ..
echo Folder creation completed successfully
cd ..
echo 4)Frontend part
start /wait cmd /c "npx create-react-app frontend"
cd frontend
start /wait cmd /c "npm i react-router-dom axios"
echo Frontend dependencies installed successfully
echo "Installation completed!!"
Go to full screen mode

Exit full screen

Stay tuned!
If you liked this post, don’t forget to follow me on social media for more updates and insights:

Twitter: madhavganesan
Instagram: madhavganesan
LinkedIn: madhavganesan