Personnal collection of useful
bash
snippets.
!!
!$
alternatively, use ESC + .
CTRL + x, * will expand the last glob pattern:
$ rm * # ctrl + x, * $ rm fileA fileB fileC
use double quotes to allow variable to expand (single quote won't interpolate anything):
$ echo '$(date +%Y-%m-%d_%H-%M)' > $(date +%Y-%m-%d_%H-%M) $ echo "$(date +%Y-%m-%d_%H-%M)" > 2018-02-18_15-01
mkdir {folderA,folderB,folderC}
touch file_{0..10}.txt
for c in {H,E,L,L,O}; do echo $c; done
for i in {1..10}; do echo $i; done
for f in *.png; do echo $f; done
use
${f%%.*}
to print filename without extension:for f in *.png; do echo ${f%%.*}; done
ecco () { sleep 1; echo $1; }
# sequential
for i in {0..10}; do ecco $i; done
# parallel
for i in {0..10}; do ecco $i & done; wait
touch $(date +%Y-%m-%d_%H-%M).log
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
for f in {,**/}*.txt; do mv $f "${f/%.txt/.fr.txt}"; done
# Running dry
find * -type f -size -1024c -exec echo '{}' \;
# Actually deleting files
find * -type f -size -1024c -exec rm '{}' \;
See --size
in find(1)
using
svgo
:for f in *.svg; do svgo --input $f --pretty --enable={removeStyleElement,removeXMLNS,cleanupIDs}; mv $f ${f%%.*}.php; done
cat files.txt | xargs $@ <COMMAND>
using
imagemagick/mogrify
:mogrify -quality 85 -resize '1280>' *.JPG
using
imagemagick/density
:convert -units PixelsPerInch image-in-72-dpi.png -density 300 image-in-300-dpi.png
using
histmatch
:for i in {8143..8370}; do histmatch -c gray DSCF8142.JPG DSCF$i.JPG norm/$i.JPG; done
using
ffmpeg
:ffmpeg -r 25 -pattern_type glob -i '*.JPG' -s hd1080 -vcodec libx264 timelapse.mp4
using
ffmpeg
:ffmpeg -i video.mp4 -ss 00:00:01.000 -vframes 1 cover.png
git ls-tree -r -z --name-only HEAD -- src/*.js | xargs -0 -n1 git blame --line-porcelain HEAD |grep "^author "|sort|uniq -c|sort -nr
git diff --name-only --relative
use
| xargs $@ <COMMAND>
to run a command against this list:git diff --name-only --relative | xargs $@ open
git ls-files -m --others --exclude-standard
use
| xargs $@ <COMMAND>
to run a command against this list:git ls-files -m --others --exclude-standard | xargs $@ open
# ... last commit
git diff --name-only HEAD HEAD~1 | cat
# ... latest release
git diff --name-only HEAD $(git describe --abbrev=0 --tags) | cat
# ... previous release
git diff --name-only HEAD $(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) | cat
using
current_branch
fromoh-my-zsh
:
git reset --hard origin/$(current_branch)
git checkout feature
git fetch origin
git rebase origin/master
In addition, see jlevy's the-art-of-command-line.