Bash by Examples
Linux Commands In Structured Order with Detailed Reference
Find Locate
Hold Option + Click: to move cursor to destination position
CTRL+a jump to the beginning of line
CTRL+e jump to to the end of line
CTRL+w will delete a word backwards
CTRL+z pause a command
CTRL+l clear the screen
CTRL+d exit current shell
CTRL+R search
CTRL + F: Forward
CTRL + B: Backward
CTRL + N: Next line
CTRL + P: Prev line
CTRL + H: Backspace
CTRL + D: Delete
CTRL + A: Begining of line
CTRL + E: End of line
CTRL + K: Kill line
source ~/.bash_profile
. ~/.bash_profile
hash -r python # to tell bash to reset the "cached" location to the python executable
sudo apt-get update
sudo apt-get upgrade
cut -d: -f1 /etc/passwd # list all users
sudo useradd -m myuser # add user
sudo passwd myuser # change password
sudo usermod -s /bin/bash myuser
sudo userdel myuser #delete user
sudo chown -R node:node /home/node && \
chmod -R 777 /home/node
ps aux | grep java # print all process
ps axjf # a tree
top
kill -STOP PID # pause the process
kill -CONT PID # resume the process
find / -name file.look # file a file
// symbol link
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
ls | tee file # output both screen and file
# download file
wget http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.csv -O earthquakes.csv
curl -O https://storage.googleapis.com/cloud-training/archinfra/Example-billing
-export.csv // download
jps | grep Launcher # find process id
# Date
date -u +"%Y-%m-%dT%H:%M:%SZ" # iso date
date -u +"%Y%m%dT%H%M%SZ"
# Logs
tail -f catalina.out &
# Find ports in use
lsof -i tcp:3000
cat /proc/cpuinfo # os info
ssh [email protected]
ssh-add -K ~/.ssh/id_rsa # add key to agent
//copy files
scp -i shizzle-dev-eu.pem /Users/haivu/projects/shizzle/apn-dev-cert.pem [email protected]:/home/ec2-user
# generate hash
echo -n "foobar" | openssl dgst -sha256
#-md4, -md5, -ripemd160, -sha, -sha1, -sha224, -sha384, -sha512 or -whirlpool
openssl x509 -in keytool_crt.pem -inform pem -noout -text # show certificate
sh -x script.sh
tar -zxvf example.tgz
unzip -n JMeterPlugins-Standard-1.2.0.zip -d apache-jmeter-2.12
tar jxf yjp-2015-build-15062-linux.tar.bz2
http://www.cyberciti.biz/tips/linux-iptables-examples.html
# Clear
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Add
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
# Allow ip
iptables -A INPUT -p udp -m udp -s 175.45.118.9 -j ACCEPT
iptables -A OUTPUT -p udp -m udp -d 175.45.118.9 -j ACCEPT
# list
sudo iptables -t nat --line-numbers -n -L
# delete
sudo iptables -t nat -D PREROUTING 2
netstat -s #
nicstat l
pidstat -t 1
awk
sed