Skip to content

stendarr/cheat-ba-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

cheat ba sheet

my personal cheat sheet for bash and related stuff

notice the lack of capitalization and punctuation? that's because it's all casual and not serious and stuff

chapter 0: what you should already know

cd, ls, mv, cp, mkdir, pwd, rm, cat, rmdir, touch, grep

linking files

symbolic link ln -s /path/to/file/that/exists /path/to/new/link

text/stream manipulation

strip the first 4 characters of each line (i.e. start on the 5th character):

cut -c 5- filename

get all the characters up to and including the 5th one: cut -c -5, get 3rd up to and including 15th: cut -c 3-15

follow the new lines being added to the file as it grows (e.g. logfiles):

tail -f filename

loops

numerical

for ((i = 0 ; i < 5 ; i++ )); do echo "$i"; done
0
1
2
3
4
for ((i = 0 ; i < 5 ; i++ )); do mkdir "year-202$i"; done

infinite

interruptible with ctrl+c

while :; do echo 'waiting'; sleep 1; done

while : is the same as while true

over filenames

all files/directories in current directory, non-recursive, leaves hidden files (dotfiles) untouched

for filename in *; do mv "${filename}" "${filename}-backup"; done

bash does not match dotfiles when globbing with *, however, this can be set with shopt -s dotglob and unset with shopt -u dotglob

to only do it for a single command you could

shopt -s dotglob; for filename in *; do mv "${filename}" "${filename}-backup"; done; shopt -u dotglob

for zsh use setopt

setopt GLOB_DOTS; for filename in *; do mv "${filename}" "${filename}-backup"; done; unsetopt GLOB_DOTS

About

cheat sheet for bash and related stuff

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published