Last active
October 19, 2021 12:33
-
-
Save chesio/61d7659a3a171dcb9de7f372e5f4fdc8 to your computer and use it in GitHub Desktop.
Useful Bash aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Working with shell | |
# - [r]e[m]ove [d]irectory | |
alias rmd='rm -rf' | |
# - [l]ist in [h]uman format | |
alias lh='ls -lh' | |
# - [l]ist [u]sage | |
alias lu='ls | xargs -d "\n" du -sh' | |
# - [l]ist [u]sage [s]orted | |
alias lus='ls | xargs -d "\n" du -sh | sort -hr' | |
# - list file counts per directory | |
alias lfc='find . -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" -type f | wc -l; done' | |
# - [less] with e[s] | |
alias lesss='less -S' | |
## curl and wget | |
# - show response headers | |
alias curl_headers='curl -s -I -X GET' | |
# alias curl_headers='curl -s -D - -o /dev/null' | |
# - get list of all URLs on the website excluding asset files | |
alias wget_spider="wget --spider -r https://www.hpe.at 2>&1 | grep '^--' | awk '{ print $3 }' | grep -v '\.\(css\|js\|png\|gif\|jpg\|jpeg\|webp\)$'" | |
## Git | |
# - reset local commits, stash the changes, pull from remote and reapply them from stash | |
alias reroll_local_commits='git reset --soft HEAD^ && git stash && git pull && git stash pop' | |
## NPM | |
# - list installed packages without dependencies (append -g to display globally installed packages) | |
alias npm_list_flat='npm list --depth=0' | |
## Working with text files | |
# - convert Windows line endings with Unix line endings [i]n place (= needs filename) | |
alias dos2unix='sed -i "s/\r//g"' | |
# - convert Windows line endings in specific text files (CSS, HTML, JS, PHP and TXT) in current directory | |
alias convert-line-endings="find . \( -name '*.css' -o -name '*.html' -o -name '*.js' -o -name '*.php' -o -name '*.txt' \) -type f -execdir sed -i 's/\r//g' '{}' +" | |
# - drop any lines that are visually empty (ie. have only tabs and spaces) | |
alias remove-empty-lines='sed "/^\s*$/d"' | |
# - drop any lines that are (truly) empty | |
alias remove-truly-empty-lines='sed "/^$/d"' | |
## Random utils | |
# - pseudo random string (append length parameter) | |
alias pseudorandomstring='< /dev/urandom tr -dc A-Z-a-z-0-9 | head -c' | |
## Syncing (and deploying) | |
# Sync a (git) repository | |
# Params: -[r]ecursive -preserve [t]imestamps -compre[z] -[v]erbose | |
# Also, exclude any hidden files and directories. | |
alias rsync_repo='rsync -rtzv --delete --delete-excluded --exclude=".*"' | |
# Deploy web (development to production) via rsync | |
# Note: add trailing slash to <src-dir> in order to sync directory contents rather than directory itself (adding trailing slash to <tgt-dir> makes no difference) | |
# Example: rsync_web ~/local/project_dir/ ~/remote/project_dir/web/ | |
# Params: -[r]ecursive -preserve sym[l]inks -preserve [t]imestamps -compre[z] -[v]erbose | |
alias rsync_web='rsync -rltzv --delete' | |
## Sysadmin | |
# Debian: list all services ([-] stopped or [+] running) | |
alias list_services='service --status-all' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment