Skip to content

Instantly share code, notes, and snippets.

@eddiejaoude
Last active October 7, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiejaoude/3081539 to your computer and use it in GitHub Desktop.
Save eddiejaoude/3081539 to your computer and use it in GitHub Desktop.
Linux
This gist contains notes/snippets
#bridge network connection
> sudo apt-get install bridge-utils
> sudo vim /etc/network/interface
# change eth0 to br0 & add bridge_ports eth0
eg.
auto eth0
iface eth0 inet dhcp
auto br0
iface br0 inet dhcp
bridge_ports eth0
# gateway
> route del default gw 192.168.1.3
> route add default gw 192.168.1.2
#!/bin/sh
FILE='consignment_latest_message2_delivery_date_dynamic'
SERVICE='php'
if ps ax | grep -v grep | grep $SERVICE | grep $FILE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
fi
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
> vim /etc/inittab
> find *.php -exec dos2unix {} \;
# single / multiple files
> dos2unix winfile.txt unixfile.txt
# recursive directory
> find . -type f -exec dos2unix {} +
> wget -r -Nc -mk [SITE-ADDRESS]
> chage -d 0 [USERNAME]
> find /path/to/files* -type f -name *.php
> find /path/to/files* -mtime +5
# Log matching results & action to file
> bash -c 'date;find /path/to/files* -mtime +5 -exec rm -v {} \;;date' > ~/mylog
# Run command on matching files
> find /path/to/files* -exec rm {} \;
# Delete all .svn files
# 1st: find, 2nd: rm
> rm -fr `find elements/ -type d -name .svn`
> find / -xdev -size +1000M - print | xargs ls -lS > /tmp/bigfiles.txt
NB:
xdev: prevents any mounted file systems being searched (apart from root)
ls -lS: S sorts by largest file first
> cd /path/to/my/existing/repo
> git remote add origin ssh://git@[DOMAIN]/[USER]/[PROJECT].git
> git push -u origin --all # to push up existing repo for the first time
# resize image with percentage
> mogrify -resize 25% images/
# resize image with pixel
> mogrify -resize 320x240 *.jpg
> killall *PROCESS NAME* // kill process by name
> killall -kill *PROCESS NAME* // if above does not work
> kill *PID* // kill process by procesor id
> kill -kill *PID* // if above does not work
# Running processes
ps // lists current terminal processes only
options:
-e // All or everyones processes
-all // same as above
-u *ACCOUNT NAME* // processes owned by a specified user (username or UID)
-f // display full information
-F // display extra full information - same as above plus more
> skill -KILL -t ptd/1
> skill -KILL -u local
# List all VMs
> virsh --connect qemu:///system list --all
# clone
> virt-clone -o [SOURCE_VM] -n [NEW_VM] -f /var/lib/libvirt/images/new-vm.img --connect=qemu:///system
# start vm
> virsh -c qemu:///system start vm_name
# auto start on boot
> virsh -c qemu:///system autostart vm_name
# shutdown vm
> virsh -c qemu:///system shutdown vm_name
# Update VM configuration via xml file
# output
virsh dumpxml build-01 > /tmp/build-01.xml
# input
> virsh define /tmp/build-01.xml
> qemu-img convert virtualbox.vmdk -O raw kvm.raw
# Generate md5sum list
> find . -type f -exec md5sum {} \; > /tmp/md5.list
# or
> find . -type f -name *.conf -exec md5sum {} \; > /tmp/md5.list
# check
> md5sum -c /tmp/md5.list
# or
> md5sum -c /tmp/md5.list | grep -v OK
1. Download mirror package
> sudo apt-get install apt-mirror
2. Configure mirror setup
> vim /etc/apt/mirror.list
3. Example mirror.list configuration (the repo list can be taken from your /etc/apt/resource.list file)
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
set mirror_path $base_path/mirror
set skel_path $base_path/skel
set var_path $base_path/var
set cleanscript $var_path/clean.sh
set defaultarch amd64
set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads 10
set _tilde 0
set limit_rate 100k
#
############# end config ##############
# deb cdrom:[Ubuntu 11.04 _Natty Narwhal_ - Release amd64 (20110427.1)]/ natty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ natty main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ natty-updates main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ natty universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty universe
deb http://gb.archive.ubuntu.com/ubuntu/ natty-updates universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://gb.archive.ubuntu.com/ubuntu/ natty multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ natty-updates multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ natty-updates multiverse
## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://gb.archive.ubuntu.com/ubuntu/ natty-backports main restricted universe multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ natty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu natty-security main restricted
deb-src http://security.ubuntu.com/ubuntu natty-security main restricted
deb http://security.ubuntu.com/ubuntu natty-security universe
deb-src http://security.ubuntu.com/ubuntu natty-security universe
deb http://security.ubuntu.com/ubuntu natty-security multiverse
deb-src http://security.ubuntu.com/ubuntu natty-security multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu natty partner
# deb-src http://archive.canonical.com/ubuntu natty partner
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu natty main
deb-src http://extras.ubuntu.com/ubuntu natty main
deb http://gb.archive.ubuntu.com/ubuntu/ natty-proposed restricted main multiverse universe
## Clean up
clean http://archive.ubuntu.com/ubuntu
clean http://extras.ubuntu.com/ubuntu
clean http://gb.archive.ubuntu.com/ubuntu/
clean http://security.ubuntu.com/ubuntu
4.Download packages for your mirror
> sudo apt-mirror /etc/apt/mirror.list
NB: Ubuntu 11.04 is about 67GB (64bit only)
> nmap -sP 192.168.2.1-255
# Overview
> cat /proc/mdstat
# Drive details
> mdadm -D /dev/md0
> mdadm -D /dev/md1
> mdadm -D /dev/md2
> mdadm -D /dev/md3
> rsync -av --progress --inplace --rsh='ssh -p8023' somefile user@host:somedir/
# kilobytes
--bwlimit 100
> sed -i 's/find/replace/g' someile.txt
# Extract lines 2 to 4
> sed -n 2,4p somefile.txt
> tar cvzf zipped_file.tgz directory/
> tcpdump tcp port 8080
NB: http://linux.byexamples.com/archives/283/simple-usage-of-tcpdump/
> history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10
> update-rc.d [service] defaults
> update-rc.d [service] remove
# If packages have been held back due to dependencies, it is possible to solve this by using the following command:
> sudo apt-get dist-upgrade
IP & Port range
> ufw allow 192.168.1.2 to any port 1000:2000
IP range
> ufw allow from 192.168.15.0/24
Initial setup
> ufw default deny incoming
> ufw default allow outgoing
Port
> ufw allow 1234
> ufw delete allow 1234
Port from IP
> ufw allow from <ipaddress> to any port <port number>
# within directory tags
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/json
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-var
/etc/vimrc.local
or
~/.vimrc
-----------------------------
" General
:set cursorline
:set number
:highlight CursorLine guibg=gray ctermbg=darkgray
:set spell
" Specifics
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
" Remember last position of file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment