Bash cheat sheet

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
You got guts Tiger! this is really helpful, detailing is amazing, Thanks buddy
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

pwd ~ view current directory
cd ~ move into a directory
.. ~ move up a directoryls ~ list what is in a directory
-a ~ hidden files and folders
-l ~ long listing, see more information
cat ~ see content of a file
-n ~ see content with line numbersless ~ see content of a file in editor
open ~ open files in the directory
touch ~ create files
mkdir ~ create folders
-p ~ create nested folders a/b/cecho ~ log string or write to file
> ~ write to file
>> ~ append at the end of file
rm ~ remove file or folder
-r ~ remove folder recursivelymv ~ used to move and rename files and folders
mv source/* target/ ~ move everything inside source to target foldercp ~ copy files and folders
cp -R source/* target/ ~ copy everything recursively from source to target folderfind ~ find files and folders
find images/ -name "*.png" ~ find files that end with png .
-iname ~ find files, but case insensitivefind . -type d -name "images" ~ find all folders in current directory with name images
-delete ~ flag to delete what was found
grep ~ search for text
grep "text" folder/file.js ~ search for text in whatever file
--color ~ search but colorize what we're looking for
-n ~ include the line numbers
-e ~ search but use regex
man grep ~ see all flags available
curl ~ make requests, by default GET
-i ~ inspect headers
-iL ~ inspect headers and follow redirect to see response
curl -iL "..."
-H ~ pass headers
curl -H "Authorization: ..."
-X ~ change the request method
curl -X POST -H "Content-Type: ..." -d '{ title: "Curling" }'
\ ~ to do things on new lines nicely formatted
curl -i -X PUT \
.sh ~ file has to end with this
chmod x+u ./file.sh ~ make file executable
$ ~ Accept arguments in your script. They will be passed in chronological order when running the script: ./file.sh argument1 argument2
$(<command>) ~ run commands inside the bash script
# ~ write comments in bash
var=value ~ set a variable's value for a session
echo $var ~ print the variable
unset var ~ unset the variable
export var ~ make the variable available to all child processes
Create and call a function in bash:
hi() {
echo "Hello world"
}
hi
Function with an argument passed:
hi() {
echo "$1 world"
}
hi "Hello"
Assign function's return statement to a variable:
hi() {
echo "$1 world"
}
hiResult=$(hi "Hello")
echo "the result from hi is $hiResult"
local ~ create local variables only available within the functionecho $? ~ see the exit status
0 for ok
1 for error
# Some conditional primaries that can be used in the if expression:
# =, != string (in)equality
# -eq, -ne numeric (in)equality
# -lt, -gt less/greater than
# -z check variable is not set
# -e check file/folder exists
# elif else if statement
if [[ $USER = 'naruto' ]]; then
echo "true"
else
echo "false"
fi
# Inline format, similar to ternaries
[[ $USER = 'naruto' ]] && echo "yes" || echo "no"
On Ubuntu, if you don't create the .bash_profile file, it will use the existing configuration file ~/.profile .
gitm="git add . && git commit -m 'commit'" ~ example of an alias
Items in the list of brackets.
touch index.js{,.backup} ~ create two files, index.js and index.js.backup , first item in the list is empty
mkdir -p packages/{pkg1,pkg2,pkg3}/src ~ create multiple packages inside packages folder, each containing src folder
echo {1..10} , echo {a..z} ~ print out ranges
You can use it for other things like creating multiple files
!! ~ run the previous commanddir=${1:-$PWD} ~ users would pass the directory as the first argument, but it defaults to the current directoryCtrl+A - go to the beginning of a line
Ctrl+E- go to the end of a line
Ctrl+K - clears line up to the cursor
Ctrl+W - delete last word
Ctrl+L - clear the screen (equivalent of the clear command)
Case statements, they can also be on multiple lines:
case "$1" in
firstValue) echo "firstValue matched";;
secondValue) echo "secondValue matched";;
thirdValue)
echo "thirdValue matched"
;;
esac