Skip to main content

The Linux Commandline

The Linux command line (shell) is your primary interface for interacting with a Linux system. This article covers the most commonly used commands to navigate, manage files, and work with processes.

CommandDescription
pwdPrint current working directory
lsList files in the current directory
ls -laList all files including hidden ones with details
cd <dir>Change directory
cd ..Go up one directory level
cd ~Go to home directory

File Management

CommandDescription
touch <file>Create an empty file
mkdir <dir>Create a new directory
cp <src> <dest>Copy a file or directory
mv <src> <dest>Move or rename a file
rm <file>Delete a file
rm -rf <dir>Delete a directory and all its contents

Viewing File Contents

CommandDescription
cat <file>Print entire file content
less <file>Scroll through a file
head -n 10 <file>Show first 10 lines
tail -n 10 <file>Show last 10 lines
tail -f <file>Follow a file in real-time (useful for logs)

Searching

# Search for a string inside files
grep -r "search term" ./

# Find files by name
find . -name "*.log"

# Find files modified in the last 24 hours
find . -mtime -1

Permissions

Every file in Linux has an owner and a set of permissions for the owner, group, and others.

# View permissions
ls -l

# Change permissions (e.g. make a script executable)
chmod +x script.sh

# Change file owner
chown user:group file.txt

Permission notation: rwxr-xr--

  • r = read, w = write, x = execute
  • First 3 characters: owner — next 3: group — last 3: others

Useful Shortcuts

ShortcutDescription
Ctrl + CCancel running command
Ctrl + LClear terminal
TabAutocomplete file/command name
↑ / ↓Navigate command history
!!Repeat last command
sudo !!Repeat last command with sudo