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

pwd

print working directory

Shows 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 directory

Move 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 contents

Shows 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 listing

Shows 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 mtime

Creates 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 directory

Makes 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 directories

Deletes 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 rename

Renames 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 directories

Copies 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 contents

Dumps 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 time

Opens 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

tail

last lines of a file

Shows 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 count

Counts 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 file

The 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 property

Locates 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 binary

Shows 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 permissions

Sets 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 owner

Changes 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 processes

Shows running processes. ps aux shows all processes for all users with detailed info.

ps
ps aux
ps aux | grep firefox

top

interactive process viewer

Real-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 process

Terminates 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 usage

Shows free and used space on each mounted filesystem. -h for human-readable sizes.

df -h

du

disk usage of files/folders

Shows 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 usage

Reports free and used RAM and swap. -h for human-readable units.

free -h

uname

system info

Prints the kernel name and version. -a shows everything (kernel, hostname, release, architecture).

uname -a

whoami

print current username

Shows 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 running

Shows current time, how long the system has been up, how many users are logged in, and the load average.

uptime

๐ŸŒ Network

ping

test network connectivity

Sends 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/HTTPS

The 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 files

Simpler than curl for downloading files. Auto-saves to the current directory.

wget https://example.com/big-file.zip

ssh

secure shell to remote host

Logs 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 info

ifconfig 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 text

Prints 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 text

Sorts input alphabetically by default. -n for numeric, -r for reverse, -u for unique.

sort names.txt
sort -nr scores.txt

uniq

remove adjacent duplicate lines

Removes 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 history

Lists 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 screen

Wipes the terminal. Ctrl+L does the same thing on most shells.

man

manual pages

The 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 shortcuts

Creates 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 manager

Installs, 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 now

Want 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.