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)