Skip to content

Instantly share code, notes, and snippets.

@ruandre
Last active Oct 5, 2021
Embed
What would you like to do?
Shell Tips
# mostly "notes to self" as I occasionally forget
# system info
uname -a
# search for a process
ps aux | grep [something]
# immediately terminate process
kill -9 [pid]
# cat gzip file
zcat [fileName.gz]
# -xvzf ~ extract, verbose, gzip, file
tar -xvzf [fileName.tar.gz]
# count words in file
wc -w [fileName]
# count lines (pipe into)
cat [fileName] | wc -l
# sort lines (pipe into)
cat [fileName] | sort
# ignore given directories
tree -I '.git|node_modules'
hostname # server domain
hostname -i # ip
hostname --fqdn # fully qualified domain name
whoami # username associated with current effective user id
whereis node # https://superuser.com/a/40304
ps aux | peco # https://github.com/peco/peco
diskonaut /home # https://github.com/imsnif/diskonaut
imgp -xp 1366x768 ~/Pictures # https://github.com/jarun/imgp
tldr man # simple man https://github.com/tldr-pages/tldr
aria2c [path] # downloads https://github.com/aria2/aria2
# delete specific folders recursively (node_modules in this case)
find . -name "node_modules" -type d -prune -exec rm -rfv '{}' +
# search file content
# -Rin ~ recursive, ignore case, line number (-l instead of -n for file name only)
# can also use --exclude=\*.jpg --include=\*.{css,html} --exclude-dir={dir1,dir2}
grep -Rin "text-to-find" --include=\*.js --exclude-dir={.git,node_modules} . # example
# copy file into subfolders (one level deep) https://askubuntu.com/a/300763
for d in */; do cp someFile.txt "$d"; done
# zip of latest commit on current branch
# excludes node_modules via .gitignore (for example)
git archive -o latest.zip HEAD
# available versions of npm package
npm view [packageName] versions
# in ~/.profile or ~/.bashrc for example:
# add to path (examples)
export PATH+=":$HOME/.local/bin"
export PATH="$HOME/.local/bin:$PATH"
# also https://github.com/tj/git-extras
alias g='git'
# ~/.gitconfig
[alias]
s = status
a = add . -A
m = commit
l = log
d = diff
p = pull
c = checkout
r = remote
b = branch -v
e = commit --amend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment