Skip to content

Instantly share code, notes, and snippets.

@ebarault
Last active October 7, 2017 17:48
Show Gist options
  • Save ebarault/c05145589cfc73817d225eb63a070197 to your computer and use it in GitHub Desktop.
Save ebarault/c05145589cfc73817d225eb63a070197 to your computer and use it in GitHub Desktop.
Shell cheat sheet
#stop all containers
#remove all containers
#remove all docker images
docker kill $(docker ps -q) && docker rm $(docker ps -a -q) && docker rmi $(docker images -q) -f
#remove all docker volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
#clear everything unused
docker ps -q | xargs -r docker stop
docker system purge -a
cf. https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

sort folders by size

du -sh /* | sort -h -r

pipe locate/find into rm

# sudo -s
locate foo | xargs rm

find pattern in files

grep -rnw '/path/to/somewhere/' -e 'pattern'
-r or -R is recursive,
-n is line number, and
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.

Along with these, --exclude, --include, --exclude-dir or --include-dir flags could be used for efficient searching:

This will only search through those files which have .c or .h extensions:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will exclude searching all the files ending with .o extension:
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

Just like exclude files, it's possible to exclude/include directories through --exclude-dir and --include-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment