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


π 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 βββββββββββββββββββ>
Subscribe to my newsletter
Read articles from Sahitya Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
