Terminal commands cheatsheet

List of handful terminal commands: npm, terminal, and git commands.

LinkIconNPM commands

Check website performance

npx unlighthouse --site https://
pnpm dlx unlighthouse --site https://

Check node.js vulnerability

npx is-my-node-vulnerable

View latest version of a packcage

npm view [package-name@version] version 

View peerDepedencies of a npm package

npm info [package-name@version] peerDependencies

Check outdated npm packages

npm outdated

Delete all node_modules in your system

npx npkill

Check for npm compromises (audit)

npx npq install

LinkIconPython commands

Python environment manager.

Install Python version

pyenv install 3.12.2

List Python versions

pyenv versions

Set global default.

pyenv global 3.12.2

LinkIconTerminal commands

Send ouptut to a new file

command | head -n 10 > output.txt
 

Append to an existing file

command | head -n 10 >> output.txt

Delete recursively a specific file/folder in every folder under a directory

find ~/pr -type d -name "node_modules" -prune -exec rm -rf '{}' +

Find heavy files

find ./public -type f -exec du -h {} + | sort -rh | head -n 100

Generate a 32 length secret key. For db passwords or env variables passwords.

openssl rand -base64 32
# or
npx auth secret

RS256 secret

ssh-keygen -t rsa

Get Wifi password

security find-generic-password -wa "The Wifi Name"
security find-generic-password -wa "The Wifi Name" | pb copy # copy to clipboard

Delete history of downlaods store in the macos sql (even clean history in Chrome)

sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'

Get your IP address

ifconfig ne0 | grep inet

Open a server that can be accessed from any device

  • To access go to the url: http://[this-device-ip]:8000
python3 -m http.server 8000 --bind 0.0.0.0 

LinkIconGit commands

Rename locally old_branch branch to main branch

git branch -m old_branch main

Reflect changes on remote

git push --force origin main

Link local main branch with remoteorigin/main for push/pull (no need check out branch).

# git branch -u [remote] [local]
git branch -u origin/main main

Delete remote branch

git push origin --delete branch-name

Delete local branch

git branch -d my-branch

LinkIconMiscellaneous

ls -la    # List files and directories
pwd       # Current directory path
cd        # Change directory
tree      # Print folder structure as tree

LinkIconFiles and Directories

touch   # Create empty file
mkdir   # Create new directory
cp      # Copy files or directories
mv      # Move or rename files
rm      # Remove files
rmdir   # Remove directories

LinkIconRead Files

cat   # Show file content
less  # Visualize file page by page
head  # Show file first lines
tail  # Show file last lines

LinkIconFile Permissions

chmod # Change file permissions
chown # Change file owner
sudo  # Execute commands as admin

LinkIconFind Files

find  # Find files in directories
grep  # Find text in files

LinkIconNetwork Utils

ping  # Testing connection 
curl  # HTTP request
wget  # Download files from a URL (have to be installed in macos)

LinkIconSystem Process

top     # Show processes
ps      # List active processes 
kill    # Kill a process
df -h   # Show available space in disk
du -sh  # Show file and directories size
uptime  # Show the system time since powered on
clear   # Clear the terminal

LinkIconUtils

echo    # Print text in the terminal
history # Show command history
man     # Show command manual
nano    # Basic Text Editor
vim     # Advanced Text Editor