Linux Fundamentals

Master the command line through interactive tutorials

Introduction to Linux

Welcome to the world of Linux! Linux is a powerful, open-source operating system that forms the backbone of the internet, servers, and even Android smartphones.

In this tutorial, you'll learn the fundamentals of navigating and working with Linux through the command line interface (CLI). The CLI might seem intimidating at first, but it's actually a very efficient way to interact with your system.

Linux File System Hierarchy

/
├── bin
├── etc
├── home
│ └── learner
│ ├── documents
│ ├── scripts
│ └── readme.txt
├── usr
└── var
What is the root directory in Linux?
  • /
  • /root
  • /home
  • C:\\

Understanding the Linux File System

Linux organizes all files in a hierarchical directory structure, starting from the root directory (/). This structure is defined by the Filesystem Hierarchy Standard (FHS).

Key Directories:

  • /bin - Essential command binaries (ls, cp, mv)
  • /etc - System configuration files
  • /home - User home directories
  • /usr - User programs and libraries
  • /var - Variable data like logs
  • /tmp - Temporary files
  • /root - Root user's home directory
# Navigate to different directories cd /bin # Go to bin directory cd /etc # Go to etc directory cd ~ # Go to home directory cd .. # Go up one level pwd # Print current location
Which directory contains system configuration files?
  • /bin
  • /etc
  • /home
  • /usr

Essential Linux Commands

Now let's learn the most fundamental commands that you'll use every day in Linux.

1. ls (List)

The ls command lists files and directories in your current location.

ls # List files in current directory ls -l # Long format with permissions ls -la # Include hidden files ls /bin # List specific directory

2. cd (Change Directory)

The cd command moves you between directories.

cd /home # Go to home directory cd documents # Go to documents subdirectory cd .. # Go up one level cd ~ # Go to your home directory cd / # Go to root directory

3. mkdir (Make Directory)

Create new directories with mkdir.

mkdir projects # Create 'projects' directory mkdir -p projects/web # Create nested directories mkdir "my folder" # Create directory with space in name

4. rm (Remove)

Delete files and directories with rm (be careful!).

rm file.txt # Delete a file rm -r directory # Delete directory and contents rm -i file.txt # Interactive deletion (confirm) rm -f file.txt # Force deletion (no confirmation)
Which command creates a new directory?
  • mkdir
  • newdir
  • createdir
  • makedir

File Operations

Learn to work with file contents and search through them efficiently.

1. cat (Concatenate)

Display file contents or combine files.

cat file.txt # Display file contents cat file1.txt file2.txt # Combine and display multiple files cat > newfile.txt # Create new file (type content, then Ctrl+D)

2. grep (Search)

Search for text patterns in files.

grep "error" log.txt # Search for "error" in file grep -i "error" log.txt # Case-insensitive search grep -r "error" /var/log # Search recursively in directory grep -n "error" log.txt # Show line numbers

3. find (Find Files)

Locate files and directories based on various criteria.

find . -name "*.txt" # Find all .txt files find /home -user learner # Find files owned by user find . -mtime -7 # Files modified in last 7 days find . -type d -name "test*" # Find directories starting with "test"

Interactive Demo

$ grep "linux" /etc/hosts
127.0.0.1 localhost linux.local
$ find . -name "*.conf" | head -3
./etc/nginx/nginx.conf
./etc/mysql/my.conf
./etc/ssh/sshd.conf
Which command searches for text in files?
  • grep
  • find
  • search
  • cat

File Permissions and Security

Linux uses a robust permission system to control access to files and directories.

Understanding Permissions

Every file has three types of permissions for three categories of users:

Permission Types:
• Read (r) - View file contents
• Write (w) - Modify file contents
• Execute (x) - Run as program

User Categories:
• User (u) - File owner
• Group (g) - Group members
• Others (o) - Everyone else

Viewing Permissions

ls -l file.txt # Show detailed permissions # Output: -rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt # ^^^^|||______ Permissions: user|group|others

Changing Permissions with chmod

chmod u+x script.sh # Add execute for user chmod g-w file.txt # Remove write for group chmod o=r document.txt # Set others to read-only chmod 755 script.sh # Numeric mode: rwxr-xr-x

Numeric Permission System

Read (r) = 4
Write (w) = 2
Execute (x) = 1

Examples:
7 = rwx (4+2+1)
6 = rw- (4+2)
5 = r-x (4+1)
4 = r-- (4)
0 = --- (0)
What does chmod 644 file.txt do?
  • Sets permissions to rw-r--r--
  • Sets permissions to rwxrwxrwx
  • Sets permissions to rwxr-xr-x
  • Sets permissions to r--------

Process Management

Learn to manage running processes and system resources.

Viewing Processes

ps # Show current processes ps aux # Show all processes ps aux | grep nginx # Find specific processes top # Interactive process viewer htop # Enhanced process viewer (if installed)

Managing Jobs

command & # Run command in background jobs # List background jobs fg %1 # Bring job 1 to foreground bg %1 # Resume job 1 in background Ctrl+Z # Suspend current process

Terminating Processes

kill PID # Terminate process by ID kill -9 PID # Force kill process killall process_name # Kill all processes by name pkill pattern # Kill processes matching pattern

System Information

df -h # Disk space usage free -m # Memory usage uptime # System uptime and load whoami # Current user hostname # System hostname
Which command shows all running processes?
  • ps aux
  • ls -la
  • top
  • jobs

🎉 Congratulations!

You've completed the Linux fundamentals tutorial. Continue practicing with the challenges!

Start Challenges