-
Notifications
You must be signed in to change notification settings - Fork 1
bash
Bash and bash utils: how to do some stuff on the command line. Scripting, common utils, etc.
- GNU Readline
- renaming files
- finding files
- searching
- suspend and resume jobs
- zero pad
- loops
- diffing and patching
- converting images
- expansion and substituion
I never learned EMACS, so I never remember this stuff. But it's handy e.g. when you're trying to edit a line in IRC or something.
https://en.wikipedia.org/wiki/GNU_Readline
for file in *.png; do mv "$file" "${file/pattern/pattern}"; done
-
Find by file name/type:
find . -type f -name *.css -
Find by recently changed:
find . -type f -name *.vue -ctime -3
- Search .js, .jsx, .vue files, ignore case:
ag --js -i orderservice
-
C-zto suspend a job, like vim e.g. -
jobsto see suspended job -
fg %nto "foreground" a suspended job by its number. (Or justfgto resume the most recent job.)
change png to jpg or whatever as needed
#!/bin/bash
num=`echo $1 | sed -n 's/\([0-9]*\).png/\1/p'`
paddednum=`printf "%03d" $num`
echo ${paddednum}.pngTest it with ./zeropad.sh 1.png or whatever. When you're confident it works,
you can:
for i in *.jpg; do mv $i `./zeropad.sh $i`; donefor i in {1..5}
do
echo "Hello `printf "%03d" $i`"
doneCreate a patchfile:
diff -u original new > patchfileapply the patch:
patch < patchfileDiff two directories (optionally include -pN where N = depth):
diff -ru original/ new/ > patchfileReverse a diff
patch -R < patchfilemake some weird lo-res images:
convert img.png +dither -remap netscape: convert_img.png