Beginner's Guide to Linux and macOS Terminal Commands
ChatGPT & Benji AsperheimWed Jul 16th, 2025

Linux OS and macOS Terminal Commands Overview

Understanding the basic command-line tools available in Linux and macOS is a game changer for anyone who wants to take control of their computer or server. Most UNIX-like systems—including Linux distributions and macOS—share a common set of POSIX-compliant commands, but subtle differences can trip up beginners. This section breaks down the core commands you’ll use daily, explains what makes Linux and macOS unique, and highlights the key flags and options that matter most.


🖥️ What Linux Is: Understanding the Basics

What is Linux? Linux is an operating system—just like Windows or macOS—but with some big differences:


Why Does Linux Matter?


How is Linux Different from Windows or macOS?


Common Linux Myths


In short: Linux is a free, open-source operating system that’s used everywhere—from personal laptops to the world’s biggest websites. It’s flexible, secure, and gives you real control over your system. Knowing even a little bit about Linux and its commands will make you more effective on almost any computer you touch.


File & Directory Management

Working with files and directories is at the heart of command-line usage. Whether you’re moving files, creating project folders, or cleaning up clutter, knowing how to use commands like ls, cd, mkdir, cp, and rm—along with their most important options—will make your workflow smoother and faster. This section covers the practical steps to navigate, organize, and manage your files safely on both Linux and macOS systems.

ls — List Files/Directories

Usage:

ls                # List files in current dir
ls -l             # Long (detailed) listing
ls -a             # Include hidden files (start with .)
ls -lh            # Human-readable sizes
ls -la            # Long listing, all files

Difference:


cd — Change Directory

Usage:

cd mydir          # Go into 'mydir'
cd ..             # Go up one level
cd                # Go to your home directory

Difference:


pwd — Print Working Directory

Usage:

pwd               # Show full current path

Difference:


mkdir — Make Directory

Usage:

mkdir mydir                   # Create single directory
mkdir -p parent/child/leaf    # Create nested dirs; parents if needed

Difference:


rm — Remove Files/Directories

Here’s how you can delete or remove a directory (or delete files)—and it works the same in both macOS and Linux:

Usage:

rm file.txt                   # Remove file
rm -i file.txt                # Interactive prompt before delete
rm -r mydir                   # Recursively delete directory
rm -rf mydir                  # Recursive, force delete (dangerous!)

Difference:


cp — Copy Files/Directories

Usage:

cp file1.txt file2.txt        # Copy file
cp -r dir1 dir2               # Copy directories recursively
cp -i file.txt dest/          # Prompt before overwrite

Difference:


mv — Move/Rename Files/Directories

Usage:

mv file.txt newloc/           # Move file to directory
mv oldname.txt newname.txt    # Rename file
mv -i file.txt dest/          # Prompt before overwrite

Difference:


touch — Create/Update File

Usage:

touch newfile.txt             # Create file (if it doesn't exist) or update timestamp

Difference:


File Viewing & Editing

cat, less, more, head, tail

Difference:


Finding Stuff

find

find . -name "*.js"           # Find files named *.js starting here

Difference:


grep

grep "search" file.txt        # Find 'search' in file.txt
grep -r "pattern" .           # Search recursively in dir
grep -i "pattern" file.txt    # Case-insensitive search

Difference:


Permissions

chmod and chown

chmod +x myscript.sh          # Make script executable
chmod 755 mydir               # Set permissions
chown user:group file.txt     # Change ownership

Difference:


Networking

curl and wget


ping


Process Management

ps, top, kill

Difference:


System Info

uname, df, du, free


Opening Files/Apps

Platform-Specific:

xdg-open is not available on macOS, and open is not available on Linux. Know which to use for your OS.


Searching Commands

which, whereis, man


macOS and Linux Differences: Quick Summary

PurposeLinux CommandmacOS Command
Open file/appxdg-openopen
Install pkgapt, yum, etc.brew (Homebrew)
GNU utilsdefaultuse Homebrew (gnu-sed, gnu-tar, etc)
View RAM usagefree -hvm_stat, top
Copy with progresscp -vcp -v (but less info on macOS)
Download filewget, curlcurl (wget needs install)

NOTE: On macOS you can install the Homebrew package manager (brew command) by executing /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" in a terminal session.


Beginner’s Takeaways


💡 PowerShell: Cross-Platform Scripting for Windows, macOS, and Linux

PowerShell is Microsoft’s modern, cross-platform command-line shell and scripting language. Originally exclusive to Windows, PowerShell now works on macOS and Linux as well. This makes it one of the few shells that can be used natively on all three major operating systems with (mostly) the same syntax.


How is PowerShell Different from Bash or Zsh?


Installing PowerShell

brew install --cask powershell    # macOS (Homebrew)
sudo apt install powershell       # Linux (Debian/Ubuntu, if repo available)

Or, download installers from: https://github.com/PowerShell/PowerShell

pwsh

PowerShell Basics for Beginners

Bash/Zsh ExamplePowerShell EquivalentWhat It Does
lsGet-ChildItem or lsList files and directories
cd mydirSet-Location mydir or cdChange directory
cat file.txtGet-Content file.txt or catShow file contents
mv a.txt b.txtRename-Item a.txt b.txtRename a file
cp a.txt b.txtCopy-Item a.txt b.txtCopy a file
rm file.txtRemove-Item file.txtDelete a file
pwdGet-Location or pwdShow current directory

Tip: Common Linux/macOS aliases like ls, cat, pwd, and cd also work in PowerShell for convenience—but the real PowerShell cmdlets are more powerful and scriptable.


Working with Objects vs Text

Get-Process | Where-Object {$_.CPU -gt 100}

Useful PowerShell Tips

Get-Help Get-Process
./myscript.ps1

On non-Windows systems, you may need to set the script as executable or set execution policy.


When is PowerShell Worth Using on macOS/Linux?

For basic day-to-day shell work, Bash/Zsh is simpler on macOS/Linux, but PowerShell’s object-based approach is unmatched for automation and data manipulation across OSes.


Summary: PowerShell is no longer just for Windows admins. If you work across OSes, learn the basics—it can save hours on cross-platform scripting and automation.


Linux Time Converter: How to Work with Dates and Times in the Terminal

Dealing with timestamps and converting time formats is a common challenge on Linux systems. Whether you need to convert a Unix timestamp to a readable date, change time zones, or format a date for scripting, the Linux terminal gives you flexible tools for all your “Linux time converter” needs. Here’s what beginners need to know.


What Is a Linux Time Converter?

A “Linux time converter” usually refers to using built-in command-line tools to convert between different time representations—like Unix timestamps, human-readable dates, and different time zones—without any third-party software.


Linux Time Converter

date -d @1689556789        # Linux
date -r 1689556789         # macOS / BSD

Converting Time in Scripts


Summary

If you ever need to convert or format dates and times on Linux (or macOS), learn the date command—it’s your built-in “linux time converter.” With just a few flags, you can handle timestamps, time zones, and custom formats right from the terminal, making scripting and log analysis much easier.


🔒 Users, Permissions, and “Why Can’t I Do That?”

Who Am I? Who’s Allowed to Do What?

whoami — Shows your current user.

whoami

Output will be your username. This matters, because the permissions system decides what you can do, based on who you are.


Users, Groups, and Root

To become root (just for one command), use sudo:

sudo <command>

E.g. sudo rm /var/log/somefile


When Do You Need sudo?


Understanding File Permissions: ls -l Output

ls -l myfile.txt
-rw-r--r--  1 jane  staff  0 Jul 16 09:15 myfile.txt

Breakdown:

Permissions split into three: [owner][group][others]

So:


Changing Permissions: Octal vs rwx Notation

Tip:


Changing File Ownership

sudo chown root:wheel /usr/local/bin/myprog

Usually, you need sudo to change ownership, and almost never do this unless you know why.


Checking Who Owns a File and What Permissions It Has

ls -l /etc/hosts

You’ll usually see root as owner for system files.


Common Permission Errors:

ErrorCauseFix
Permission deniedNot enough rights to read/write/runUse sudo, or fix permissions/ownership
Operation not permittedEven sudo can’t do it (immutable file, SIP on macOS)Special case—don’t mess unless you really know
Command not foundFile is not executable, or not in $PATHchmod +x file, or specify path (./myscript.sh)

Key Beginner Rules:

Summary: Files and folders have owners and permission sets. System files are “root-owned” and need sudo. Learn to read ls -l and understand chmod. When in doubt, check with ls -l and ask yourself if you really need more permissions, or if you’re working in the wrong place.


UNIX/Linux/macOS Terminal Cheat Sheet

Here’s a no-BS, practical Linux/macOS command-line cheat sheet with real copy-paste examples and notes on common gotchas. You’ll see which options matter, which to skip, and what breaks between macOS and Linux:

Directory & File Basics

PurposeCommand & ExampleNotes / Differences
List filesls -la-l (long), -a (all incl. hidden)
Change dircd /path/to/dircd ~ for home
Make dirmkdir -p foo/bar/baz-p = parents (ALWAYS use for nesting)
Remove filerm file.txtNo trash/recycle, it’s gone
Remove dirrm -rf mydir-r=recursive, -f=force
Copy filecp file1.txt backup.txtOverwrites without warning
Copy dircp -r sourcedir/ destdir/-r = recursive
Move/renamemv old.txt new.txtAlso moves files between dirs
Touch filetouch file.txtNew or update timestamp
Show pwdpwdShows absolute path

File Viewing/Editing

CommandExample(s)Notes
Show all file contentcat file.txtCareful with big files!
View + scrollless file.txtq to quit, /search to search
Head/tailhead -n 20 file.txt
tail -f logfile
-f follows updates
Edit (basic CLI)nano file.txtWorks everywhere, easier than vi
Edit (macOS GUI)open -e file.txtOpens TextEdit on macOS only
Edit (Linux GUI)xdg-open file.txtOpens default editor

Searching & Finding in Linux or macOS

CommandExampleNotes
Find filesfind . -name "*.js"Current dir down, match pattern
Search insidegrep -i "error" file.txt-i = case-insensitive
Search recur.grep -r "TODO" .Recursively in all files

POSIX Permissions & Ownership

CommandExampleNotes
Make executablechmod +x script.shNeeded to run as ./script.sh
Set permissionschmod 644 file.txtRead/write owner, read others
Change ownersudo chown $USER:staff file.txtUse sudo if not your file

Disk & System Info

CommandExampleNotes
Disk usagedu -sh *Dir/file sizes, human readable
Disk free spacedf -hHuman readable
Show RAMfree -h (Linux)
vm_stat (macOS)
macOS: vm_stat output is weird, search for “Pages free”
System infouname -aKernel and arch

Processes & Management

CommandExampleNotes
List all procsps auxAll user/system processes
Real-time toptopUse htop if installed
Kill processkill 12345By PID
Force killkill -9 12345Use if regular kill fails

Networking

CommandExampleNotes
Ping hostping -c 4 google.commacOS default is 1, Linux is infinite
Download filecurl -O http://example.com/file.zipwget not default on macOS
Check open ports`netstat -angrep LISTEN`

Open Files & Apps in Linux and macOS

OSCommandExampleNotes
macOSopenopen file.pdf or open .Opens in default app/Finder
Linuxxdg-openxdg-open file.pdfOpens in default app/file mgr

Installing Packages and Programs in a Terminal

Here’s a general guide to installing packages on various Linux distros, or on macOS using Homebrew:

OSCommandExampleNotes
Debian/Ubuntusudo apt update && sudo apt install treesudo apt install treeUses APT package manager
Fedora/RHELsudo dnf install treesudo dnf install treeUses DNF package manager (Fedora 22+), YUM (Fedora 21-)
Arch Linuxsudo pacman -S treesudo pacman -S treeUses Pacman package manager
Alpine Linuxsudo apk add treesudo apk add treeUses APK package manager
Red Hatsudo yum install tree (RHEL 7 and earlier) or sudo dnf install tree (RHEL 8 and later)sudo yum install treeUses YUM (RHEL 7 and earlier), DNF (RHEL 8 and later)
macOS/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" and brew install treeInstall Homebrew, then installNative macOS pkg mgmt is limited; use Homebrew

NOTE: Some Linux distros may have different package managers or installation commands.

This table covers some of the most popular package managers in Linux:

Keep in mind that this is not an exhaustive list, and you may need to check the documentation for your specific Linux distro to find the correct installation command.


Other Useful Commands

CommandExampleNotes
Path of a cmdwhich pythonFull path to binary
Manual pageman grepRead docs in terminal
Show env varsprintenv or envAll your env vars
Previous cmdUp arrow / !!Run last command
AutocompleteTab keyComplete file/dir names

Scripting Portability Tips


This cheat sheet is enough to cover 99% of daily tasks for anyone new or casual with a Linux or macOS terminal.


Conclusion

Mastering the basics of the terminal is one of the fastest ways to become more productive—and less frustrated—on any Unix-based system. By understanding file permissions, user roles, and the subtle differences between Linux and macOS command-line tools, you avoid permission errors, protect your system, and save serious time. Refer back to the cheat sheet when in doubt. Remember: don’t use sudo unless you know exactly why, and what its effects are. If you’re ever stuck, run man <command> or search the official docs. The command line isn’t just for power users—it’s for anyone who wants to actually control their computer.