Linux logoLinux BEGINNER

Linux Essential Commands

Essential Linux command-line reference for file operations, system management, and everyday tasks

6 min read
linuxbashshellterminalclicommandsunixcommand-line

File & Directory Operations

ls - List Files

List directory contents with various formatting options

📄 Codebash
✅ -l shows permissions, owner, size, and modification date
💡 -a includes hidden files (starting with .)
🔍 Combine flags: -lah for detailed, human-readable, with hidden files
filesdirectorylistbasic

cd - Change Directory

Navigate between directories in the filesystem

📄 Codebash
✅ Use tab completion to avoid typing full paths
💡 cd - is useful for toggling between two directories
🔍 pwd shows your current directory path
directorynavigationbasic

cp - Copy Files

Copy files and directories with options for recursive and interactive copying

📄 Codebash
✅ -r (recursive) is required for copying directories
💡 -i prompts before overwriting existing files
🔍 -p preserves timestamps, ownership, and permissions
filescopybasic

mv - Move/Rename Files

Move or rename files and directories

📄 Codebash
✅ Works for both moving and renaming files
💡 -i prompts before overwriting files
🔍 No -r needed for directories (unlike cp)
filesmoverenamebasic

rm - Remove Files

Delete files and directories (use with caution)

📄 Codebash
✅ -r (recursive) required for directories
💡 -f forces deletion without prompts (dangerous!)
🔍 Use rm -i to confirm before deleting important files
filesdeleteremovebasic

mkdir - Create Directories

Create new directories with support for nested paths

📄 Codebash
✅ -p creates parent directories as needed
💡 -m sets permissions when creating directory
🔍 Use -p to avoid errors if directory already exists
directorycreatebasic

touch - Create/Update Files

Create empty files or update timestamps

📄 Codebash
✅ Creates file if it does not exist
💡 Updates access and modification times on existing files
🔍 Useful for creating placeholder files quickly
filescreatebasic

File Viewing & Editing

cat - View Files

Display file contents, concatenate files, or create new files

📄 Codebash
✅ Best for viewing small files
💡 -n adds line numbers to output
🔍 Use less or more for large files
filesviewdisplay

less - Paginated Viewing

View files one screen at a time with navigation

📄 Codebash
✅ More efficient than cat for large files
💡 Allows forward and backward navigation
🔍 Search with / and navigate results with n/N
filesviewpagination

head & tail - View File Parts

View the beginning or end of files

📄 Codebash
✅ head shows beginning of file, tail shows end
💡 tail -f follows file updates in real-time
🔍 Perfect for monitoring log files as they grow
filesviewlogs

nano - Simple Text Editor

User-friendly terminal text editor for beginners

📄 Codebash
✅ Easiest terminal editor for beginners
💡 Shows keyboard shortcuts at bottom of screen
🔍 Use Ctrl+O to save and Ctrl+X to exit
editortextbeginner

vim - Advanced Text Editor

Powerful modal text editor with steep learning curve

📄 Codebash
✅ Extremely powerful once learned
💡 Press i to start editing, Esc to exit insert mode
🔍 Type :q! to exit without saving changes
⚡ vimtutor command provides interactive tutorial
editortextadvanced

File Permissions & Ownership

chmod - Change Permissions

Modify file and directory access permissions

📄 Codebash
✅ 755 = rwxr-xr-x (common for scripts and directories)
💡 644 = rw-r--r-- (common for regular files)
🔍 First digit=user, second=group, third=others
⚡ r=4, w=2, x=1 (add numbers for combinations)
permissionssecuritychmod

chown - Change Ownership

Change file owner and group

📄 Codebash
✅ Requires sudo for files you do not own
💡 Use colon (:) to specify group
🔍 -R changes ownership recursively in directories
ownershippermissionssudo

chgrp - Change Group

Change group ownership of files

📄 Codebash
✅ Changes only group ownership (not user)
💡 Use groups command to see available groups
🔍 Alternative to chown for group-only changes
grouppermissionsownership

Process Management

ps - View Processes

Display currently running processes

📄 Codebash
✅ ps aux shows all running processes with details
💡 Use grep to filter for specific processes
🔍 PID (Process ID) is in the second column
processesmonitoringsystem

top - Live Process Monitor

Real-time view of system processes and resource usage

📄 Codebash
✅ Updates every few seconds showing CPU and memory usage
💡 Press M to sort by memory, P to sort by CPU
🔍 Press k then enter PID to kill a process
processesmonitoringinteractive

kill - Terminate Processes

Send signals to processes to stop them

📄 Codebash
✅ kill sends SIGTERM (graceful shutdown) by default
💡 -9 sends SIGKILL (force kill, no cleanup)
🔍 Use ps aux | grep to find process PIDs
⚡ killall affects all processes with that name
processeskillterminate

Background Jobs

Run processes in background and manage jobs

📄 Codebash
✅ & runs command in background immediately
💡 Ctrl+Z suspends current process, bg resumes it in background
🔍 jobs shows all background jobs with IDs
⚡ nohup keeps process running after logout
jobsbackgroundprocesses

System Information

System Overview

Display system information and kernel details

📄 Codebash
✅ uname -a shows kernel, hostname, and architecture
💡 /etc/os-release contains distribution details
🔍 Use uname -r to check kernel version for driver compatibility
systeminfokernel

Disk Usage

Check disk space and directory sizes

📄 Codebash
✅ df -h shows available space on all mounted filesystems
💡 du -sh gives total size of a directory
🔍 -h makes sizes human-readable (GB, MB, KB)
diskstoragespace

Memory Usage

View RAM and swap memory usage

📄 Codebash
✅ free -h shows total, used, and available RAM
💡 -h displays in human-readable format
🔍 Check available column for actual free memory
memoryramsystem

System Uptime & Load

Check how long system has been running and load average

📄 Codebash
✅ uptime shows time running and load averages
💡 Load averages: 1min, 5min, 15min intervals
🔍 whoami shows current username
uptimeloadusers

Networking

ping - Test Connectivity

Check network connectivity to a host

📄 Codebash
✅ Tests if host is reachable and measures latency
💡 -c limits number of pings (useful in scripts)
🔍 Press Ctrl+C to stop continuous ping
networkconnectivityping

curl - Transfer Data

Make HTTP requests and download files from command line

📄 Codebash
✅ -O saves file with original name, -o specifies name
💡 -L follows redirects (important for many URLs)
🔍 Use -I to see headers only
networkhttpdownloadcurl

wget - Download Files

Download files from the web with resume capability

📄 Codebash
✅ Better than curl for downloading large files
💡 -c resumes interrupted downloads
🔍 Automatically retries failed downloads
networkdownloadwget

SSH - Remote Access

Securely connect to remote servers

📄 Codebash
✅ Secure encrypted connection to remote machines
💡 -i specifies private key file for authentication
🔍 Store keys in ~/.ssh/ directory (chmod 600)
networksshremotesecurity

scp - Secure Copy

Copy files between local and remote machines via SSH

📄 Codebash
✅ Uses SSH for secure file transfer
💡 -r copies directories recursively
🔍 -P (uppercase) specifies port for scp
networkscpcopyremote

Network Information

View network interfaces, connections, and routing

📄 Codebash
✅ ip addr shows all network interfaces and IPs
💡 ss is faster and more modern than netstat
🔍 -tuln shows TCP/UDP listening ports with numbers
networkipnetstatconnections

Search & Find

find - Search Files

Search for files and directories by name, type, size, and more

📄 Codebash
✅ -name searches by filename (case-sensitive)
💡 Use -iname for case-insensitive search
🔍 -exec runs commands on found files
⚡ . searches current directory and subdirectories
searchfindfiles

grep - Search File Contents

Search for patterns in file contents

📄 Codebash
✅ -i ignores case, -r searches recursively
💡 -n shows line numbers for matches
🔍 Use grep with pipes: ps aux | grep process_name
searchgreppatterntext

locate - Fast File Search

Quickly find files by name using pre-built database

📄 Codebash
✅ Much faster than find (uses database)
💡 Run updatedb to refresh file database
🔍 May not find recently created files until updatedb runs
searchlocatefast

which & whereis - Find Commands

Locate executable commands and their paths

📄 Codebash
✅ which shows path to executable in PATH
💡 whereis also shows man pages and source files
🔍 Useful for checking which version of a command will run
searchwhichwhereiscommands

Compression & Archives

tar - Archive Files

Create and extract tar archives (tape archives)

📄 Codebash
✅ c=create, x=extract, v=verbose, f=file, z=gzip, j=bzip2
💡 .tar.gz is most common compressed format
🔍 -C extracts to specific directory
⚡ Remember: "eXtract Ze Files" for -xzf
archivetarcompression

gzip - Compress Files

Compress and decompress files with gzip

📄 Codebash
✅ gzip replaces original file by default
💡 Use -k to keep original file
🔍 gunzip is alias for gzip -d
compressiongzipcompress

zip & unzip - Zip Archives

Create and extract zip archives (cross-platform)

📄 Codebash
✅ zip format is cross-platform (Windows compatible)
💡 -r zips directories recursively
🔍 unzip -l lists contents without extracting
archivezipcompressioncross-platform