Skip to content

Instantly share code, notes, and snippets.

View jmstfv's full-sized avatar
🤔
It is duct tape and bubble gum all the way down.

Jama jmstfv

🤔
It is duct tape and bubble gum all the way down.
View GitHub Profile
@jmstfv
jmstfv / find_dir.sh
Created February 17, 2020 19:05
Find a directory
# Find a directory (Linux/MacOS)
sudo find / -type d -name 'dirname'
@jmstfv
jmstfv / flush_dns_cache.sh
Last active March 3, 2020 06:26
Flush DNS cache on MacOS
# Flush DNS cache on MacOS (Yosemite and later)
sudo killall -HUP mDNSResponder
@jmstfv
jmstfv / chmod.sh
Created December 29, 2019 07:43
Recursively set file and folder permissions
# Recursively set directory and file permissions (replace $mydir with a target directory)
find $mydir -type d -exec chmod 755 {} \;
find $mydir -type f -exec chmod 644 {} \;
@jmstfv
jmstfv / kill.sh
Created December 26, 2019 07:18
Kill the process by the port number
# replace 4567 with a target port number of the process
# run lsof with sudo if the process was spawned by the root user
kill -9 $(lsof -ti tcp:4567)
@jmstfv
jmstfv / replace.sh
Last active November 5, 2019 18:31
Replace all occurrences of a string in any file on MacOS
# Replace all occurrences of a string in any file on MacOS
# Substitute "html" with a target file extension
# using find (built-in)
find . -name '*.html' -print0 | xargs -0 sed -i "" "s/replaceme/withthis/g"
# using fd (https://github.com/sharkdp/fd)
fd -e html --print0 | xargs -0 sed -i "" "s/replaceme/withthis/g"