From d6ba64e4b9bb4e5c1fcbc5b5dbd6e95bf38dafd6 Mon Sep 17 00:00:00 2001 From: Codyhintzch <40745418+Codyhintzch@users.noreply.github.com> Date: Fri, 14 May 2021 15:45:11 -0600 Subject: [PATCH] Added some basics commands and key combos Noticed there was some stuff missing that I consider good basics to use so I compared the cheat sheet with my own personal cheat sheet and added some stuff. I tried to stay basic enough that it stayed relevant to anybody doing bash stuff --- languages/bash.sh | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/languages/bash.sh b/languages/bash.sh index 13213f5..ea106d6 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -18,8 +18,9 @@ CTRL+M # same as RETURN CTRL+N # next line in command history CTRL+O # same as RETURN, then displays next line in history file CTRL+P # previous line in command history +CTRL+Q # resumes suspended shell output CTRL+R # searches backward -CTRL+S # searches forward +CTRL+S # searches forward or suspends shell output CTRL+T # transposes two characters CTRL+U # kills backward from point to the beginning of line CTRL+V # makes the next character typed verbatim @@ -38,6 +39,13 @@ ALT+U # capitalizes every character from the current cursor position to the en ALT+L # uncapitalizes every character from the current cursor position to the end of the word ALT+C # capitalizes the letter under the cursor. The cursor then moves to the end of the word. ALT+R # reverts any changes to a command you’ve pulled from your history if you’ve edited it. +ALT+? # list possible completions to what is typed +ALT+^ # expand line to most recent match from history + +CTRL+X then ( # start recording a keyboard macro +CTRL+X then ) # finish recording keyboard macro +CTRL+X then E # recall last recorded keyboard macro +CTRL+X then CTRL+E # invoke text editor (specified by $EDITOR) on current command line then execute resultes as shell commands BACKSPACE # deletes one character backward DELETE # deletes one character under cursor @@ -75,7 +83,11 @@ ls # lists your files in current directory, ls ls -l # lists your files in 'long format', which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified ls -a # lists all files in 'long format', including hidden files (name beginning with '.') ln -s # creates symbolic link to file +readlink # shows where a symbolic links points to +tree # show directories and subdirectories in easilly readable file tree +mc # terminal file explorer (alternative to ncdu) touch # creates or updates (edit) your file +mktemp -t # make a temp file in /tmp/ which is deleted at next boot (-d to make directory) cat # prints file raw content (will not be interpreted) any_command > # '>' is used to perform redirections, it will set any_command's stdout to file instead of "real stdout" (generally /dev/stdout) more # shows the first part of a file (move with space and type q to quit) @@ -90,6 +102,7 @@ diff # compares files, and shows where they differ wc # tells you how many lines, words and characters there are in a file. Use -lwc (lines, word, character) to ouput only 1 of those informations sort # sorts the contents of a text file line by line in alphabetical order, use -n for numeric sort and -r for reversing order. sort -t -k # sorts the contents on specific sort key field starting from 1, using the field separator t. +rev # reverse string characters (hello becomes olleh) chmod -options # lets you change the read, write, and execute permissions on your files (more infos: SUID, GUID) gzip # compresses files using gzip algorithm gunzip # uncompresses files compressed by gzip @@ -120,6 +133,7 @@ cd # changes directory cp -r # copy into including sub-directories pwd # tells you where you currently are cd ~ # changes to home. +cd - # changes to previous working directory ############################################################################## # SSH, SYSTEM INFO & NETWORK COMMANDS @@ -158,6 +172,8 @@ dig # gets DNS information for domain dig -x # reverses lookup host wget # downloads file +time # report time consumed by command execution + ############################################################################## # VARIABLES @@ -170,7 +186,9 @@ echo $varname # checks a variable's value echo $$ # prints process ID of the current shell echo $! # prints process ID of the most recently invoked background job echo $? # displays the exit status of the last command -read # reads a string from the input and assigns it to a variable +read # reads a string from the input and assigns it to a variable +read -p "prompt" # same as above but outputs a prompt to ask user for value +column -t # display info in pretty columns (often used with pipe) let = # performs mathematical calculation using operators like +, -, *, /, % export VARNAME=value # defines an environment variable (will be available in subprocesses) @@ -365,6 +383,8 @@ n<&m # file descriptor n is made to be a copy of the input file descriptor n>&- # closes the ouput from file descriptor n n<&- # closes the input from file descripor n +|tee # output command to both terminal and a file (-a to append to file) + ############################################################################## # PROCESS HANDLING @@ -402,6 +422,10 @@ trap - sig1 sig2 # resets the action taken when the signal is received to the disown # removes the process from the list of jobs wait # waits until all background jobs have finished +sleep # wait # of seconds before continuing + +pv # display progress bar for data handling commands. often used with pipe like |pv +yes # give yes response everytime an input is requested from script/process ############################################################################## @@ -462,7 +486,7 @@ trap returntrap RETURN # is executed each time a shell function or a script exe ############################################################################## # COLORS AND BACKGROUNDS ############################################################################## - +# note: \e or \x1B also work instead of \033 # Reset Color_Off='\033[0m' # Text Reset @@ -521,3 +545,4 @@ On_White='\033[47m' # White echo -e "${Green}This is GREEN text${Color_Off} and normal text" echo -e "${Red}${On_White}This is Red test on White background${Color_Off}" # option -e is mandatory, it enable interpretation of backslash escapes +printf "${Red} This is red \n"