_____                   _             ___     _________  __
 |_   _|__ _ __ _ __ ___ (_)_ __   __ _| \ \   / / ____\ \/ /
   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | |\ \ / /|  _|  \  /
   | |  __/ |  | | | | | | | | | | (_| | | \ V / | |___ /  \
   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_|  \_/  |_____/_/\_\
basics9 min

10 Essential Terminal Commands Every Developer Should Know

Introduction: Why These 10 Commands?

The terminal world contains hundreds of commands, but a handful of core commands actually make up the bulk of your daily workflow. In this article, we will cover the 10 commands you will use most frequently as a developer, complete with detailed examples. Once you master these commands, your productivity in the terminal will noticeably increase.

1. pwd — Print Working Directory

The pwd (print working directory) command displays which directory you are currently in. It is a command you will frequently use to keep track of your location when navigating the file system.

$ pwd
/home/ali/projects/web-app

$ cd /var/log
$ pwd
/var/log

Usage Tip: In shell scripts, you can assign the current directory to a variable using the pattern CURRENT_DIR=$(pwd).

2. ls — List Directory Contents

The ls (list) command lists the files and folders in the specified directory. Learning its most frequently used flags will speed up your workflow considerably.

# Simple listing
$ ls
index.html  style.css  app.js  images/

# Detailed listing (permissions, size, date)
$ ls -l
-rw-r--r-- 1 ali ali  2048 Jan 15 10:30 index.html
-rw-r--r-- 1 ali ali  1024 Jan 15 10:30 style.css
-rw-r--r-- 1 ali ali  4096 Jan 15 11:00 app.js
drwxr-xr-x 2 ali ali  4096 Jan 14 09:00 images/

# Include hidden files
$ ls -la

# Human-readable sizes
$ ls -lh
-rw-r--r-- 1 ali ali 2.0K Jan 15 10:30 index.html

# Sort by time (newest first)
$ ls -lt

# Recursive listing (include subdirectories)
$ ls -R

Common Flags:

  • -l : Long (detailed) format
  • -a : Show hidden files
  • -h : Show sizes in human-readable format (KB, MB)
  • -t : Sort by modification time
  • -R : List subdirectories recursively
  • -S : Sort by file size

3. cd — Change Directory

The cd (change directory) command allows you to navigate to different directories within the file system. It is one of the most fundamental building blocks of terminal usage.

# Go to a specified directory
$ cd projects

# Go up one directory
$ cd ..

# Go up two directories
$ cd ../..

# Return to home directory
$ cd ~
$ cd    # Same effect

# Navigate using absolute path
$ cd /var/log/nginx

# Return to previous directory
$ cd -

Pro Tip: The cd - command lets you quickly toggle between the last two directories. If you are constantly working in two different directories, this shortcut is invaluable.

4. cat — View File Contents

The cat (concatenate) command prints file contents to the terminal. It is used for quickly viewing short files, merging multiple files, and creating new files.

# Display file contents
$ cat README.md

# Show with line numbers
$ cat -n config.js
     1  const config = {
     2    port: 3000,
     3    host: 'localhost'
     4  };

# Concatenate multiple files
$ cat header.html body.html footer.html > page.html

# Append content to a file
$ cat extra-notes.txt >> notes.txt

# Squeeze blank lines
$ cat -s file.txt

Note: For very large files, prefer less or head/tail instead of cat.

5. mkdir — Create New Directories

The mkdir (make directory) command creates new directories (folders). It is one of the commands you will use most often when setting up project structures.

# Create a single directory
$ mkdir projects

# Create nested directory structure (-p flag)
$ mkdir -p projects/web-app/src/components

# Create multiple directories
$ mkdir css js images fonts

# Create with specific permissions
$ mkdir -m 755 public

The -p flag is very important: it automatically creates intermediate directories if they do not exist and does not throw an error if the directory already exists.

6. touch — Create Files and Update Timestamps

The touch command is used to create empty files or update the timestamp of existing files.

# Create an empty file
$ touch index.html

# Create multiple files
$ touch style.css app.js README.md

# Update timestamp of an existing file
$ touch -m existing-file.txt

# Assign a specific date
$ touch -t 202601151030 file.txt

Developer Tip: When starting a new project, you can use mkdir -p and touch together to quickly scaffold your project structure.

7. cp — Copy Files and Directories

The cp (copy) command is used to copy files and directories. It is essential for backups, creating templates, and duplicating files.

# Copy a file
$ cp source.txt destination.txt

# Copy to a different directory
$ cp config.js /home/ali/backup/

# Copy directory with all contents (-r: recursive)
$ cp -r src/ src-backup/

# Ask before overwriting (-i: interactive)
$ cp -i important.txt /backup/

# Preserve attributes when copying (-p: preserve)
$ cp -p file.txt backup/

# Show progress (for large files)
$ cp -v large-file.zip /destination/
'large-file.zip' -> '/destination/large-file.zip'

Common Flags: -r (recursive), -i (interactive confirmation), -v (verbose output), -p (preserve attributes), -u (copy only if newer).

8. mv — Move and Rename Files

The mv (move) command is used to move or rename files. In Linux, moving and renaming are done with the same command.

# Rename a file
$ mv old-name.txt new-name.txt

# Move a file to a different directory
$ mv report.pdf /home/ali/Documents/

# Move a directory
$ mv src/ /home/ali/projects/web-app/

# Move multiple files to a directory
$ mv *.jpg images/

# Ask before overwriting
$ mv -i file.txt destination/

# Move only if newer
$ mv -u source.txt destination/

Warning: The mv command overwrites the destination file by default if it already exists. Make it a habit to use the -i flag when working with important files.

9. rm — Remove Files and Directories

The rm (remove) command permanently deletes files and directories. This command cannot be undone; deleted files do not go to a trash can.

# Delete a file
$ rm unnecessary-file.txt

# Ask for confirmation before deleting
$ rm -i important-file.txt
rm: remove regular file 'important-file.txt'? y

# Delete an empty directory
$ rmdir empty-folder/

# Delete a directory with all contents (-r: recursive, -f: force)
$ rm -rf old-project/

# Delete only specific files
$ rm *.log
$ rm temp-*

Critical Warning: The rm -rf / command deletes the entire system! Always check which directory you are in with pwd before deleting. When possible, use rm -i or rm -I to request confirmation. Be extremely careful, especially when using wildcard characters (*).

10. echo — Print Text and Display Variables

The echo command prints text to the terminal, displays environment variables, and writes content to files. Although it appears simple, it is one of the most frequently used commands in shell scripts.

# Print text
$ echo "Hello World!"
Hello World!

# Display environment variables
$ echo $HOME
/home/ali
$ echo $PATH
/usr/local/bin:/usr/bin:/bin

# Write to a file (overwrites)
$ echo "First line" > file.txt

# Append to a file
$ echo "Second line" >> file.txt

# Special characters (-e flag)
$ echo -e "Line 1\nLine 2\tTabbed"
Line 1
Line 2	Tabbed

# Print variable value
$ PROJECT="web-app"
$ echo "Project name: $PROJECT"
Project name: web-app

Summary and Next Steps

These 10 essential commands are the building blocks of terminal usage. As you integrate them into your daily workflow, you will experience firsthand how powerful and efficient a tool the terminal truly is. You can expand your knowledge of each command by experimenting with different flag combinations and accessing detailed documentation with man command_name. Your next step should be learning to chain these commands together to create complex workflows — check out our article on pipes and redirection for that.