<<

Common Commands Cheat Sheet by mmorykan via cheatography.com/89673/cs/20411/

Scripting Scripting (cont) GitHub bash filename - Runs script value - Forces the script to value git clone - Clones gitkeeper url Shebang - "#​ !bi​ n/b​ ash​ " - First line of bash seconds git add - Adds the to git script. Tells script what binary to use while [[ condition ]]; do stuff; done git commit - Commits all files to git ./fil​ename - Also runs script if [[ condition ]]; do stuff; fi git push - Pushes all git files to # - Creates a comment until [[ condition ]]; do stuff; done ${varia​ ble} - Prints variable words="​ h​ ouse dogs telephone dog" - Package / Networking hello_int = 1 - Treats "1​ " as a string Declares words array dnf upgrade - Updates system packages Use UPPER​CASE for constant variables for word in ${words} - traverses each dnf - Installs package element in array Use lowerc​ ase​ _wi​ th_​ und​ ers​ cores for dnf search - Searches for package for counter in {1..10} - Loops 10 times regular variables dnf remove - Removes package for ((;;)) - Is infinite for loop echo $(( ${hello​ _int} + 1 )) - Treats hello_int systemctl start - Starts systemd service as an integer and prints 2 break - exits loop body systemctl stop - Stops systemd service - Creates temporary random file for ((count​ er=1; counter -le 10; counter​ ++)) systemctl restart - Restarts systemd service - Denoted by "[[ condition ]]" tests the - Loops 10 times systemctl reload - Reloads systemd service condition ${arra​ y[I]} - Indexes array configu​ ration files bash -x - Prints commands and their ${arr​ay[]} - References the whole array. systemctl enable - Enable systemd service arguments Can also use @* boot -f - Copies the current shell in the fork declare -A array - declares associa​ tive systemctl disable - Disable systemd service value - Exits the script with value exit array systemctl status - Displays activity state code myassoc​ arr​ ay=​ ([a​ ppl​ e]=​ "red​ " [banana​ ]="​ ‐​ and some log lines of service -n varia​ ble - decides if variable is not yell​ ow"​ ) - Creates associa​ tive array atq - Displays currently scheduled empty ${mya​sso​car​ray​[ba​nana]} - References commands -z varia​ ble - Decides if variable is empty bananas value in the array at - Runs command once at certain unset array[I] - Deletes the I index $? - Stands for the previous exit code /day unset array - Deletes the array $# - Stands for the number of arguments atrm - Remove scheduled commands passed ${#arr​ ay} - Outputs the length of the array crontab -e - Create a file for scheduled [[ $# -ne 2 ]] - Evaluates to true if the ll = ' -l' - Creates the ll command as commands to run number of arguments is not equal to 2 an alias journ​alctl - Shows logs -f file​name - Determines if filen​ ame is a file home() { do stuff ; } Creates the home dmesg - Shows kernel messages, function -d dire​cto​ryN​ame - Determines if direc​ to‐​ hardware, driver, etc. ryNa​ me is a directory return - defaults to the previous exit value - Shows previous commands $1, $2, $3 - Refers to the first, second, and local - Creates local variable within function script - Records all input and writes it to a third arguments - Cuts away parts of the output file -eq - means == route - Configures IP connection -lt - Means < hostname - Sets system host name -le - Means <= netstat -rn - Gives routing table -gt - Means > - Outputs network interface -ge - Means >= ip addr - Shows different addresses and dirname - Prints directory name of of internet connect​ ions argument

By mmorykan Published 18th December, 2019. Sponsored by CrosswordCheats.com cheatography.com/mmorykan/ Last updated 28th January, 2020. Learn to solve cryptic crosswords! Page 1 of 2. http://crosswordcheats.com Common Commands Cheat Sheet by mmorykan via cheatography.com/89673/cs/20411/

Package / Networking (cont) User/Root Commands (cont) File and Directory Manipul​ ation (cont) tracer​ oute -I - Gives list of IPs the machine 1777 filename - Sets all permiss​ ions '{print $1,$2,$3}' filename - Prints first, went through and a sticky bit second, third words of each line wget - Downloads file from internet - Sorts lines of text files Samba brctl, nmcli - Creates bridging between filename - Opens text editor for file. Hard ports smbpas​ swd - Sets server password to use file filename - Gives informa​ tion on file Other Stuff File and Directory Manipul​ ation filename - Displays file contents (no Ctrl - U - Deletes command line ls - Shows all files in current directory scrolling) Ctrl - C - Aborts command ls -a - Shows all files including hidden files "t​ ext​ " filename - Searches for text in current directory Ctrl - Z - Suspends command within file - Shows current directory (present fg - Resumes command after suspension - Finds files working directory) Ctrl - T - Fix misspelled command - Prints current user - Changes curent directory - Prints ASCII calendar - Removes directo​ ries - Shows running processes as a - Displays file space usage System Informa​ tion ps - Report a snapshot of current processes - Displays the same line of text until free - Displays amount of free and used - Copies files interru​ pted memory in system cp filename newfile​ name - Creates new file - Reports file system disk space usage with old file informa​ tion lsblk - Reports informa​ tion about block cp filename directo​ ry/ - Puts file into devices directory fdisk - Manipul​ ates disk partition table - Moves files - Prints system informa​ tion mv filename direct​ory/ - Moves file into directory - Display and update sorted about processes - Removes​ \de​ letes files - Displays the amount of timed the rm -r - Deletes directo​ ries machine has been running rm -r directo​ ry/ - Removes directory rm -rf direct​ory/ - Removes directory to User/Root Commands oblivion useradd - Creates new user - Creates directo​ ries - Sets password for new user echo - Moves data (e.g. moves text into a userdel - Removes user file) --shell /bin/sh username - Changes echo text >> filename - Moves text into file shell - Reads file text or concate​ nate files and grouped groupante - Creates group print file text - Changes owner - Creates any kind of file - Changes group - Outputs last part of files chmod - Changes permiss​ ions - Views files instead of opening them. Lets user scroll through chmod ug +x filename - Gives user and group permission to execute file awk - Selects data and presents rows and columns in output

By mmorykan Published 18th December, 2019. Sponsored by CrosswordCheats.com cheatography.com/mmorykan/ Last updated 28th January, 2020. Learn to solve cryptic crosswords! Page 2 of 2. http://crosswordcheats.com