Linux Commands Reference
60+ essential Linux commands with examples. Every command works in our free browser-based Linux sandbox โ click Open sim โ to try them right now.
๐ง Try any command live in LinuxSim๐ Navigation
pwd
print working directoryShows the full path of the directory you're currently in. Usually the first thing you type when you're lost.
pwd
/home/student
cd
change directoryMove into another directory. cd with no argument takes you home. cd .. moves up one level. cd - toggles between the previous two directories.
cd /etc # absolute path
cd Documents # relative path
cd .. # up one level
cd ~ # home directory
cd - # previous directory
ls
list directory contentsShows the files and folders in a directory. -l gives the long format with permissions, owner, size, and modified time. -a includes hidden files (those starting with a dot). -h makes sizes human-readable.
ls # simple list
ls -l # long format
ls -la # long + hidden
ls -lh /var/log # human-readable sizes
tree
recursive visual listingShows a directory's contents as an indented tree. Great for getting oriented in a new project.
tree /home/student
๐ File Operations
touch
create empty file or update mtimeCreates an empty file if it doesn't exist. If it does exist, it updates the file's modified time to right now. Common use: quickly make a new file without opening an editor.
touch hello.txt
touch a.txt b.txt c.txt
mkdir
create directoryMakes a new directory. Use -p to create a whole nested path at once (no error if parts already exist).
mkdir notes
mkdir -p project/src/lib
rm
remove files or directoriesDeletes a file. Use -r to delete a directory and everything inside it. Use -f to skip the "are you sure" prompt. There is no trash bin in Linux โ rm is permanent. Be careful.
rm old.txt
rm -r my_folder
rm -rf /tmp/scratch # dangerous, irreversible
mv
move or renameRenames a file or moves it to a new location. Same command for both โ if the destination is a directory, it's a move; if it's a new name, it's a rename.
mv old.txt new.txt # rename
mv report.pdf ~/Documents/ # move
mv *.jpg ~/Pictures/ # move multiple
cp
copy files or directoriesCopies a file. Use -r to copy a directory recursively. Use -p to preserve permissions and timestamps.
cp original.txt backup.txt
cp -r project project-backup
cat
print file contentsDumps the entire contents of a file to the terminal. Short for "concatenate" because it can combine multiple files. For long files, use less instead.
cat /etc/os-release
cat file1.txt file2.txt > combined.txt
less
view file one page at a timeOpens a file in a pager you can scroll through. Space = next page, q = quit, / = search, n = next match. Better than cat for files longer than one screen.
less /var/log/syslog
head
first lines of a fileShows the first 10 lines of a file by default. -n 20 shows 20 lines.
head /etc/passwd
head -n 5 access.log
tail
last lines of a fileShows the last 10 lines. -f follows the file as new lines are appended โ essential for watching log files in real time.
tail /var/log/syslog
tail -f /var/log/nginx/access.log
wc
word countCounts lines, words, and characters in a file. -l just lines, -w just words, -c just characters.
wc book.txt
wc -l /etc/passwd # count users
๐ Searching
grep
search for pattern in fileThe essential text search tool. Finds lines containing a pattern. -i ignores case, -r searches recursively in directories, -n shows line numbers.
grep "error" /var/log/syslog
grep -i "TODO" *.js
grep -rn "deprecated" src/
find
search for files by name or propertyLocates files anywhere in a directory tree. More powerful than ls because you can filter by size, type, permissions, date modified, and more.
find /home -name "*.txt"
find . -type d -name "src"
find /tmp -size +10M
find . -mtime -1 # modified in last day
which
locate a command's binaryShows the full path of an executable. Useful for checking which version of a tool you're actually running.
which python3
/usr/bin/python3
๐ Permissions
chmod
change file permissionsSets file permissions using octal numbers (read=4, write=2, execute=1) for owner, group, and others. 755 means owner full, group & others read+execute. 644 is the usual permission for files. +x makes a script executable.
chmod 755 script.sh # rwxr-xr-x
chmod 644 document.txt # rw-r--r--
chmod +x run.sh # add execute
chown
change file ownerChanges who owns a file. Usually requires root. Format: chown user:group file.
sudo chown alice:alice report.txt
sudo chown -R www-data /var/www
โ๏ธ Processes & System
ps
list processesShows running processes. ps aux shows all processes for all users with detailed info.
ps
ps aux
ps aux | grep firefox
top
interactive process viewerReal-time view of running processes sorted by CPU usage. Press q to quit. htop is a friendlier alternative on systems that have it.
top
kill
send signal to a processTerminates a process by PID. kill -9 is the "force" kill (SIGKILL) for processes that won't respond to normal termination. Get the PID from ps or top.
kill 1234
kill -9 1234 # force kill
df
show disk space usageShows free and used space on each mounted filesystem. -h for human-readable sizes.
df -h
du
disk usage of files/foldersShows how much space a file or directory takes. -s for a summary total, -h for human-readable.
du -sh /var/log
du -sh * # size of each item in cwd
free
show memory usageReports free and used RAM and swap. -h for human-readable units.
free -h
uname
system infoPrints the kernel name and version. -a shows everything (kernel, hostname, release, architecture).
uname -a
whoami
print current usernameShows which user you're logged in as. Useful in scripts and when you're not sure which account you sudo'd into.
whoami
student
uptime
how long the system has been runningShows current time, how long the system has been up, how many users are logged in, and the load average.
uptime
๐ Network
ping
test network connectivitySends echo requests to a host to see if it's reachable and how fast the round trip is. Press Ctrl+C to stop.
ping google.com
ping -c 4 1.1.1.1 # 4 packets then stop
curl
transfer data over HTTP/HTTPSThe universal tool for making HTTP requests from the command line. Fetch a URL, post JSON, send headers, download files โ curl does it all.
curl https://api.github.com
curl -X POST -d '{"a":1}' https://example.com/api
curl -o file.zip https://example.com/file.zip
wget
download filesSimpler than curl for downloading files. Auto-saves to the current directory.
wget https://example.com/big-file.zip
ssh
secure shell to remote hostLogs into a remote machine over an encrypted connection. Also used to run a single command remotely. Uses key-based auth by default.
ssh [email protected]
ssh user@host "uptime"
ifconfig / ip
network interface infoifconfig is the classic way to see your IP address and network interfaces. On newer systems, ip addr replaces it.
ifconfig
ip addr
ip route # routing table
โ๏ธ Text Processing
echo
print textPrints its arguments to the terminal. Used constantly in scripts to display messages and to write text into files via redirection.
echo "hello"
echo "hello" > greeting.txt
echo $HOME # expand a variable
sort
sort lines of textSorts input alphabetically by default. -n for numeric, -r for reverse, -u for unique.
sort names.txt
sort -nr scores.txt
uniq
remove adjacent duplicate linesRemoves duplicate lines โ but only if they're adjacent. Usually piped after sort. -c prefixes each line with its count.
sort names.txt | uniq
sort names.txt | uniq -c
๐ Shell & Help
history
show command historyLists every command you've run in the current shell. Combine with grep to find old commands, or press up-arrow to cycle through them one at a time.
history
history | grep ssh
clear
clear the terminal screenWipes the terminal. Ctrl+L does the same thing on most shells.
man
manual pagesThe built-in documentation for every command. When you don't know what a command does, man <command> is almost always the right place to start.
man grep
man ls
alias
create command shortcutsCreates a nickname for a longer command. Add to ~/.bashrc to make it permanent.
alias ll='ls -la'
alias ..='cd ..'
๐ฆ Package Management
apt / apt-get
Debian/Ubuntu package managerInstalls, updates, and removes software on Ubuntu, Debian, Linux Mint, Pop!_OS, and any Debian-derived distro. Requires sudo.
sudo apt update # refresh package list
sudo apt install htop # install
sudo apt upgrade # upgrade all
sudo apt remove firefox # uninstall
Try everything live
Every command on this page works in LinuxSim โ a free browser-based Linux desktop simulator. No installation, no risk, nothing to break. Open a terminal and start typing.
๐ง Open LinuxSim nowWant to learn Linux the proper way? Check out the Linux Essentials course at Apex Online Academy โ 22 modules, 66 lessons, structured labs, AI tutor built in.