From 73ca2d2e1fae246b749a731943bd8b78a08059b3 Mon Sep 17 00:00:00 2001 From: bajatin <43754300+bajatin@users.noreply.github.com> Date: Sun, 9 Feb 2020 18:44:11 +0530 Subject: [PATCH] Command line cheat sheet --- cheats/shell.cheat | 248 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 cheats/shell.cheat diff --git a/cheats/shell.cheat b/cheats/shell.cheat new file mode 100644 index 0000000..a85527d --- /dev/null +++ b/cheats/shell.cheat @@ -0,0 +1,248 @@ + +% Shell Usage + +# Re-call last input with sudo +sudo !! + +# Help +help cd / help dir (...) + +# Finding Help +apropos directory / apropos search (...) + +# Define custom startup screen +sudo nano /etc/motd + +# Run a script as background process +python script.py & + +# List all running process's +ps aux + +# Kill a running process +sudo kill <12345> + +% Shell System + +# Get the current path +pwd + +# Copy to clipboard +pwd | pbcopy + +# Paste +pbpaste + +# Get the current hostname +hostname + +# Get the current users +users + +# Get all info about the environment +env + +# Show calendar +cal + +# Show today's date +date + +# Exit terminal +exit + +% Shell Permissions + +# Use -R option to change permissions recursively. + +# List +ps -ef | grep apache | grep -v grep + +# Change permissions +chmod 755 + +# Change group +chgrp + +% Shell WordPress Files/Folder Permissions + +# Let apache be owner +chown : -R * + +# Change directory permissions rwxr-xr-x +find . -type d -exec chmod 755 {} \; + +# Change file permissions rw-r--r-- +find . -type f -exec chmod 644 {} \; + +% Shell Directories + +# List directory contents +ls + +# List all directory contents +ll + +# List all directory contents sorted by time edited +ls -alt + +# List directory (wildcard matching) +ls *. + +# List all files of type +find . -name *. -print + +# Go back to previous directory +cd - + +# Make (empty) directory +mkdir + +# Remove (empty) directory +rmdir + +# Remove directory with all contents without prompt +rm -rf + +# Remove directory contents and keep directory +rm -rf * + +# Checkout directory +cd + +% shell Symlinks + +# Create symlink +ln -s + +# Update symlink +ln -sfn + +# Remove symlink +unlink + +% Shell Files + +# Make (empty) file +touch + +# Change creation date +touch –t + +# Change modified date +touch –mt + +# Duplicate file +cp + +# Copy/Page folder with content +cp -a / + +# Move/Rename file +mv + +# Move/Rename file and prompt before overwriting an existing file +mv -i + +# Remove file +rm + +# View file +less / more + +# Write to file (will overwrite existing content) +cat > + +# Search for a filename-(not content!) in the current directory +find + +# Search for a string inside all files in the current directory and subdrectories +grep -r * + +# Search and replace within file +sed -i 's///g' + +# MD5 hash for files +md5 + +# MD5 hash for folders +tar c | md5sum + +# Encrypt file +openssl enc -aes-256-cbc -e -in + +# Decrypt file +openssl enc -aes-256-cbc -d -in -out + +% Shell Server + +# Access via ssh +ssh + +# Copy file from server to local +scp : + +# Copy file from local to server +scp : + +# Escape files with spaces in name like this +<-path-to-file>\\\ + +% Shell System + +# Show disc space +df -h + +# Show disc space (inodes) +df -i + +# Show disc space for current directory +du -hs + +# Current processes (also CPS usage) +top or htop + +# Show running php processes +ps aux | grep php + +# Monitor error log (stream as file grows) +tail error.log -f -n 0 + +% Shell Apps + +# Start appliction +open -a + +# Open finder with current folder +open . + +% Shell Variables + +# Register variable +export = + +# Echo variable +echo $ + +# Unset variable +unset + +% Shell Output & Redirects + +# Write to file +echo > + +# Append content from a file to another file +cat >> + +# Add the amount of lines, words, and characters to +cat | | cat > + +# Sort the content of a file (like cat) +sort +.txt +# Save to sorted content to a new file +cat | sort > + +# Sort and remove duplicates and save to a new file +sort | uniq > \ No newline at end of file