Getting Started with the Linux Command Line: Essential Commands & Bash Basics

Sahitya GuptaSahitya Gupta
4 min read

πŸ“ mkdir -p – Create a Directory (Like Creating a Folder in Windows)

In Linux, we use mkdir (make directory) to create folders, similar to how we create new folders in Windows Explorer. The -p option is especially useful β€” it creates parent directories as needed.

Example:

mkdir -p /home/user/projects/myapp/logs

This command creates the entire path if it doesn’t exist already β€” just like creating nested folders in Windows using File Explorer.

πŸ“ pwd – Print Working Directory

Just like in Windows where we can see the current path in the address bar of File Explorer, pwd shows the full path of your current location in the terminal.

Example:

pwd

Output might be: /home/user/projects

πŸ“‚ ls – List Files and Folders

In Windows, we double-click a folder to see what’s inside. In Linux, ls does that in the terminal.

Example:

ls

It displays all the files and directories in the current folder. Add -l or -a for more details or hidden files.

πŸ“ cd – Change Directory (Like Opening a Folder in Windows)

The cd command is used to move between directories, just like double-clicking a folder in Windows.

Example:

cd Documents

Use cd .. to go back one level β€” similar to pressing the Back button in File Explorer.

πŸ—‘οΈ rmdir – Remove Empty Directory

This command removes only empty directories.

Example:

rmdir old_folder

In Windows, this is similar to deleting an empty folder via right-click > Delete.

🧹 rm -r – Remove Directory and Contents

To delete a folder along with its files, we use rm -r.

Example:

rm -r unwanted_folder

This is equivalent to selecting a folder in Windows and pressing Shift+Delete to permanently delete it.

πŸ”„ chsh – Change Shell (Like Changing Command Line Environment)

In Windows, we can choose between CMD or PowerShell. In Linux, we have shells like bash, zsh, etc. The chsh command allows switching the default shell.

Example:

chsh -s /bin/bash

Auto-completion using Tab is a powerful feature of bash, making command-line work much faster.

⏱️ alias – Create Shortcuts for Commands

In Windows, we use desktop shortcuts. In Linux, we can create command shortcuts using alias.

Example:

alias dt='date'

Now typing dt will show the current date and time.

πŸ•˜ history – View Command History

Like the arrow key history in CMD or PowerShell, history in Linux shows the list of previously used commands.

Example:

history

Useful for reusing commands or understanding previous work.

🧭 pushd and popd – Navigate Like Browser Tabs

pushd saves your current directory and moves to a new one. popd brings you back. Think of it like browser tabs or a bookmark system in navigation.

Example:

pushd /etc

do something

popd

Very helpful when switching back and forth between folders.

❓ apropos – Search Commands by Description

Not sure what command to use? apropos helps you find the right one based on keywords, like using Windows Help or Search.

Example:

apropos network

It will list all commands related to networking.

🌍 Environment Variables: Temporary vs Permanent

Environment variables define the session’s behavior.

Temporary (For Current Session Only):

export Office=Accenture

Permanent (Across Reboots): Add to ~/.profile or ~/.pam_environment.

Just like setting system variables in Windows via System Properties > Environment Variables.

πŸ§ͺ env – View Environment Variables

In Windows, we check environment variables through system settings. In Linux, use:

env

This shows all variables like PATH, HOME, etc.

πŸ‘€ $LOGNAME, $SHELL, $PATH, $PS1 – Important Environment Variables

$LOGNAME – Your username

$SHELL – The current shell (e.g., /bin/bash)

$PATH – Where Linux looks for executable files

$PS1 – The terminal prompt format

These are like the %USERNAME%, %PATH%, etc., environment variables in Windows.

πŸ” which – Find Where a Program is Installed

Similar to checking file location in Windows. Example:

which python3

Might return: /usr/bin/python3

πŸ›£οΈ Relative vs Absolute Paths

Absolute Path: Full path from root /, like cd /home/user/projects

Relative Path: Path from current location, like cd ../other_folder

This is the same concept as in Windows file navigation.

βž• export PATH=$PATH:/opt/vlc/bin – Add New Path

This adds new directories to the system's executable search path.

Equivalent to modifying PATH variable in Windows Environment Variables section.

πŸ—’οΈ Echo with Quotes

When using echo, enclosing text in quotes ensures spaces or special characters are preserved.

Example:

echo 'Hello, this is a message with spaces.'

This mirrors the way you use quotes in CMD or PowerShell for strings.

←—————————————————— END β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”>

0
Subscribe to my newsletter

Read articles from Sahitya Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sahitya Gupta
Sahitya Gupta