|
bash filename - Runs script
|
|
Shebang - "#!bin/bash" - First line of bash script. Tells script what binary to use
|
|
./filename - Also runs script
|
|
# - Creates a comment
|
|
echo ${variable} - Prints variable
|
|
hello_int = 1 - Treats "1" as a string
|
|
Use UPPERCASE for constant variables
|
|
Use lowercase_with_underscores for regular variables
|
|
echo $(( ${hello_int} + 1 )) - Treats hello_int as an integer and prints 2
|
|
mktemp - Creates temporary random file
|
|
test - Denoted by "[[ condition ]]" tests the condition
|
|
bash -x - Prints commands and their arguments
|
|
ps -f - Copies the current shell in the fork
|
|
exit value - Exits the script with value exit code
|
|
-n variable - decides if variable is not empty
|
|
-z variable - Decides if variable is empty
|
|
$? - Stands for the previous exit code
|
|
$# - Stands for the number of arguments passed
|
|
[[ $# -ne 2 ]] - Evaluates to true if the number of arguments is not equal to 2
|
|
-f filename - Determines if filename is a file
|
|
-d directoryName - Determines if directoryName is a directory
|
|
$1, $2, $3 - Refers to the first, second, and third arguments
|
|
-eq - means ==
|
|
-lt - Means <
|
|
-le - Means <=
|
|
-gt - Means >
|
|
-ge - Means >=
|
|
dirname - Prints directory name of of argument
|
|
sleep value - Forces the script to wait value seconds
|
|
while [[ condition ]]; do stuff; done
|
|
if [[ condition ]]; do stuff; fi
|
|
until [[ condition ]]; do stuff; done
|
|
words="house dogs telephone dog" - Declares words array
|
|
for word in ${words} - traverses each element in array
|
|
for counter in {1..10} - Loops 10 times
|
|
for ((;;)) - Is infinite for loop
|
|
break - exits loop body
|
|
for ((counter=1; counter -le 10; counter++)) - Loops 10 times
|
|
${array[I]} - Indexes array
|
|
${array[]} - References the whole array. Can also use @*
|
|
declare -A array - declares associative array
|
|
myassocarray=([apple]="red" [banana]="yellow") - Creates associative array
|
|
${myassocarray[banana]} - References bananas value in the array
|
|
unset array[I] - Deletes the I index
|
|
unset array - Deletes the array
|
|
${#array} - Outputs the length of the array
|
|
alias ll = 'ls -l' - Creates the ll command as an alias
|
|
home() { do stuff ; } Creates the home function
|
|
return - defaults to the previous exit value
|
|
local - Creates local variable within function
|
|
cut - Cuts away parts of the output
|
|
git clone <url> - Clones gitkeeper url
|
|
git add <filename> - Adds the file to git
|
|
git commit - Commits all files to git
|
|
git push - Pushes all git files to host
|
|
dnf upgrade - Updates system packages
|
|
dnf install - Installs package
|
|
dnf search - Searches for package
|
|
dnf remove - Removes package
|
|
systemctl start - Starts systemd service
|
|
systemctl stop - Stops systemd service
|
|
systemctl restart - Restarts systemd service
|
|
systemctl reload - Reloads systemd service configuration files
|
|
systemctl enable - Enable systemd service at boot
|
|
systemctl disable - Disable systemd service
|
|
systemctl status - Displays activity state and some log lines of service
|
|
atq - Displays currently scheduled commands
|
|
at - Runs command once at certain time/day
|
|
atrm - Remove scheduled commands
|
|
crontab -e - Create a file for scheduled commands to run
|
|
journalctl - Shows logs
|
|
dmesg - Shows kernel messages, hardware, driver, etc.
|
|
history - Shows previous commands
|
|
script - Records all input and writes it to a file
|
|
route - Configures IP connection
|
|
hostname - Sets system host name
|
|
netstat -rn - Gives routing table
|
|
ifconfig - Outputs network interface
|
|
ip addr - Shows different addresses and internet connections
|
|
traceroute -I - Gives list of IPs the machine went through
|
|
wget - Downloads file from internet
|
|
brctl, nmcli - Creates bridging between ports
|
|
Ctrl - U - Deletes command line
|
|
Ctrl - C - Aborts command
|
|
Ctrl - Z - Suspends command
|
|
fg - Resumes command after suspension
|
|
Ctrl - T - Fix misspelled command
|
|
cal - Prints ASCII calendar
|
|
free - Displays amount of free and used memory in system
|
|
df - Reports file system disk space usage
|
|
lsblk - Reports information about block devices
|
|
fdisk - Manipulates disk partition table
|
|
Uname - Prints system information
|
|
top - Display and update sorted info about processes
|
|
uptime - Displays the amount of timed the machine has been running
|
|
useradd - Creates new user
|
|
passwd - Sets password for new user
|
|
userdel - Removes user
|
|
chsh --shell /bin/sh username - Changes shell
|
|
sudo grouped groupante - Creates group
|
|
chown - Changes owner
|
|
chgrp - Changes group
|
|
chmod - Changes permissions
|
|
chmod ug +x filename - Gives user and group permission to execute file
|
|
chmod 1777 filename - Sets all permissions and a sticky bit
|
|
smbpasswd - Sets server password
|
|
ls - Shows all files in current directory
|
|
ls -a - Shows all files including hidden files in current directory
|
|
pwd - Shows current directory (present working directory)
|
|
cd - Changes curent directory
|
|
pstree - Shows running processes as a tree
|
|
ps - Report a snapshot of current processes
|
|
cp - Copies files
|
|
cp filename newfilename - Creates new file with old file information
|
|
cp filename directory/ - Puts file into directory
|
|
mv - Moves files
|
|
mv filename directory/ - Moves file into directory
|
|
rm - Removes\deletes files
|
|
rm -r - Deletes directories
|
|
rm -r directory/ - Removes directory
|
|
rm -rf directory/ - Removes directory to oblivion
|
|
mkdir - Creates directories
|
|
echo - Moves data (e.g. moves text into a file)
|
|
echo text >> filename - Moves text into file
|
|
cat - Reads file text or concatenate files and print file text
|
|
touch - Creates any kind of file
|
|
tail - Outputs last part of files
|
|
less - Views files instead of opening them. Lets user scroll through
|
|
awk - Selects data and presents rows and columns in output
|
|
awk '{print $1,$2,$3}' filename - Prints first, second, third words of each line
|
|
sort - Sorts lines of text files
|
|
vi filename - Opens text editor for file. Hard to use
|
|
file filename - Gives information on file
|
|
more filename - Displays file contents (no scrolling)
|
|
grep "text" filename - Searches for text within file
|
|
find - Finds files
|
|
whoami - Prints current user
|
|
rmdir - Removes directories
|
|
du - Displays file space usage
|
|
yes - Displays the same line of text until interrupted
|
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.