Skip to content

Instantly share code, notes, and snippets.

View schneefisch's full-sized avatar

Florian schneefisch

View GitHub Profile
@schneefisch
schneefisch / grep_snippets.sh
Last active September 27, 2020 17:36
search source IPs and occurrences from Apache access_log
# us awk to show the unique source-ips from access logs
awk '{ print $1 }' /var/log/*access*log | sort -n | uniq -c | sort -nr | head -20
# to use that on several compressed files:
gzip -dc /var/log/*access*.gz | awk '{ print $1 }' | sort -n | uniq -c | sort -nr
# to show only the most-occuring addresses:
gzip -dc /var/log/*access*.gz | awk '{ print $1 }' | sort -n | uniq -c | sort -nr | head -20
@schneefisch
schneefisch / zgrep_search.sh
Last active September 27, 2020 17:36
search in multiple compressed files with zgrep
#!/bin/bash
# grep over several zipped files
# in this case with with two search words "SEARCH1" OR "SEARCH2"
# it will also sort the entries and open them in "less" to view as a document
zgrep "SEARCH1\|SEARCH2" /application/logs/2019/03/app_*17.03.30*.gz|cut -d : -f 2-|sort --stable --key 1,1 |less
# E.G. search for "Exception
zgrep "Exception" /application/logs/2019/03/app_*17.05.*.gz|cut -d : -f 2-|sort --stable --key 1,1 |less
# to count the output lines, add following pipe at the end, instead of | less
@schneefisch
schneefisch / docker_basics.md
Last active September 21, 2022 08:13
Basic docker command line entries

This file contains basic commands for controlling docker

list running containers

docker ps

stop containers

docker stop <containerId>

docker kill

@schneefisch
schneefisch / git_graft.sh
Last active September 14, 2020 09:12
remove the history of a git-repo
# Case:
# The git-repo is enourmous an we want to drop a part of the history
# or, if we split a monolithic application, and the "new" application emerging from it should only have a few commits and not the whole history.
#
git checkout --orphan temp $1 # create a new branch without parent history
git commit -m "Truncated history" # create a first commit on this branch
git rebase --onto temp $1 master # now rebase the part of master branch that we want to keep onto this branch
git branch -D temp # delete the temp branch
# The following 2 commands are optional - they keep your git repo in good shape.
[user]
name = Florian Roeser
email = mail@dummy.org
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[web]
browser = google-chrome
[instaweb]
@schneefisch
schneefisch / git_move.md
Last active December 8, 2022 10:30
rebase and move a git commit

move last commit to new branch

this is when the last commit(s) have accidentially been committed to the wrong branch (i.e. master) but HAVE NOT been pushed

git branch newBranch
git reset --hard HEAD~2 # go back 2 commits, you will lose uncommited work
git checkout newBranch

Rebase

@schneefisch
schneefisch / git_new_remote.md
Last active October 14, 2022 11:22
Set a new remote URI for a git repo

Directly Set a Remote-URL if it does not yet have one

this git-command changes an existing remote repository URL

git remote set-url <https://github.com/USERNAME/REPO.git>

Migrate to a new Repository

If you want to move an existing git repo to a new remote location. First, checkout the required repo with all the branches you want to migrate

@schneefisch
schneefisch / git_remove_large_objects.md
Last active December 8, 2022 10:10
Remove large objects from repository and history

Git remove large objects from history

check the size of the git repo

du -hs .git/objects/

delete file using git filter-branch

git filter-branch --index-filter 'git rm --cached --ignore-unmatch pathname'
@schneefisch
schneefisch / git_stash.md
Last active December 8, 2022 10:07
Git stash help

Git Stash Manual

git stash list []
git stash show []
git stash drop [-q|--quiet] []
git stash ( pop | apply ) [--index] [-q|--quiet] []
git stash branch  []
git stash [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all] []]
git stash clear
@schneefisch
schneefisch / git_tag.md
Last active April 4, 2023 07:11
Basics for git tag

Tagging

checkout a specific tag

git co tags/1.5.0.0

fetch tags

git fetch --tags