Created
August 17, 2021 14:34
-
-
Save x86-39/36f6a5b76d3d5dd1fdb694fc6b2a3a9f to your computer and use it in GitHub Desktop.
Useful bash/zsh functions
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
# Create a directory and enter it | |
# Usage: | |
# mkcd dirname | |
mkcd () | |
{ | |
mkdir -p -- "$1" && cd -P -- "$1" | |
} | |
# Resursively run sed on files | |
# Usage: | |
# rsed 's/foo/bar/g' dir1 dir2 file3 | |
rsed () | |
{ | |
find ${@:2} -type f -exec sed -i "$1" {} + | |
} | |
# Change file extension in bulk | |
# Usage: | |
# chext oldext newext file1 file2 file3 | |
chext () | |
{ | |
for f in ${@:3}; do | |
if [[ $f == *.${1} ]]; then mv -- "$f" "${f%.${1}}.${2}"; fi | |
done | |
} | |
# Run a command on (multiple) hosts | |
# Usage: | |
# sshc "ls -lah" host1 host2 | |
sshc () | |
{ | |
for host in ${@:2}; do | |
printf "\033[0;34mRunning on \033[0;31m${host}\033[0m\n"; | |
ssh -q -t $host "$1"; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment