zdb-doc Documentationzdb-doc Documentation, Release 1.13ubuntu 1.13.1ubuntu change grub boot order...
Transcript of zdb-doc Documentationzdb-doc Documentation, Release 1.13ubuntu 1.13.1ubuntu change grub boot order...
zdb-doc DocumentationRelease
zdb
May 13, 2016
Contents
1 Linux use and programming 3
2 Sphinx 9
3 Python Programming 11
4 Windows 15
5 Emacs 17
6 svn 19
7 scons 21
8 git 23
9 clojure 25
10 cygwin 29
11 Indices and tables 31
i
ii
zdb-doc Documentation, Release
Contents:
Contents 1
zdb-doc Documentation, Release
2 Contents
CHAPTER 1
Linux use and programming
1.1 show file last modified time
cmd is
stat -c %y file_name
1.2 how to add a user to sudoers list
edit file /etc/sudoers:
# User privilege specificationroot ALL=(ALL:ALL) ALLzdb ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command%sudo ALL=(ALL:ALL) ALL
1.3 add user on debian/ubuntu
in bash, run:
sudo useradd -m -U -s /bin/bash zdb
-m create home-M no create home-s login shell for the new user-U create a group with the same name as the user
1.4 remove user on debian/ubuntu
in bash, run:
userdel -r user_name
-r remove home directory
3
zdb-doc Documentation, Release
1.5 tar use
1.5.1 .tar.gz
extract:: tar zxvf FileName.tar.gz
compress:: tar zcvf FileName.tar.gz DirName
1.6 simple file encryption with openssl
encrypt a file:
openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc
decrypt a file:
openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
1.7 on server,use openssl to generate your key and cert file
use this:
$ openssl genrsa -out privkey.pem 2048$ openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
1.8 run as another user
if you are root , run this:
sudo -u username command
1.9 use sudo to redirect output in a command
just spawn another shell:
sudo sh -c 'ls -hal /root/ > /root/test.out'
1.10 transmission
1.10.1 transmission-cli
install transmission-cli:
$ sudo aptitude install transmission-cli
download:
4 Chapter 1. Linux use and programming
zdb-doc Documentation, Release
$ transmission-cli -u 40 -w ~/btd/ -er magnet_link/torrent_url
1.10.2 transmission-daemon
install and configure transmission-daemon:
$ sudo aptitude install transmission-daemon
$ sudo /etc/init.d/transmission-daemon stop
$ sudo vim /etc/transmission-daemon/settings.json
rpc-bind-address "127.0.0.1"upload-limit 40rpc-port 9092encryption 1rpc-usernamerpc-password
$ sudo /etc/init.d/transmission-daemon start
nginx config:
$ sudo vim /etc/nginx/conf.d/bt.conf
server {include conf.d/ssl;server_name foo.bar;
location / {include conf.d/reverse;
proxy_pass http://localhost:9092;}include conf.d/misc;
}
$ sudo vim /etc/nginx/conf.d/reverse
#proxy_pass_header Server;proxy_redirect off;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Scheme $scheme;proxy_set_header Host $host:$server_port;proxy_set_header X-Forwarded-Port $server_port;
$ sudo vim /etc/nginx/conf.d/ssl
listen 443 ssl;ssl_certificate /etc/ssl/cacert.pem;ssl_certificate_key /etc/ssl/privkey.pem;
1.10. transmission 5
zdb-doc Documentation, Release
1.11 rsync
1.11.1 rsync and ssh alias
if u have a ssh alias called linode, then sync files like this:
$ rsync -avzP ./client.py linode:/tmp/
1.11.2 use rsync to sync files(folder)
save this as ~/downmovie:
#!/bin/bashrsync --iconv=GBK,UTF-8 -s -LrtvzP -e ssh "[email protected]:/var/lib/transmission-daemon/downloads/$1" /cygdrive/d/movie/
# local windows gbk# remote linux utf-8# -L the contents in soft link# -s protected args
# $ chmod u+x /cygdrive/c/Users/zdb/Dropbox/Public/linux/bittorrent/transmission/downmovie# $ ln -s /cygdrive/c/Users/zdb/Dropbox/Public/linux/bittorrent/transmission/downmovie ~/downmovie# $ ~/downmovie "remote_folder"
1.12 lftp
configure ~/.ssh/config:
Host foo.barIdentityFile ~/.ssh/your_private_key
use lftp(sftp) download folder:
lftp -c "open sftp://[email protected];mirror -c -L -P 5 --use-pget-n=5 --loop '~/btd/remote_folder' /tmp/"
download file:
lftp -c "open sftp://[email protected];pget -c -n 5 '~/btd/remote_file_name' -o /tmp/local_name"
if downloaded file’s name has invalid character, then edit /etc/lftp.conf:
set file:charset "GBK" # this may not be set, local encoding, windows Chinese coding gbk will be OKset sftp:charset "UTF-8" # utf-8 will be OK in transfer
example:
lftp -c "set sftp:charset \"UTF-8\";open sftp://[email protected];pget -c -n 5 '~/btd/' -o /tmp/"lftp -c "set sftp:charset \"UTF-8\";open sftp://[email protected];pget -c -n 5 '~/btd/e™' -o /tmp/e™"lftp -c "open ftp://192.168.6.19;mirror -c -L -P 5 --use-pget-n=5 --loop 'E:/movie/Wreck-It.Ralph.2012.DVDRip.XviD-RiPS' /cygdrive/d/movie/"
6 Chapter 1. Linux use and programming
zdb-doc Documentation, Release
1.13 ubuntu
1.13.1 ubuntu change grub boot order
sudo vi /etc/default/grub
Change the number in GRUB_DEFAULT line. First boot menu is numbered 0. If it is 6th boot menu, type inGRUB_DEFAULT=5.
sudo update-grub
1.14 use vi shortcuts in terminal
http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal
To enable Vi-mode, edit (or create) the file ~/.inputrc or /etc/inputrc and add the following lines:
set editing-mode viset keymap vi-command
1.15 openvpn
aptitude install openvpn
cd /usr/share/doc/openvpn/examples/easy-rsa/2.0. ./vars./clean-all./build-ca./build-key-server server./build-key client./build-dhcd keysmv *.pem *.crt *.csr *.key /etc/openvpncd /usr/share/doc/openvpn/examples/sample-config-filesgunzip -c server.conf.gz > /etc/openvpn/server.conf
vim /etc/openvpn/server.confport 1194proto udp
cd /etc/openvpncp /usr/share/doc/openvpn/examples/sample-config-files/client.conf client.ovpnecho "set CLIENT_CERT 0" >> client.ovpnecho "<ca>" >> client.ovpncat ca.crt | grep -A 100 "BEGIN CERTIFICATE" | grep -B 100 "END CERTIFICATE" >> client.ovpnecho "</ca>" >> client.ovpnecho "<cert>" >> client.ovpncat client.crt | grep -A 100 "BEGIN CERTIFICATE" | grep -B 100 "END CERTIFICATE" >> client.ovpnecho "</cert>" >> client.ovpnecho "<key>" >> client.ovpncat client.key | grep -A 100 "BEGIN PRIVATE KEY" | grep -B 100 "END PRIVATE KEY" >> client.ovpnecho "</key>" >> client.ovpn
1.13. ubuntu 7
zdb-doc Documentation, Release
iptables -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPTiptables -A FORWARD -s 10.8.0.0/24 -o eth0 -j ACCEPTiptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forwardvim /etc/sysctl.confnet.ipv4.ip_forward=1
https://wiki.debian.org/OpenVPN#Debian_Server_with_Android_.2F_iOS_deviceshttps://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04https://play.google.com/store/apps/details?id=net.openvpn.openvpn
1.16 poor man rysnc
push files to server:
server:nc -l -p 38383 | openssl aes-128-cbc -d -k 'secret' | tar zxf -
client:tar czf - . | openssl aes-128-cbc -k 'secret' | nc dabin.info 38383
pull files from server: (needs server to send ctrl + c)
server:
tar czf - 'Kung Fu porn-461.mp4' | openssl aes-128-cbc -k 'secret' | nc -l -p 38383
client:
nc dabin.info 38383 | openssl aes-128-cbc -d -k 'secret' | pv | tar zvvxf
1.17 curl
# cookiecurl 'http://foo.baar' -H 'Cookie: cookie1=123;cookie2=456'
# postcurl -s -D - -d "client_name=web&pin_code=123456" http://foo.bar
8 Chapter 1. Linux use and programming
CHAPTER 2
Sphinx
2.1 use sphinx and rst to generate documents
http://raxcloud.blogspot.com/2013/02/documenting-python-code-using-sphinx.html ‘ http://sphinx-doc.org/markup/desc.html#info-field-lists < http://sphinx-doc.org/markup/desc.html#info-field-lists>‘_
only generate documents from rst files, not python files
first install sphinx:
$ pip install sphinx
use this python script to create a sphinx project:
from sphinx import quickstart as qs
d = dict(path = '.',sep = True,dot = '_',project = 'project_name',author = 'author_name',version = '',release = '',suffix = '.rst',master = 'index',epub = True,ext_autodoc = False,ext_viewcode = False,makefile = True,batchfile = True,mastertocmaxdepth = 1,
)
qs.generate(d, silent=True, overwrite=False)
2.2 set environment for Windows
so you can use make.bat:
9
zdb-doc Documentation, Release
@echo offset path=C:\Python27\Scripts;%path%cmd
save code above as set_sphinx.bat
10 Chapter 2. Sphinx
CHAPTER 3
Python Programming
3.1 Install pip on windows
download setuptools, uncompress and run python setup.py install
https://pypi.python.org/packages/source/s/setuptools/setuptools-1.1.7.tar.gz
download pip, uncompress and run python setup.py install
https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
3.2 python remote debug
3.2.1 python
http://shell909090.com/blog/2013/07/%E4%B8%80%E7%A7%8D%E6%96%B0%E7%9A%84python%E5%B1%80%E9%83%A8%E8%B0%83%E8%AF%95%E6%89%8B%E6%B3%95/
pythonpdbpdbpdb
__import__('pdb').set_trace()
console
import pdb, sockets = socket.socket()s.connect(('127.0.0.1', 8888))f = s.makefile()pdb.Pdb(stdin=f, stdout=f).set_trace()
nc
3.2.2 rpdb
install rpdb:
$ pip install rpdb
This is essentially a wrapper around pdb that will re-route stdin and stdout to a socket handler. By default it opens thedebugger on port 4444:
11
zdb-doc Documentation, Release
import rpdb; rpdb.set_trace()
connect to the console:
$ nc localhost 4444
3.2.3 rpd2
download winpdb
in foo.py:
import rpdb2; rpdb2.start_embedded_debugger('password')
connect:
$ python rpdb2.py -a -o localhost -p password foo.py
3.3 High-productivity software for complex networks
NetworkX is a Python language software package for the creation,
manipulation, and study of the structure, dynamics, and functions of complex networks.
install:
$ pip install networkx
code example:
import networkx as nx
G=nx.Graph()
G.add_edge('a','b',weight=2)G.add_edge('b','d',weight=3)G.add_edge('d','f',weight=1)G.add_edge('a','c',weight=1)G.add_edge('c','e',weight=1)G.add_edge('e','f',weight=1)
print nx.dijkstra_path(G, source='a', target='d')
# ['a', 'c', 'e', 'f', 'd']
'''b 3 d
2 1a f
1 1c 1 e
'''
12 Chapter 3. Python Programming
zdb-doc Documentation, Release
3.4 python logging module
verbose = Falselevel = logging.INFO if not verbose else logging.DEBUGlogging.basicConfig(format='[%(module)s][line %(lineno)d] %(asctime)s [%(levelname)s] %(message)s',\
datefmt='%m/%d/%Y %I:%M:%S %p',\level=level)
3.4. python logging module 13
zdb-doc Documentation, Release
14 Chapter 3. Python Programming
CHAPTER 4
Windows
4.1 Install Telnet Client by using a command line
On Windows 7, Windows Server 2008 R2, Windows Server 2008 or Windows Vista you can use the following com-mand line procedure to install Telnet Client.
1. Open a command prompt window. Click Start, type cmd in the Start Search box, and then press ENTER.
2. Type the following command:
pkgmgr /iu:"TelnetClient"
3. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and thenclick Continue.
4. When the command prompt appears again, the installation is complete
4.2 halt
save this as halt.bat in %SystemRoot% folder:
shutdown /s /t 0
4.3 Disables the hibernate feature
this is it:
powercfg -h off
15
zdb-doc Documentation, Release
16 Chapter 4. Windows
CHAPTER 5
Emacs
5.1 Installation of Emacs
5.1.1 windows instruction
download this http://ftp.gnu.org/gnu/emacs/windows/emacs-24.3-bin-i386.zip
unzip it to somewhere, I use C:\emacs-24.3
the default config folder is %appdata%, .emacs.d is here
run addpm.exe in bin folder to add shortcut to startmenu
add c:\emacs-24.3\bin to path
add file assocation:
set emacsbin=C:\emacs-24.3\bin\emacsclientwftype txtfile=%emacsbin% -na runemacs "%1"ftype EmacsLisp=%emacsbin% -na runemacs "%1"ftype CodeFile=%emacsbin% -na runemacs "%1"ftype Clojurescipt=%emacsbin% -na runemacs "%1"ftype wisp=%emacsbin% -na runemacs "%1"assoc .txt=txtfileassoc .text=txtfileassoc .log=txtfileassoc .el=EmacsLispassoc .c=CodeFileassoc .h=CodeFileassoc .=txtfileassoc .wisp=wispassoc .cljs=Clojurescipt
17
zdb-doc Documentation, Release
18 Chapter 5. Emacs
CHAPTER 6
svn
6.1 on windows use gvim to see slik svn diff
edit %appdata%Subversionconfig, add:
diff-cmd = c:\bin\svndiff.bat
this is c:\bin\svndiff.bat:
@ECHO OFF
REM Configure your favorite diff program here.SET DIFF=C:\PROGRA~1\Vim\vim74\gvim.exe -d
REM Subversion provides the paths we need as the sixth and seventhREM parameters.SET LEFT=%6SET RIGHT=%7
REM Call the diff command (change the following line to make sense forREM your merge program).%DIFF% %LEFT% %RIGHT%
REM Return an errorcode of 0 if no differences were detected, 1 if some were.REM Any other errorcode will be treated as fatal.
6.2 subversion roll back to some reversion
you can just use this:
svn updatesvn merge -r 150:140 .svn commit -m "Rolled back to r140"
19
zdb-doc Documentation, Release
20 Chapter 6. svn
CHAPTER 7
scons
7.1 install soncs with pip
on windows:
pip install --egg SCons
on Linux, after installing virtualenv, set a virtual python environment:
$ ~/your-virtualenv-folder/bin/pip install --egg SCons
21
zdb-doc Documentation, Release
22 Chapter 7. scons
CHAPTER 8
git
8.1 set up git server on debian
add git user:
$ sudo useradd -m -U -s `which git-shell` git$ sudo -u git mkdir /home/git/.ssh
add your public key to /home/git/.ssh/authorized_keys
8.2 set an empty repository on server
save the folloing as init_git_repo.sh:
cd /home/git/sudo -u git mkdir $1.gitcd /home/git/$1.git/sudo -u git git --bare init
then run:
sh init_git_repo.sh repo_name
8.3 pull push from multiple remote locations
add a self remote:
$ cd your_repo$ git remote add self [email protected]:/home/git/wynemo-man.git
edit your git config:
$ vi .git/config
add a all remote:
[remote "origin"]url = https://github.com/wynemo/man.gitfetch = +refs/heads/*:refs/remotes/origin/*
23
zdb-doc Documentation, Release
[remote "self"]url = [email protected]:/home/git/wynemo-man.gitfetch = +refs/heads/*:refs/remotes/self/*
[remote "all"]url = [email protected]:/home/git/wynemo-man.giturl = https://github.com/wynemo/man.git
then use this to push changes to all repo:
git push all master
8.4 git status not show untracked files
this is it:
git status -uno .
8.5 change remote url
git remote set-url origin [email protected]:wynemo/nemo_vim.git
8.6 submodule
8.6.1 add submodule
git submodule add https://github.com/sjl/gundo.vim.git bundle/gundogit add bundle/gundo .gitmodules
24 Chapter 8. git
CHAPTER 9
clojure
9.1 clojure tutorial
9.1.1 install openjdk
on linux:
$ sudo aptitude install openjdk-6-jdk
on windows, your need install oracle’s jdk
9.1.2 install lein
on linux or cygwin:
$ export HTTP_CLIENT="wget --no-check-certificate -O"$ mkdir -p ~/bin$ wget --no-check-certificate https://raw.github.com /technomancy/leiningen/stable/bin/lein$ cp lein ~/bin/$ chmod 755 ~/bin/lein$ lein version
on windows, download lein.bat, place it to C:
$ wget https://raw.github.com/technomancy/leiningen/stable/bin/lein.bat$ lein self-install
9.1.3 install node.js
on windows, place node.exe to C:\cygwin\home\zdb\bin
$ wget http://nodejs.org/dist/v0.10.26/node.exe
9.1.4 create a new clojurescript project
$ lein new cljs-helloworld$ cd cljs-helloworld
25
zdb-doc Documentation, Release
edit project.clj:
(defproject cljs-helloworld "1.0.0-SNAPSHOT":description "FIXME: write description":plugins [[lein-cljsbuild "1.0.1"]]:dependencies [[org.clojure/clojurescript "0.0-2138"] [org.clojure/clojure "1.5.1"]]:cljsbuild{:builds[{:source-paths ["src"],
:compiler{:pretty-print true, :target :nodejs, :optimizations :advanced}}]})
this will install lein-cljsbuild, clojurescript:
$ lein deps
rename core.clj:
$ mv src/hello_cljs/core.clj src/hello_cljs/core.cljs$ vi src/hello_cljs/core.cljs
edit core.cljs:
(ns hello-cljs.core)
(defn -main [& args](println (apply str (map [\space "world" "hello"] [2 0 1]))))
(set! *main-cli-fn* -main)
build:
lein cljsbuild once
run:
node target/cljsbuild-main.js
on windows run repl:
set NODE_PATH=C:\LightTable\plugins\node\node_modulesset path=c:;C:\cygwin\home\zdb\bin;%path%set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_51set path=%JAVA_HOME%\bin;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%path%set CLASSPATH = ;.%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
lein repl
9.2 clojurescript development on windows
9.2.1 install lighttable
download lighttable
extract the zip on C:
26 Chapter 9. clojure
zdb-doc Documentation, Release
9.2.2 configure lighttable
change font to consolas and add line number
view - commands - Settings: Default behaviors
in :editor section:
(:lt.objs.style/font-settings consolas 11 1):lt.objs.editor/line-numbers
9.2.3 install npm
download latest npm.zip on http://nodejs.org/dist/
extract npm,zip to c:/LightTable/plugins/node/
now you can use npm in command line
9.3 use nodejs and clojurescript
9.3.1 create a new project
lein new red-rss
9.3.2 edit core.cljs
move src/core.clj to src/core.cljs
(ns red_rss.core(:require [cljs.nodejs :as node]))
(def express (node/require "express"))(def app (express))
(defn -main [& args](. app (get "/" (fn [req res]
(. res (send "hello world")))))(.log js/console (str "Express server started on port: " (.-port (.address (.listen app 3000))))))
(set! *main-cli-fn* -main)
9.3.3 edit project.clj
(defproject red-rss "1.0.0-SNAPSHOT":description "FIXME: write description":plugins [[lein-cljsbuild "1.0.2"]]:dependencies [[org.clojure/clojurescript "0.0-2173"] [org.clojure/clojure "1.5.1"] [org.bodil/cljs-noderepl "0.1.11"]]:cljsbuild{:builds[{:source-paths ["src"],
:compiler{:pretty-print true, :target :nodejs, :optimizations :simple}}]})
9.3. use nodejs and clojurescript 27
zdb-doc Documentation, Release
9.3.4 compile and run
$ lein deps$ lein cljsbuild once$ node target/cljsbuild-main.js
28 Chapter 9. clojure
CHAPTER 10
cygwin
10.1 sshd and cygwin
http://tsengf.blogspot.com/2011/06/installing-sshd-in-cygwin-on-windows-7.html
http://superuser.com/questions/110726/how-to-uninstall-reinstall-cygwin-to-use-the-sshd
10.1.1 install sshd service
$ ssh-host-config
Should privilege separation be used? (yes/no) yes
*** Info: Administrator privileges. Should this script attempt to create a
*** Query: new local account 'sshd'? (yes/no) yes
(Say "no" if it is already installed as a service) (yes/no) yes
Do you want to use a different name? (yes/no) no
Create new privileged user account 'cyg_server'? (yes/no) yes
*** Query: Please enter the password for user 'cyg_server':123
*** Query: Reenter:
10.1.2 start and test
net start sshdssh localhost
10.1.3 uninstall sshd service
delete LOCAL_MACHINE\SYSTEM\ControlSet001\services\sshdrun 'sc delete sshd'reboot
29
zdb-doc Documentation, Release
30 Chapter 10. cygwin
CHAPTER 11
Indices and tables
• genindex
• modindex
• search
31