Skip to content

Instantly share code, notes, and snippets.

@cristopher-rodrigues
Last active July 11, 2020 17:02
Show Gist options
  • Save cristopher-rodrigues/dcc70a9d77edf2bd1865 to your computer and use it in GitHub Desktop.
Save cristopher-rodrigues/dcc70a9d77edf2bd1865 to your computer and use it in GitHub Desktop.
SSH POWER BASH
SOUND WHEN GET A RESPONSE

ping -i 60 -a ADDRESS
S.O/HARD INFOS

gnu

uname -a   
grep flags /proc/cpuinfo
lscpu
sudo lshw -short
hwinfo --short

darwin

system_profiler
sysctl hw
SSH KEY TO ACCESS

  • Generate SSH KEY in client
ssh-keygen -t rsa
  • Copy the client .pub
cat ~/.ssh/id_rsa.pub
  • Paste in server
cat ~/.ssh/id_rsa.pub | ssh user@machine “mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys”  || ssh-copy-id user@host
  • Restart ssh service in server
/etc/init.d/ssh restart ||  service sshd restart
LIST PROCESSES

sudo lsof -i | grep LISTEN
FIND ANYTHING BY NAME

find . -name "name*"

just dir

find . -name "name*" -d

just last X day(s)

find . -mtime -2
FIND ANYTHING BY NAME AND EXEC REMOVE OR SOME THING LIKE

find . -name ".git*" -exec rm -r "{}" \;
DISK USED ON DIR OR FILE

du -hs *
ON USERS

who
w
COPY FILE/DIR OF ANOTHER PLACE

scp -r user@place:/file_or_dir /to/file_or_dir
FIND EXPRESSION ON FILE(S)

digits

grep -r '[0-9][0-9]' /dir && grep '[0-9][0-9]' /file

blank lines

grep -r '^$' /dir && grep '^$' /file

Foo foo FOO FoO..

grep -r '[fF][oO][oO]$' /dir && grep '[fF][oO][oO]$' /file
TUNNEL FROM PLACE-PORT TO YOUR PLACE-PORT

ssh -N -LX:localhost:Y machine YOUT LOCAL ON 80 TO 3000 http://localhost->http://localhost:3000

ssh -N -L3000:localhost:80 localhost
DIFF FILES

local

diff /foo /bar

external

ssh user@host cat /path/to/remotefile | diff /path/to/localfile –
LIST DETAILED INFO

ls -alh
WATCH FILE CONTINUOUSLY

tail -f /file
SEE X LAST LINES

tail -200 /file 
SEE X FIRST LINES

tail -200 /file
SYMLINK

ln -s /dir to-dir
LAST X LOGINS TO USER

last -20 user name-user
CREATE TAR FILES

tar -cvf output.tar /dirname || tar -cvf output.tar /dirname1 /dirname2 filename1 filename2 || tar -cvf output.tar /home/vivek/data /home/vivek/pictures /home/vivek/file.txt || tar -cvf /tmp/output.tar /home/vivek/data /home/vivek/pictures /home/vivek/file.txt
VIEW CONTENT TAR FILES

tar -tvf /tmp/data.tar
EXTRACT CONTENT TAR FILES

tar -xvf /tmp/data.tar || tar -xvf data-backup.tar resume.pdf || tar -xvf data-backup.tar pic1.jpg file1.doc foo.movf
  • c : Create a tar ball.
  • v : Verbose output (show progress).
  • f : Output tar ball archive file name.
  • x : Extract all files from archive.tar.
  • t : Display the contents (file list) of an archive.
SEE USED PARTITIONS

df
DIFF FILES

diff foo.txt bar.txt
SIZE DIR

du -h
USERS INFO

finger
SIMPLE MONIT TOP

top -l 1 -s 0 | awk ' /Processes/ || /PhysMem/ || /Load Avg/{print}'
DOWN

halt
shutdown -r now   
DOWN

halt
TEN LAST COMMANDS

history | tail -10
USER AGENT TEXT MODE ( ON MAC SEE: lynxlet )

lynx
SEE HOW MANY HOURS UP SYS

uptime
MATH CALCULATION

expr 1+1
SIMILAR WORDS

look car
4EVER PRINT

yes "Hello bich"
REVERSE FILE PRINT

tac file.txt
FIND PROCESS ON PORT

lsof -i :80
FIND PROCESS ON PORT AND KILL OR MORE

lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9 
ps auxwww | grep postgres
sudo launchctl list | grep post
sudo lsof -i -P | grep -i "listen"
netstat -lptu OR netstat -tln

find and kill specified proccess

ps -ef | pgrep -f "cypress" | xargs kill -9 # killall cypress
@cristopher-rodrigues
Copy link
Author

list used ports:

netstat -tulpn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment