Unix Command Line Basics for Salesforce Developers: The Complete Beginner’s Guide (With Examples & Essential Commands
Essential Unix Commands Every Salesforce Developer Should Master in 2025 🚀
If you're a Salesforce developer working with SFDX CLI, deploying metadata, or simply navigating your local project files, understanding Unix commands isn't optional—it's essential. Whether you're on Mac, Linux, or using Windows Subsystem for Linux (WSL), these commands will supercharge your productivity and make your Salesforce development workflow smoother.
In this comprehensive guide, you'll learn the must-know Unix commands for Salesforce developers in 2025, from basic navigation to Salesforce-specific SFDX workflows, complete with practical examples you can use today.
Table of Contents
- Understanding the Foundation: What You Need to Know
- The Essential Unix Commands Every Developer Needs
- Salesforce-Specific Unix & SFDX Commands
- Quick Reference Cheat Sheet
- Combining Commands for Powerful Workflows
- Common Mistakes to Avoid
- Advanced Tips for Power Users
- Practice Exercise: Build a Salesforce Project
- Related Resources
Understanding the Foundation: What You Need to Know
What is the Kernel? 🧠
The kernel is the core component of your operating system—think of it as the conductor of an orchestra. It sits between your hardware (CPU, memory, disk) and the applications you run daily. When you execute a command in the terminal, the kernel translates that instruction into actions the hardware can understand.
CLI vs GUI: Which One Should You Use?
A Command Line Interface (CLI) is a text-based interface where you type commands to interact with your system. It's fast, scriptable, and incredibly powerful once you master it.
A Graphical User Interface (GUI) uses windows, icons, and menus that you interact with using a mouse. While more intuitive for beginners, it's often slower for repetitive tasks.
For Salesforce developers, mastering the CLI is crucial because:
- SFDX CLI operations require terminal knowledge
- Deployment scripts and automation rely on command-line tools
- Version control with Git happens primarily in the terminal
- Faster navigation and file manipulation for large Salesforce DX projects
The Essential Unix Commands Every Developer Needs 💻
1. pwd — Know Where You Are
Print Working Directory shows your current location in the file system.
pwd
Output example:
/Users/yourname/projects/salesforce-dx
When to use it: Perfect when you've been navigating multiple directories and need to confirm your current location before running commands like sfdx force:source:push or git commit.
2. ls — See What's Around You
List Files and Folders displays all contents in your current directory.
ls
Power up with options:
ls -l # Long format showing permissions, owner, size, date
ls -a # Show hidden files (starting with .)
ls -lh # Human-readable file sizes (KB, MB, GB)
ls -la # Combine both: all files in long format
Pro tip: Hidden files like .gitignore and .sfdx won't appear with plain ls—always use ls -a to see everything in your Salesforce DX project.
3. cd — Navigate Like a Pro
Change Directory is how you move through your file system.
cd myProject # Enter a folder
cd .. # Go up one level
cd ../.. # Go up two levels
cd ~ # Jump to home directory
cd /path/to/folder # Go to specific path
cd - # Go back to previous directory
Real-world Salesforce example:
cd ~/projects/salesforce-dx/force-app/main/default/classes
4. mkdir — Create Your Workspace
Make Directory creates new folders.
mkdir myProject
mkdir -p parent/child/grandchild # Create nested directories
Salesforce example:
mkdir -p force-app/main/default/triggers
5. rm — Remove Files (With Caution! ⚠️)
Remove deletes files permanently—there's no recycle bin.
rm file.txt # Delete a file
rm -r folderName # Delete a folder and contents
rm -rf folderName # Force delete (use carefully!)
rm *.txt # Delete all .txt files
Safety tip: Always double-check before using rm -rf—it's irreversible and can delete critical Salesforce project files if misused.
6. cp — Copy Files and Folders
Copy duplicates files or directories.
cp file1.txt file2.txt # Copy file
cp -r folder1 folder2 # Copy entire folder
cp *.apex ../backup/ # Copy all Apex files to backup
Use case: Creating backup copies of force-app before making significant changes to your Salesforce metadata.
7. mv — Move or Rename
Move can relocate files or rename them.
mv oldName.txt newName.txt # Rename file
mv file.txt folder/ # Move file to folder
mv *.cls ../classes/ # Move all Apex classes
8. cat — View File Contents Quickly
Concatenate displays file contents in the terminal.
cat myfile.txt
cat AccountTrigger.trigger # View trigger code
Bonus: Use cat with grep for quick searches:
cat AccountTrigger.trigger | grep "insert"
9. touch — Create Files Instantly
Touch creates empty files or updates timestamps.
touch index.js
touch .env # Create hidden config file
touch AccountController.cls # Create Apex class file
10. grep — Search Text Like a Detective 🔍
Global Regular Expression Print searches for text patterns in files.
grep "trigger" *.cls # Find "trigger" in all Apex classes
grep -r "Account" force-app/ # Recursive search in directory
grep -i "soql" *.cls # Case-insensitive search
Pro tip: Combine with other commands:
ls -la | grep ".xml" # List only XML files
11. echo — Print and Test
Echo displays text or variable values.
echo "Hello World"
echo $PATH # Show PATH environment variable
echo "export JAVA_HOME=/path" >> ~/.bash_profile # Append to file
12. code . — Open VS Code Instantly
Opens the current directory in Visual Studio Code.
code . # Open current folder
code myfile.cls # Open specific file
Setup required: Install VS Code command-line tools from the Command Palette (Cmd/Ctrl + Shift + P) → Shell Command: Install "code" command in PATH.
Salesforce-Specific Unix & SFDX Commands 🌩️
Now let's apply these Unix fundamentals to real Salesforce development workflows using the SFDX CLI.
Check SFDX Version
sfdx --version
Use this to ensure you're running the latest SFDX version for bug fixes and features.
Authorize a Salesforce Org
sfdx auth:web:login -a DevOrg
sfdx auth:web:login -a ProdOrg -r https://login.salesforce.com
The -a flag assigns an alias for easy reference later.
Pull Metadata from Scratch Org
sfdx force:source:pull
sfdx force:source:pull -f # Force pull, overwrite local changes
Push Metadata to Org
sfdx force:source:push
sfdx force:source:push -f # Force push
Run Apex Tests
sfdx force:apex:test:run --resultformat human
sfdx force:apex:test:run -n AccountTriggerTest --resultformat human
Create a Scratch Org
sfdx force:org:create -f config/project-scratch-def.json -a MyScratchOrg
Deploy to Production
sfdx force:source:deploy -p force-app/main/default -u ProdOrg
Quick Reference Cheat Sheet 📋
Here’s a handy Unix command cheat sheet for Salesforce developers you can refer to while working with SFDX projects.
| Command | Purpose | Example |
|---|---|---|
pwd |
Show current directory | pwd |
ls |
List files/folders | ls -la |
cd folder |
Change directory | cd force-app |
cd .. |
Go up one level | cd .. |
mkdir name |
Create folder | mkdir components |
rm file |
Delete file | rm old.txt |
rm -r folder |
Delete folder | rm -r temp/ |
cp a b |
Copy | cp test.cls backup.cls |
mv a b |
Move/rename | mv old.cls new.cls |
cat file |
View file | cat trigger.trigger |
touch file |
Create empty file | touch .gitignore |
grep "text" file |
Search text | grep "Account" *.cls |
code . |
Open VS Code | code . |
Combining Commands for Powerful Workflows 🔗
The real magic happens when you chain Unix commands together. This is where Salesforce developers can save huge amounts of time.
Example 1: Find All Apex Classes with SOQL Queries
grep -r "SELECT" force-app/main/default/classes/*.cls
Example 2: Create Project Structure Quickly
mkdir -p force-app/main/default/{classes,triggers,lwc,aura} && \
touch force-app/main/default/classes/.gitkeep
Example 3: Backup Before Deployment
cp -r force-app force-app-backup-$(date +%Y%m%d) && \
sfdx force:source:deploy -p force-app
Example 4: Count Your Apex Classes
ls force-app/main/default/classes/*.cls | wc -l
Common Mistakes to Avoid ❌
1. Using rm -rf Without Checking
Always verify your location with pwd before deleting:
pwd # Check you're in the right place
ls # Confirm what will be deleted
rm -rf temp/ # Then delete
2. Forgetting Hidden Files
Files like .sfdx, .gitignore, and .forceignore are crucial but hidden. Always use ls -a to see them in your Salesforce DX project root.
3. Not Using Tab Completion
Press Tab while typing folder/file names to autocomplete and avoid typos:
cd for<Tab> # Autocompletes to force-app/
4. Ignoring Command History
Use the up/down arrows to cycle through previous commands. Use history to see all past commands.
history | grep "sfdx" # Find all sfdx commands you've run
Advanced Tips for Power Users ⚡
Create Aliases for Common Commands
Add these to your ~/.bash_profile or ~/.zshrc to speed up your Salesforce CLI work:
alias ll='ls -lah'
alias gs='git status'
alias sf='sfdx force:'
alias sfpush='sfdx force:source:push'
alias sfpull='sfdx force:source:pull'
Reload with:
source ~/.bash_profile
Use Wildcards Efficiently
*.cls # All Apex classes
Account* # All files starting with Account
*Test.cls # All test classes
Redirect Output to Files
sfdx force:apex:test:run > test-results.txt # Save output
grep "ERROR" logs/*.log >> errors.txt # Append errors
Practice Exercise: Build a Salesforce Project 🎯
Try this complete workflow to practice Unix commands with Salesforce DX:
# 1. Create project structure
mkdir salesforce-demo && cd salesforce-demo
sfdx force:project:create -n my-app
# 2. Navigate to project
cd my-app
# 3. Authorize org
sfdx auth:web:login -a DevOrg
# 4. Create Apex class
mkdir -p force-app/main/default/classes
touch force-app/main/default/classes/AccountController.cls
# 5. Open in VS Code
code .
# 6. After coding, push to org
sfdx force:source:push
# 7. Run tests
sfdx force:apex:test:run --resultformat human
Related Resources
Last updated: November 2025 | Tags: Salesforce, Unix Commands, SFDX, Salesforce Developer, Command Line, CLI, DevOps, Productivity
✍️ by @sk
From coding to calculating, this SDE's passion spans finance, geopolitics, and article writing. With a sweet tooth for rasmalai and khurchan peda, they find balance through spirituality.
Comments
Post a Comment