Skip to content

Instantly share code, notes, and snippets.

@regexyl
Last active April 8, 2022 01:35
Show Gist options
  • Save regexyl/11dda83275516c7ddad35c79e74c465f to your computer and use it in GitHub Desktop.
Save regexyl/11dda83275516c7ddad35c79e74c465f to your computer and use it in GitHub Desktop.
Linux/MacOS commands I use a lot
# ***** FILE SYSTEM *****
# Find paths of all files beginning with a regex in the current directory
find . -regex '.*/learn.*' -maxdepth 1
# Move all files matching the regex to a folder ./learn
# Warning: An error will appear but it's ok, all files except for ./learn itself are moved
# mv: rename ./learn to learn/learn: Invalid argument
mv $(find . -regex '.*/learn.*' -maxdepth 1) learn
# Delete folders matching name recursively under the current directory (#2)
# You could view the file paths that are going to be deleted with (#1)
find ./** -name '.git' -type d # (1)
find ./** -name '.git' -type d -exec rm -rf {} \; # (2)
# ***** PROCESSES *****
# Find the process running on port 3000
sudo lsof -i :3000
# Kill the port with <PID>
# PLEASE NOTE: -9 kills the process immediately, and gives it no chance
# of cleaning up after itself. This may cause problems. Consider using -15 (TERM)
# or -3 (QUIT) for a softer termination which allows the process to clean up after itself.
kill -9 <PID>
# Get CPU utilization
ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'
# ***** APPLICATION-SPECIFIC *****
# POSTGRESQL
# https://tableplus.com/blog/2018/10/how-to-start-stop-restart-postgresql-server.html
# To start manually
pg_ctl -D /usr/local/var/postgres start
# To stop manually
pg_ctl -D /usr/local/var/postgres stop
# To start PostgreSQL server now and relaunch at login
brew services start postgresql
# And stop PostgreSQL
brew services stop postgresql
# WATCH
# brew install watch
# Run any designated command at regular intervals (with x representing number of seconds).
watch -n x <your command>
# CURL
# TODO: Find out with curling /tar.gz/starter does + what `tar -xz --strip=1` is
curl https://codeload.github.com/howtographql/react-apollo/tar.gz/starter | tar -xz --strip=1 react-apollo-starter/server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment