Linux OS Notes - robbiehume/CS-Notes GitHub Wiki

Things to look into

sudo / root

  • To allow sudo access to aliases:
    • Run sudo visudo and add Defaults env_keep += "alias" to the file

.bashrc / .bash_profile

  • Aliases can have commands in them: alias greet="echo Hello, $(whoami)!"

How programs get run

Processes & Jobs

Processes

Jobs

  • Jobs have three possible states in Linux: foreground, background, and stopped

Directory Structure

  • Common Directories Explained
  • FHS (Filesystem Hierarchy Standard)
  • /bin: essential user binaries (programs); important system programs and utilities
    • /usr/bin: non-essential command binaries
  • /sbin: similar to /bin; contains essential binaries generally intended to be run by root for sysadmin stuff
    • /usr/sbin: non-essential system administration binaries
  • /lib: libraries essential for binaries in /bin and /sbin
  • /etc: contains system-wide configuration files
  • /opt: contains subdirectories for optional software packages
    • Commonly used by proprietary software that doesn't obey the standard file system hierarchy
  • /proc: contains special files that represent system / kernel and process information
  • /tmp: used by applications to store temporary files. The files are generally deleted whenever the system is restarted
  • /usr: contains apps and files used by users, as opposed to by the system
    • Holds things that are read-only in normal operation
  • /usr/local: where locally compiled apps install to by default
  • /var: contains variable files, i.e. files whose content is expected to continually change during normal operation of the system, such as logs and temporary e-mail files
    • /var/log/messages: a log file used to store a variety of system messages and information

systemd, systemctl, and service

Commands

  • See all services: sudo systemctl -t service

systemctl

  • using systemctl to manage systems services
  • Syntax: sudo systemctl <command> <application>
  • Service application actions
    • Status: sudo systemctl status <application>; Starting: sudo systemctl start <application>; Stopping: sudo systemctl stop <application>; Restart: sudo systemctl restart <application>
    • Start on boot: sudo systemctl enable <application>
      • Remove from start on boot: sudo systemctl disable <application>
      • Can add --now with enable / disable to also start / stop the service
    • Reload: sudo systemctl reload <application>
    • Reload config w/o restarting if possible, if not then restart: sudo systemctl reload-or-restart <application>
      • Some services don't support reload, so this is a good command if you're not sure if it does or doesn't

service

  • Can do similar commands as systemctl^ (start, stop, restart, try-restart, reload, force-reload, status)
  • Syntax: sudo service <application> <command>

systemd

File Descriptors, Redirects (>, <) and pipes (|)

File descriptors

  • fd 0: standard input (stdin); (<)
    • Purpose: represents input to a program, typically from the keyboard
    • Default stream: reads from the keyboard or any input source
    • Redirection: you can redirect input from a file or another command to the standard input of a program
      • Example: command < inputfile
        • This runs command and provides the contents of inputfile as input instead of typing from the keyboard
  • fd 1: standard output (stdout); (>)
    • Purpose: represents normal output from a program, typically from displayed on the terminal
    • Default stream: reads from the keyboard or any input source
    • Redirection: you can redirect the standard output to a file or another output stream
      • Example: command > outputfile
        • This writes the standard output ofcommand to outputfile, overwriting the file's contents if it exists
  • fd 2: standard error (stderr); (2>)
    • Purpose: represents error messages from a program
    • Default stream: writes errors to the terminal
    • Redirection: you can redirect error messages to a file, another command, or /dev/null to suppress them
      • Example: command 2> errorfile
        • This writes error messages to errorfile
  • fd 3 and beyond: custom file descriptors

Redirects:

  • Redirect both stout and stderr to a file: ls /nonexistent > all_output.txt 2>&1

logrotate

Crons

Hard Links vs. Symbolic (Soft) Links

  • Hard Links: Still useful for specific tasks such as backup, file deduplication, atomic updates, and version control
  • Symbolic Links: More versatile, can cross filesystems, link to directories, and are generally used for convenience and flexibility
Feature Hard Links Symbolic Links
Points To The actual data on disk (the inode) The file path (a reference to another file or directory)
Effect on Deletion Original file and hard link are indistinguishable; deleting one does not remove the data until all hard links are deleted Deleting the original file breaks the link; the symbolic link becomes a "dangling" or "broken" link
Cross-Filesystem Support Cannot span across different filesystems (must be on the same partition) Can span across different filesystems (since it points to a path)
Directory Linking Cannot link to directories (except with special permissions) Can link to directories, files, or even other symbolic links
Performance Slightly faster access because no path resolution is needed Slightly slower due to the need for path resolution
Use Cases Backup, version control, deduplication, saving space Shortcuts, references across filesystems, convenience
⚠️ **GitHub.com Fallback** ⚠️