DEV Community

Nwafor Onyebuchi
Nwafor Onyebuchi

Posted on

Basic Command Line

🔧 Step-by-Step Guide to Learn Basic Command Line

✅ Prerequisites:

  • A computer with macOS, Linux, or Windows with WSL (Windows Subsystem for Linux) or Git Bash.
  • A terminal app: Terminal (Mac), Bash (Linux), or Git Bash/WSL (Windows).

Step 1: Open the Terminal

  • macOS: Press Cmd + Space, type Terminal, hit Enter.
  • Windows: Use Git Bash or WSL.
  • Linux: Press Ctrl + Alt + T.

Step 2: Basic Navigation Commands

These help you move around your project folders.

Command What it does
pwd Shows current directory
ls Lists files/folders in a directory
ls -l Lists with details
cd foldername Move into a folder
cd .. Go up one level
cd Go to your home directory
clear Clears the terminal screen

📌 Try this:

pwd
ls
cd Desktop
mkdir mern-project
cd mern-project
Enter fullscreen mode Exit fullscreen mode

Step 3: File and Folder Management

Command What it does
mkdir foldername Make a new folder
touch filename.js Create a new file
rm filename Delete a file
rm -r foldername Delete a folder
code . (if VS Code is installed) Open current folder in VS Code

📌 Try this:

mkdir backend
cd backend
touch server.js
cd ..
Enter fullscreen mode Exit fullscreen mode

Step 4: Using Package Managers

You'll use Node.js and npm/yarn.

Install Node.js:

Basic npm commands:

Command What it does
node -v Check Node.js version
npm init -y Create a package.json file quickly
npm install express Install Express in your project
npm install Install all dependencies
npm start Run the project (if defined)

📌 Try this:

cd backend
npm init -y
npm install express
Enter fullscreen mode Exit fullscreen mode

Step 5: Running Your App

Use Node or tools like nodemon.

Command What it does
node server.js Runs your Node.js file
npx nodemon server.js Runs and watches for changes

📌 Install nodemon (optional but useful):

npm install --save-dev nodemon
Enter fullscreen mode Exit fullscreen mode

Add this to package.json:

"scripts": {
  "start": "nodemon server.js"
}
Enter fullscreen mode Exit fullscreen mode

Then run:

npm start
Enter fullscreen mode Exit fullscreen mode

Step 6: Git Basics (Optional but recommended)

Command What it does
git init Initialize Git in your folder
git status Show changes
git add . Stage all files
git commit -m "message" Commit with a message

📌 Try this:

git init
git add .
git commit -m "initial commit"
Enter fullscreen mode Exit fullscreen mode

Step 7: Bonus - Useful Tips

  • Use Tab to autocomplete folder or file names.
  • Use ↑ and ↓ arrows to scroll through previous commands.
  • Use Ctrl + C to stop running programs.

🧠 Cheat Sheet Summary

pwd                  # where am I?
ls                   # what's here?
cd folder            # go into folder
mkdir folder         # make new folder
touch file.js        # make new file
npm init -y          # init Node project
npm install express  # install a package
node file.js         # run JS file
code .               # open VS Code here
Enter fullscreen mode Exit fullscreen mode

📄 Printable Command Line Cheat Sheet (Beginner MERN Dev)

You can copy/paste this into a document or print it.

=======================
🔧 Basic Terminal Commands
=======================

pwd                 → Show current directory
ls                  → List files and folders
ls -l               → List with details
cd foldername       → Change into a folder
cd ..               → Go up one directory
mkdir foldername    → Create a new folder
touch filename.js   → Create a new file
rm filename         → Delete a file
rm -r foldername    → Delete a folder
clear               → Clear the terminal
code .              → Open folder in VS Code

=======================
📦 Node & npm
=======================

node -v             → Show Node.js version
npm init -y         → Create package.json
npm install package → Install a package
npm start           → Run the app

=======================
🚀 Running a Node App
=======================

node file.js            → Run JS file
npx nodemon file.js     → Run with auto-restart
npm install --save-dev nodemon → Install nodemon

Add to package.json:
"scripts": {
  "start": "nodemon server.js"
}

Then:
npm start

=======================
🌱 Git Basics
=======================

git init             → Start Git repo
git status           → Show changes
git add .            → Stage all files
git commit -m "msg"  → Commit changes

=======================
💡 Tips
=======================

Tab         → Auto-complete filenames
↑ ↓         → Browse command history
Ctrl + C    → Stop running process
Enter fullscreen mode Exit fullscreen mode

✅ Interactive Command Line Challenge (For Practice)

Try this in your terminal or shell:

  1. Create a new MERN project folder
   cd Desktop
   mkdir mern-tutorial
   cd mern-tutorial
Enter fullscreen mode Exit fullscreen mode
  1. Make subfolders
   mkdir backend
   mkdir frontend
Enter fullscreen mode Exit fullscreen mode
  1. Initialize a Node project in the backend
   cd backend
   npm init -y
   npm install express
   touch server.js
Enter fullscreen mode Exit fullscreen mode
  1. Add a basic server Edit server.js (or open in VS Code using code .) and paste:
   const express = require('express');
   const app = express();
   const PORT = 3000;

   app.get('/', (req, res) => {
     res.send('Hello MERN!');
   });

   app.listen(PORT, () => {
     console.log(`Server running on http://localhost:${PORT}`);
   });
Enter fullscreen mode Exit fullscreen mode
  1. Run the server
   node server.js
Enter fullscreen mode Exit fullscreen mode
  1. (Optional) Add nodemon
   npm install --save-dev nodemon
Enter fullscreen mode Exit fullscreen mode

Update package.json:

   "scripts": {
     "start": "nodemon server.js"
   }
Enter fullscreen mode Exit fullscreen mode

Run with:

   npm start
Enter fullscreen mode Exit fullscreen mode

Top comments (0)