Linux
Overview
- Two main flavors in use - Debian-based (Ubuntu, Debian, Mint, etc) & RHEL-based (Red Hat, CentOS, Fedora etc)
- Debian uses apt-get to install packages whereas RHEL uses yum
- For Debian,
apt-get update,apt-get upgradeandapt-get install <app>are all that’s needed - /etc/network/interfaces used for permanent interface modification in Debian distros
- /etc/resolvconf/resolv.conf.d/ stores files for generating resolv.conf file in Debian distros, which determines DNS resolution
- To restart Debian networking after making changes, use
sudo systemctl restart networking
- Bash script files start with
#!/bin/bash, called a shebang which points to the location of the bash interpreter- Similarly, Python scripts would have a shebang of
#!/usr/bin/env python3
- Similarly, Python scripts would have a shebang of
Environment Variables
- Dynamic variables stored in the system and used by the shell and its applications
- .env extension files typically used to store variables, like below:
#.env file
# IP Address
export HOST="192.168.1.10"exportis used to set environment variables, andsetis used to view them- By storing credentials in environment variables and not including these variables in your git repo, you can prevent accidentally pushing credentials to git in a script
Linux Filesystem
- /bin - contains binaries, applications and programs such as ‘ls’
- /boot - system boot files - do not modify
- /dev - device files such as USB drives, webcams etc
- /etc - mostly contains configuration files
- /home - user personal directories
- /lib - contains libraries, kernel modules, drivers
- /media - mount point for external storage
- /mnt - mostly legacy, for manually mounting storage partitions
- /opt - compiled software lives here
- /proc - contains files for the core operating system
- /root - superuser home directory
- /sbin - like bin but for programs only superusers can run
- /usr - original home directory, now used for applications, documents, libraries and other files
- /srv - configuration files for Linux servers
- /sys - similar to /proc and /dev, contains information about connected devices
- /tmp - temporary files
- /var - mostly log files
Vi
- Ctrl-f - Page down or ‘forward’
- Ctrl-b - Page up or ‘back’
- :q! to exit without making changes, :wq to write and exit
- Press ‘i’ to enter insert mode
Useful Commands
ls, cd, pwd, mkdir, rmdir, rm, cp, mv, uptime- Basic commandscd ~will bring you to your home directory,cd /for the root directoryfind <directory> -name <name>can be used to find files, accepts wildcardsgrepcan be used for searching within fileslesscan be used to view fileschmod- Used for modifying file permissionsechowill print a command to the terminal with stdout, can be redirected to a file with>readcan take user input from the shell, stdinhtop, ps aux- Different commands for displaying system processes, can usekill <pid>to stop processdf -h- Shows disk usage for each mounted filesystemfree -h- Displays memory usageroute- Displays route tableifconfig- Displays interfaces & IP addresseshistory- Displays past commands used - can also use CTRL+R to search historyset- Displays shell and environment variablesexport- Set an environment variablevi ~/.bashrc,source ~/.bashrccan be used to modify aliases -aliaswill show all existing aliases