docs/guides/linux/pages/basics.md

94 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2023-06-27 07:54:20 +00:00
---
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
---
2023-06-27 08:00:08 +00:00
# Linux Basics
This guide provides a brief introduction to Linux, including basic commands and concepts.
## Navigating the filesystem
- Change a directory: `cd <directory>`
- 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 <directory>`
- Create a new file: `touch <file>`
- Copy a file: `cp <file> <new-file>`
- Remove a file: `rm <file>`
- Remove a directory: `rm -r <directory>`
## File Permissions
- Change file permissions: `chmod <permissions> <file>`
- Change file ownership: `chown <user> <file>`
- Change file ownership (recursively): `chown -R <user> <directory>`
- View file permissions: `ls -l <file>`
## Text Processing
2023-06-27 08:07:18 +00:00
There are alternatives to nano, but it is the easiest to use.
- Edit a file: `nano <file>`
2023-06-27 08:00:08 +00:00
- View a file: `cat <file>`
- View a file (with line numbers): `cat -n <file>`
- Get the beginning of a file: `head <file>`
- Get the end of a file: `tail <file>`
2023-06-27 08:08:47 +00:00
## File Compression and Archiving
- Create a tar archive: `tar -cvf <archive.tar> <file>`
- Extract a tar archive: `tar -xvf <archive.tar>`
- Create a zip archive: `zip <archive.zip> <file>`
- Extract a zip archive: `unzip <archive.zip>`
2023-06-27 08:00:08 +00:00
## Package Management (Ubuntu)
- Update package lists: `sudo apt update`
- Install a package: `sudo apt install <package>`
- Purge a package: `sudo apt purge <package>`
- Remove a package: `sudo apt remove <package>`
- Search for a package: `apt search <package>`
- Upgrade packages: `sudo apt upgrade`
2023-06-27 08:05:58 +00:00
## Networking
- Get all interface ips: `ip a`
- Ping a host: `ping <host>`
- 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 <rule>`
- Allow a port: `sudo ufw allow <port>`
- Deny a port: `sudo ufw deny <port>`
- Allow a service: `sudo ufw allow <service>`
- Deny a service: `sudo ufw deny <service>`
2023-06-27 08:10:56 +00:00
## Service Management (Systemd)
- Start a service: `sudo systemctl start <service>`
- Stop a service: `sudo systemctl stop <service>`
- Check the status of a service: `sudo systemctl status <service>`
- Restart a service: `sudo systemctl restart <service>`
- Enable a service (start on boot): `sudo systemctl enable <service>`
- Disable a service (stop on boot): `sudo systemctl disable <service>`
- Reload a service: `sudo systemctl reload <service>`