--- title: The basics of Linux description: Simple examples showing you around Linux published: true date: 2023-06-27T07:54:18.672Z tags: linux, server editor: markdown dateCreated: 2023-06-27T07:54:18.672Z --- # Linux Basics This guide provides a brief introduction to Linux, including basic commands and concepts. ## Navigating the filesystem - Change a directory: `cd ` - List files in a directory: `ls` - List files in a directory (including hidden files): `ls -a` - Getting the current directory: `pwd` - Going back a directory: `cd ..` ## Managing Files and Directories - Create a new directory: `mkdir ` - Create a new file: `touch ` - Copy a file: `cp ` - Remove a file: `rm ` - Remove a directory: `rm -r ` ## File Permissions - Change file permissions: `chmod ` - Change file ownership: `chown ` - Change file ownership (recursively): `chown -R ` - View file permissions: `ls -l ` ## Text Processing - View a file: `cat ` - View a file (with line numbers): `cat -n ` - Get the beginning of a file: `head ` - Get the end of a file: `tail ` ## Package Management (Ubuntu) - Update package lists: `sudo apt update` - Install a package: `sudo apt install ` - Purge a package: `sudo apt purge ` - Remove a package: `sudo apt remove ` - Search for a package: `apt search ` - Upgrade packages: `sudo apt upgrade` ## File Compression and Archiving - Create a tar archive: `tar -cvf ` - Extract a tar archive: `tar -xvf ` - Create a zip archive: `zip ` - Extract a zip archive: `unzip ` ## Networking - Get all interface ips: `ip a` - Ping a host: `ping ` - Get the public IP: `curl ifconfig.me` - Get the public IP (alternative): `curl ipinfo.io/ip` ## Firewall (UFW) Make sure to allow SSH before enabling the firewall, otherwise you will be locked out of your server. `sudo ufw allow ssh` - Enable the firewall: `sudo ufw enable` - Disable the firewall: `sudo ufw disable` - List all rules: `sudo ufw status` - List all rules (showing numbers): `sudo ufw status numbered` - Delete a rule: `sudo ufw delete ` - Allow a port: `sudo ufw allow ` - Deny a port: `sudo ufw deny ` - Allow a service: `sudo ufw allow ` - Deny a service: `sudo ufw deny `