๐
Shell
On this page
Bash-Oneliner
A collection of handy Bash One-Liners and terminal tricks for data processing and Linux system maintenance.
You Don't Need GUI
A curated list of commands to execute everyday tasks which might be tempted to do in GUI.
Help message for shell scripts
sh
#!/bin/bash###### my-script โ does one thing well###### Usage:### my-script <input> <output>###### Options:### <input> Input file to read.### <output> Output file to write. Use '-' for stdout.### -h Show this message.help() {sed -rn 's/^### ?//;T;p' "$0"}if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; thenhelpexit 1fiecho Hello World
Kill processes on port
sh
kill -9 $(lsof -t -i:"4004")
Delete a bunch of Github Repositories
sh
#!/bin/sh# Delete a bunch of GitHub reposnukem="repo1 repo2"user=""password_or_oauth_token=""for repo in $nukem; doecho "Deleting https://github.com/repos/$user/$repo"curl -v -u "$user:$password_or_oauth_token" -X DELETE \"https://api.github.com/repos/$user/$repo"done
Start Node Project With Multiple Stages
sh
#!/bin/bashCONFIG_PATH_DOMAIN=""TEMP_CONFIG_PATH="public/config/config-temp.json"case "$1" insbx) CONFIG_PATH_DOMAIN="sbx" ;;*) CONFIG_PATH_DOMAIN="test" ;;esacCONFIG_PATH="https://${CONFIG_PATH_DOMAIN}/config/config.json"echo "Download ${S1} Config ${CONFIG_PATH} successfully"mkdir -p public/config/ && curl -o ${TEMP_CONFIG_PATH} ${CONFIG_PATH}react-scripts start
Loop through all the files with a specific extension
Recursively add subfolders
- Simple example
sh
for i in `find . -name "*.java" -type f`; doecho "$i"done
- Advanced example
sh
for i in `find . -name "*.java" -type f`; do# Strip longest match of */ from startfilename="${fullpath##*/}"# Substring from 0 thru pos of filenamedir="${fullpath:0:${#fullpath}-${#filename}}"# Strip shortest match of . plus at least one non-dot char from endbase="${filename%.[^.]*}"# Substring from len of base thru endext="${filename:${#base}+1}"# If we have an extension and no base, it's really the baseif [[ -z "$base" && -n "$ext" ]]; thenbase=".$ext"ext=""fi# echo -e "$fullpath:\n\tdir : \"$dir\"\n\tbase = \"$base\"\n\text = \"$ext\""echo -e "$fullpath:\n\tdir: \$dir\\n\tbase: \$base\\n\text: $ext"done