Linux OS Notes - robbiehume/CS-Notes GitHub Wiki
- systemctl: using systemctl to manage systems services
- systemd:
- puppet / facter
- To allow
sudo
access to aliases:- Run
sudo visudo
and addDefaults env_keep += "alias"
to the file
- Run
- Aliases can have commands in them:
alias greet="echo Hello, $(whoami)!"
- https://unix.stackexchange.com/questions/268766/what-exactly-happens-when-i-execute-a-file-in-my-shell
- How a Unix / Linux shell script is executed
- Linux processes overview (with good diagrams)
- Commands:
-
ps aux
: see list of all running processes -
jobs
: see list of current jobs
-
- Jobs have three possible states in Linux: foreground, background, and stopped
- 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
-
- systemctl vs service command
- systemd service unit configuration
- systemd service execution environment config
- systemd unit configuration files (drop-in directory)
-
See all services:
sudo systemctl -t service
- 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
withenable
/disable
to also start / stop the service
-
Remove from start on boot:
- 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
-
Status:
- Can do similar commands as
systemctl
^ (start, stop, restart, try-restart, reload, force-reload, status) - Syntax:
sudo service <application> <command>
- systemd essentials
- understanding systems units and unit files (more recently updated)
- systemd service unit files
- The .service file goes in
/etc/systemd/system/<service_name>.service
- Enable on startup:
sudo systemctl enable <service_name>
- Environment variables for service: look at sample_systemd.service
- Run script before starting:
ExecStartPre
; link
-
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 ofinputfile
as input instead of typing from the keyboard
- This runs
-
Example:
-
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 of
command
tooutputfile
, overwriting the file's contents if it exists
- This writes the standard output of
-
Example:
-
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
- This writes error messages to
-
Example:
-
fd
3
and beyond: custom file descriptors
- Redirect both
stout
andstderr
to a file:ls /nonexistent > all_output.txt 2>&1
- Should use copytruncate instead of (or with?) create so that the programs writing to the file don't potentially get thrown off with a file descriptor change
- https://www.digitalocean.com/community/tutorials/how-to-manage-logfiles-with-logrotate-on-ubuntu-20-04
- For a sample file look at: /misc/sample_logrotate
- The file goes in /etc/logrotate.d and need to set permissions to 644
- 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 |