Skip to content

Instantly share code, notes, and snippets.

@safizn
Last active December 25, 2017 05:47
Show Gist options
  • Save safizn/0427ba1e8622cc69349b733fc5994f8b to your computer and use it in GitHub Desktop.
Save safizn/0427ba1e8622cc69349b733fc5994f8b to your computer and use it in GitHub Desktop.
apt-get -y update && apt-get -y upgrade
# current working directory.
$(pwd)
# process status
ps aux
# show process of specific running task
ps aux | egrep '(apache|httpd)'
# restart
/sbin/reboot
# determine public IP
wget http://ipinfo.io/ip -qO -
# determine network IP
ifconfig
# ping every device on network
# 255.255.255.255 is a broadcast address, you are sending a ping to every device on your local network and you will get a reply from every device. The ping command is only showing the first reply it gets, in your case your own PC (127.0.0.1 is loopback) was the quickest.
ping 255.255.255.255 -b
# Measure time of running script by showing distribution information.
time … cat /etc/lsb-release
# List running processes.
ps auxf
# cURL transfer files from a given server url & then search with grep for sentence with the word.
curl localhost:8080 | grep STRING…
# get environment variable
env | grep variableName
# vim editor - esc then : then q! to quite without saving and wq to save
vi <file>
# Access as root user
sudo -i
su -
# Log in as different user
su - <username>
# send http requests for testing
openssl s_client -connect localhost:443
# copy with permissions:
cp -rp <source> <destination>
# move hidden file .htaccess
mv -v <source>/.[!.]* <destination>
# show dot files
ls -a | egrep '^\.'
# log checking real time live
tail -f <file>
# check mounts
mount
# or more readable
df -aTh
# reuse argument from last command:
mkdir x && cd $_
#show tree structure:
tree -I "./node_modules"
# list processes
ps ax
https://ubuntuforums.org/archive/index.php/t-2132978.html
curl -i <IP>/<routePath>
# send get request through unix socket:
curl --unix-socket /var/run/docker.sock http:/services | jq '.'
# send Post request
curl -XPOST -d \
'{ "Name": "go-demo-db", "TaskTemplate": { "ContainerSpec": {"Image": "mongo:3.2.10"} } }' \
--unix-socket /var/run/docker.sock http:/services/create | jq '.'
# send DELTE request through unix socket:
curl XDELETE --unix-socket /var/run/docker.sock http:/services/go-demo-db
# http://www.computerhope.com/unix/wget.htm
wget -q <address> -P <destinationDirectory>
# get values of specific column
awk '{print $<columnNumber>}'
# remove table titles
tail -n +2
# example :
$(docker service ps -f desired-state=running go-demo-db | tail -n 1 | awk '{print $4}')
export VARIABLE=x;
# Next command will have access to it.
# e.g. echo $VARIABLE;
# clear environment variables - Doesn't work
# removes all exported environment variables in bash or git bash. - messes up things.
env - /bin/bash
# IMPORTANT - when changing permissions of folders and users a restart of the SSH session must be made inorder to apply changes.
# REMEMBER - files permissions should allow group to read/write/execute even if its `root` group.
ls -ld <directory>
id <username>
groups <username>
# change default permissions for directories and files created
# direcotry 775, file 664 - default
umask 002
# direcotory 755, file 644
umask 022
# add to a group
sudo usermod -a -G <group> <username>
# change group
find <direcotry> -type d -exec chgrp -R <group> {} \;
find <direcotry> -type f -exec chgrp -R <group> {} \;
# change permissions
chmod -R g+rwx <direcotry>
find <directory> -type f -exec chmod -R g+rwx {} \;
find <directory> -type d -exec chmod -R g+rwx {} \;
find <directory> -type f -exec chmod -R 775 {} \;
find <directory> -type d -exec chmod -R 775 {} \;
# clone permissions from another file.
chown --reference=<otherFile> <targetFile>
# change owner and group:
chown -R <ownerUser>:<ownerGroup> <directory>
find <directory> -type f -exec chown -R <ownerUser>:<ownerGroup> {} \;
find <directory> -type d -exec chown -R <ownerUser>:<ownerGroup> {} \;
# "adm" is admin group (apparently).
find ./ -type f -exec chown 1000 {} \;
find ./ -type d -exec chown 1000 {} \;
# find also container process
ps -eaf
# delete process
kill <PID>
# Archive
tar -zcvf <filename>.tar.gz <destination>
# Extract
tar -xvzf <filename>.tar.gz
# extract to directory
tar -vxf <filename>.tar.gz -C <directory>
# install curl and wget.
tce-load -wi curl wget
# install jq - for formating JSON responses.
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
sudo mv jq-linux64 /usr/local/bin/jq
sudo chmod +x /usr/local/bin/jq
# https://superuser.com/questions/604998/monitor-tcp-traffic-on-specific-port
sudo tcpdump -i any port 80
https://shapeshed.com/unix-watch/
watch -d docker service ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment