Skip to content

Instantly share code, notes, and snippets.

View ipan's full-sized avatar

Ivan Pan ipan

  • Thermo Fisher Scientific, Inc.
  • San Francisco, CA
View GitHub Profile
@ipan
ipan / bash-redirect.md
Last active March 29, 2018 05:30
bash redirect

bash redirect

Error redirect to /dev/null

  • 2>&-
  • 2>/dev/null
  • |&
  • &>/dev/null
  • >/dev/null 2>&1
@ipan
ipan / rev-list.md
Created March 29, 2018 05:19
git rev-list

git rev-list

get latest commits for given directory

git rev-list -1 --abbrev-commit HEAD -- <dir-name>/

list all objects in git repo

git rev-list --objects --all
@ipan
ipan / git-delete-history.sh
Created March 29, 2018 05:15
delete big files in git history
# delete files in history
git filter-branch --prune-empty \
--index-filter 'git rm -rf --cached \
--ignore-unmatch MY-BIG-DIRECTORY-OR-FILE' \
--tag-name-filter cat -- --all
@ipan
ipan / su.sh
Created January 25, 2018 13:26
switch to non-login users such as www-data #su #linux
# www-data is non-login user
sudo su -l www-data -s '/bin/bash'
@ipan
ipan / apt.md
Created January 18, 2018 01:24
disable and remove apt repo #apt #sed #linux

disable apt repo

sudo sed -i 's:^deb:#deb:' /etc/apt/sources.list

remove unwanted repo:

sed -i '/^#/d' sources.list
sed -i '/^deb-src/d' sources.list
sed -i '/backports/d' sources.list
@ipan
ipan / sed_mac.md
Created January 18, 2018 01:22
sed (Mac OS X / Darwin) #sed #mac #darwin

search and replace

sed -e 's:origin:github:' -i .orig .git/config

find all config

find . -name config -depth 1 -exec sed -e 's:origin:github:' -i .orig {} \;
@ipan
ipan / nmap.md
Created January 18, 2018 01:01
nmap: useful options #nmap

nmap - port scanner

  1. scanning for open ports

nmap <machine-address>

  1. more verbose

nmap -v <machine-address>

@ipan
ipan / lvm.md
Last active January 18, 2018 01:00
extending existing LVM partition #lvm #unix #lvextend #resize2fs #vgdisplay #lvdisplay

The starting logical volume (vm) is 1TB. The volume group (data) has plenty of free space. This can be queried with lvdisplay.

The following command will extend the logical volume vm under volume group data by 4 TB

lvextend -L4T /dev/data/vm
resize2fs /dev/data/vm

Run vgdisplay to confirm:

@ipan
ipan / screen.md
Created January 18, 2018 00:48
screen or byobu scroll up and down #screen #byobu #scroll

scroll up and down

Ctrl-A [

This will activate copy mode in GNU/screen. Now, you can scroll up/down and look at your data. Use the following keys:

  1. Ctrl-u and Ctrl-d scroll the display up/down by the specified amount of lines while preserving the cursor position. (Default: half screen-full).
  2. Ctrl-b and Ctrl-f scroll the display up/down a full screen.
@ipan
ipan / swap.md
Created January 18, 2018 00:42
creating swap partition #unix #swap

creating swap

This is how to format swap partition

mkswap /dev/data/swap

shell output:

mkswap: /dev/data/swap: warning: don't erase bootbits sectors

on whole disk. Use -f to force.