Introduction

Linux Command Line Basics

The terminal is where a developer spends a huge chunk of their time. Learning a handful of commands will unlock your entire WSL environment and make you dramatically faster.


Anatomy of a command

Every command follows the same pattern:

command [options] [arguments]
  • command — the program to run (e.g. ls, cp, mkdir)
  • options — flags that change the behavior, usually starting with - (e.g. -r, -a)
  • arguments — what to act on (e.g. a file name or folder path)

Example:

ls -la ~/projects

Here ls is the command, -la are options (show all files in long format), and ~/projects is the argument (the folder to list).


pwd

pwd stands for print working directory. It tells you exactly where you are in the filesystem.

/home/john

List files in a folder

ls

Add -l for details (permissions, size, date) and -a to show hidden files:

ls -la

Change directory

cd projects

Useful shortcuts:

ShortcutGoes to
cd ~Your home directory (/home/john)
cd ..One folder up
cd -The previous directory you were in
cd /The root of the filesystem

Working with files and folders

Create a folder

mkdir my-project

Create nested folders all at once with -p:

mkdir -p my-project/src/components

Create an empty file

touch index.js

Copy a file

cp index.js index-backup.js

Copy a folder with -r (recursive):

cp -r my-project my-project-backup

Move or rename a file

mv moves a file to a new location. If the destination is just a new name in the same folder, it renames it.

# Rename
mv old-name.js new-name.js

# Move to another folder
mv index.js src/index.js

Delete a file

rm index-backup.js

Delete a folder and everything inside it:

rm -r my-project-backup

There is no Recycle Bin in the terminal

rm permanently deletes files — they don't go to Trash. Double-check the path before pressing Enter, especially when using -r.


Reading file contents

cat index.js

Scroll through a long file

less package.json

Press q to quit, arrow keys to scroll, / to search.

Show just the first or last lines

head -n 10 index.js   # first 10 lines
tail -n 10 index.js   # last 10 lines

Finding things

Search inside files

grep "console.log" index.js

Search recursively through all files in a folder:

grep -r "console.log" src/

Find a file by name

find . -name "index.js"

Running programs

Run a JavaScript file

node index.js

Install a package

npm install express

Run a script from package.json

npm run dev

Stop a running program

Press Ctrl + C to interrupt and stop whatever is currently running in the terminal.


Managing output

Clear the terminal screen

clear

Or press Ctrl + L — same result, faster.

Redirect output to a file

node index.js > output.txt

Chain commands with &&

The second command only runs if the first one succeeds:

mkdir my-app && cd my-app

Getting help

Every command has a built-in manual. Add --help to see a quick summary:

ls --help
cp --help

For a full manual page:

man ls

Press q to exit the manual.


Quick reference

CommandWhat it does
pwdPrint current directory
ls -laList all files with details
cd <folder>Change directory
mkdir <name>Create a folder
touch <file>Create an empty file
cp <src> <dest>Copy a file
mv <src> <dest>Move or rename a file
rm <file>Delete a file
rm -r <folder>Delete a folder
cat <file>Print file contents
grep <text> <file>Search inside a file
clearClear the screen
Ctrl + CStop the running program

Next steps

You now know enough terminal to navigate confidently. Move on to How the web works to start learning what actually happens when you type a URL into a browser.

Previous
Setup your environment