Cheatography
https://cheatography.com
A cheat sheet for SYS ADMIN
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Automated Commands
atq: show which commands you have in the at queue. Also displays job number, job owner, and date of planned execution. |
arm job-num: deletes a job from the queue by specifying job-num. |
at: reads commands to be executed from files or standard input. |
man 5 crontab: view manpage for crontab. |
crontab -e: edit scheduled tasks in the /var/spool/cron/crontabs file |
crontab -l: list schedule tasks |
Bash Scripting
#!/bin/env/bash: the shebang used to at the start of all bash scripts. |
bash file-name.sh: run the bash script in terminal. |
exit [0-225]: exit script and return number from 0-255. |
exit [0]: means everything ran as intended. |
exit[1-255]: these values are used to tell the user some error, different by the number, has occurred |
$0: refers back to the script name |
$#: the number of arguments that have been passed to the script |
&&: AND |
||: OR |
#: Used to make comments throughout the script |
[parameter]: used to denote when parameters are optional in a script |
<parameter>: used to denote when parameters are required in a script |
./ file-name.sh: runs the bash script in terminal if script is set too executable |
System
shutdown now: shutdown the machine |
man command: show manpage for command |
kill: get rid of a command running in the background |
free: display amount of free and used memory |
df: display free disk space |
du: display disk usage stats |
&: puts command into the background |
File Searching Commands
locate file: locates a file |
grep -r pattern dir: recursively searches for pattern in dir |
grep options pattern files: searches through files for a certain pattern, displays all lines containing that pattern |
find: search for a file or directory |
|
|
Bash Functions and Arrays
type -a command: tells the user if the command is an alias |
alias alias='bash-command': how to define an alias |
alias: lists all aliases defined in user's current session |
function() {something}: how to define a function |
shift: move argument $2 to $1 |
array=("some" "strings"): creates an array of strings |
${array[0]}: gets the first index of the array |
${array[*]}: gets all elements of the array |
${array[-1]}: gets the last element in the array |
Basic Usage
pwd: print working directory |
cd: change directory |
mkdir: make directory |
rmdir: remove directory |
rm: deletes files |
ls: list files in a directory |
cat: used to be able to quickly scan a file/directory |
ssh: stands for secure shell, used to securely access the virtual machine |
scp: copies files and moves a copy to the desired location |
add a -r to scp: copies a directory |
sudo: changes the user to root |
adduser: adds a user into the system. |
passwd: allows root to change a user's password |
userdel: deletes the users account |
add a -r to userdel: forces the users home directory to be deleted as well |
chown: changes the owner of a file |
chgrp: changes the group of a file |
chmod: changes permissions |
(add onto chmod) +: adds what permission to change |
(add onto chmod) -: removes a permission |
dnf upgrade: updates system |
System Log Commands
exit: exit from session |
script: record output for session in a file |
!command-num: repeat and run command from history |
history | grep keyword: search for command by keyword in user's history |
history: list previous commands used |
last: display last user login |
dmesg: view kernel messages from the last boot of the machine |
journalctl: view the log of the whole system |
journalctl -u sshd: view only log entries for ssh unit |
who: gives information on who is logged in |
w: gives information on who is logged in |
finger: gives information on who is logged in |
id -u username: get user ID for specific user |
|
|
Bash Syntax
basename path: get the filename from a given path |
cut: cut different parts of a string |
break: can add to while or for loops to exit from the loop, while continuing the rest of the script |
for ((;;)) do ... done: infinite loop |
for counter in {starting-value ... ending-value}; do ... done: brace expansion that iterates over a number range from starting value to ending value |
for ((counter=number; counter <=number; counter++)); do ... done: start the counter at equal to some number, do something then increment that counter by 1 until the counter is greater than or equal to some other number. |
for value in list-of-values; do ... done; iterate over a list of values |
sleep time: wait for a specified number of seconds before continuing through the script |
until condition-is-true; do ... done: opposite of a while loop, does something until the condition is true. |
while condition-is-true; do ... done: does something as long as the condition is true |
if condition; then do ... elif condition; then do ... else do...: If condition is true, so something. Else if this other condition is true and the first is not, do this different thing. Else, if all conditions prior are false, do this thing. |
if fi: basic structure of if statements in bash |
Download Help
wget file-url: download a file |
tar -xzf tar-file: extract a tar file |
Package Management Commands
dnf remove package-name: remove a package from system |
dnf install package-name: install new software packages |
dnf provides package-name: check package name to install |
dnf search package-name: search for new software called package-name |
dnf upgade: update the system and all of its package |
SSH
ssh: gives information about ssh command |
ssh-keygen: generate private/public key pair |
exit: exits the shell |
ssh-keyscan: used for retrieving public keys from servers |
Notable Directories
/: root directory |
/boot: location where the kernel and other files used during booting are stored |
/dev: contains device files, which is the interface between the hardware and the filesystem |
/etc: contains configuration files, can usually be edited by a text editor(nano) |
/home: contains a home folder for each user on system |
/root: home directory for the root user |
/tmp: temporary files stored by apps |
/var: contains administrative files |
/var/spool: temporary storage for files being printed |
|