Skip to content

Instantly share code, notes, and snippets.

@alexlopes
Last active March 6, 2024 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlopes/91998166bab258c7dd467840447ccc08 to your computer and use it in GitHub Desktop.
Save alexlopes/91998166bab258c7dd467840447ccc08 to your computer and use it in GitHub Desktop.
Linux Tricks

Remove file with find asking confirmation

find . -iname "file.extension"  -exec rm -i {} \;

Remove/reduce git history packs

# https://help.github.com/articles/removing-sensitive-data-from-a-repository/
# http://www.ducea.com/2012/02/07/howto-completely-remove-a-file-from-git-history/

git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5

git rev-list --objects --all | grep <revision_id>

git filter-branch --index-filter 'git rm --cached --ignore-unmatch <filename>'

git update-ref -d refs/original/refs/heads/master

git commit --amend -CHEAD

git push

List RSS and Command with columns

ps -eo rss,cmd --sort -rss

How to create a patch file from diff

https://www.thegeekstuff.com/2014/12/patch-command-examples/

Common errors

No space left on device

df -ih

du --max-depth=1 | sort -n

Top 5

du -ah ./ | sort -n -r | head -n 5

Add timestamp to history command

zsh

setopt EXTENDED_HISTORY

history -i

Delete

find /opt/backup -type f -mtime +30 -delete 

List big files

# https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
sudo du -ah /dir/ | sort -n -r | head -n 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment