mirror of
https://github.com/denisidoro/navi
synced 2024-11-23 03:53:05 +00:00
248 lines
4.2 KiB
Text
248 lines
4.2 KiB
Text
|
|
|||
|
% 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 <index>
|
|||
|
|
|||
|
# Change group
|
|||
|
chgrp <group-name> <index>
|
|||
|
|
|||
|
% Shell WordPress Files/Folder Permissions
|
|||
|
|
|||
|
# Let apache be owner
|
|||
|
chown <www-data>:<www-data> -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 *.<txt>
|
|||
|
|
|||
|
# List all files of type
|
|||
|
find . -name *.<txt> -print
|
|||
|
|
|||
|
# Go back to previous directory
|
|||
|
cd -
|
|||
|
|
|||
|
# Make (empty) directory
|
|||
|
mkdir <dirname>
|
|||
|
|
|||
|
# Remove (empty) directory
|
|||
|
rmdir <sample-dirname>
|
|||
|
|
|||
|
# Remove directory with all contents without prompt
|
|||
|
rm -rf <sample-dirname>
|
|||
|
|
|||
|
# Remove directory contents and keep directory
|
|||
|
rm -rf *
|
|||
|
|
|||
|
# Checkout directory
|
|||
|
cd <sample-dirname>
|
|||
|
|
|||
|
% shell Symlinks
|
|||
|
|
|||
|
# Create symlink
|
|||
|
ln -s <source-dirname> <destination-dirname>
|
|||
|
|
|||
|
# Update symlink
|
|||
|
ln -sfn <source-dirname> <destination-dirname>
|
|||
|
|
|||
|
# Remove symlink
|
|||
|
unlink <sample-dirname>
|
|||
|
|
|||
|
% Shell Files
|
|||
|
|
|||
|
# Make (empty) file
|
|||
|
touch <filename-txt>
|
|||
|
|
|||
|
# Change creation date
|
|||
|
touch –t <yymmddhhmm> <filename>
|
|||
|
|
|||
|
# Change modified date
|
|||
|
touch –mt <yymmddhhmm> <filename>
|
|||
|
|
|||
|
# Duplicate file
|
|||
|
cp <filename-txt> <filename-copy-txt>
|
|||
|
|
|||
|
# Copy/Page folder with content
|
|||
|
cp -a <old-folder>/ <new-folder>
|
|||
|
|
|||
|
# Move/Rename file
|
|||
|
mv <current-filename-txt> <new-filename-txt>
|
|||
|
|
|||
|
# Move/Rename file and prompt before overwriting an existing file
|
|||
|
mv -i <current-filename-txt> <new-filename-txt>
|
|||
|
|
|||
|
# Remove file
|
|||
|
rm <filename-txt>
|
|||
|
|
|||
|
# View file
|
|||
|
less <filename-txt> / more <sample-filename-txt>
|
|||
|
|
|||
|
# Write to file (will overwrite existing content)
|
|||
|
cat > <filename-txt>
|
|||
|
|
|||
|
# Search for a filename-(not content!) in the current directory
|
|||
|
find <filename-txt>
|
|||
|
|
|||
|
# Search for a string inside all files in the current directory and subdrectories
|
|||
|
grep -r <string> *
|
|||
|
|
|||
|
# Search and replace within file
|
|||
|
sed -i 's/<original-text>/<new-text>/g' <filename-txt>
|
|||
|
|
|||
|
# MD5 hash for files
|
|||
|
md5 <filename-txt>
|
|||
|
|
|||
|
# MD5 hash for folders
|
|||
|
tar c <folder> | md5sum
|
|||
|
|
|||
|
# Encrypt file
|
|||
|
openssl enc -aes-256-cbc -e -in <sample-filename-txt -out <sample-encrypted-txt>
|
|||
|
|
|||
|
# Decrypt file
|
|||
|
openssl enc -aes-256-cbc -d -in <sample-encrypted> -out <sample-filename>
|
|||
|
|
|||
|
% Shell Server
|
|||
|
|
|||
|
# Access via ssh
|
|||
|
ssh <username@remote>
|
|||
|
|
|||
|
# Copy file from server to local
|
|||
|
scp <username@remote>:<file-to-send-path> <path-to-recieve>
|
|||
|
|
|||
|
# Copy file from local to server
|
|||
|
scp <file-to-end> <username@remote>:<where-to-put>
|
|||
|
|
|||
|
# Escape files with spaces in name like this
|
|||
|
<-path-to-file>\\\ <name-png>
|
|||
|
|
|||
|
% 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 <programme>
|
|||
|
|
|||
|
# Open finder with current folder
|
|||
|
open .
|
|||
|
|
|||
|
% Shell Variables
|
|||
|
|
|||
|
# Register variable
|
|||
|
export <TESTING>=<Sample-Text>
|
|||
|
|
|||
|
# Echo variable
|
|||
|
echo $<TESTING>
|
|||
|
|
|||
|
# Unset variable
|
|||
|
unset <TESTING>
|
|||
|
|
|||
|
% Shell Output & Redirects
|
|||
|
|
|||
|
# Write to file
|
|||
|
echo <Hello> > <hello-txt>
|
|||
|
|
|||
|
# Append content from a file to another file
|
|||
|
cat <file1-txt> >> <file2-txt>
|
|||
|
|
|||
|
# Add the amount of lines, words, and characters to <file2-txt>
|
|||
|
cat <file1-txt> | <word-count> | cat > <file2-txt>
|
|||
|
|
|||
|
# Sort the content of a file (like cat)
|
|||
|
sort <hello.txt>
|
|||
|
.txt
|
|||
|
# Save to sorted content to a new file
|
|||
|
cat <file1-txt> | sort > <sorted-file1-txt>
|
|||
|
|
|||
|
# Sort and remove duplicates and save to a new file
|
|||
|
sort <file1-txt> | uniq > <uniq-file1-txt>
|