Skip to content

Instantly share code, notes, and snippets.

@whusnoopy
Last active January 3, 2016 08:39
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 whusnoopy/8437975 to your computer and use it in GitHub Desktop.
Save whusnoopy/8437975 to your computer and use it in GitHub Desktop.

安装配置部分

配网络

vi /etc/network/interface

interface (part):

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

# host-only
auto eth1
allow-hotplug eth1
iface eth1 inet static
    address 192.168.56.102
    netmask 255.255.255.0
    gateway 192.168.56.255

restart it

/etc/init.d/networking restart

修改区域

dpkg-reconfigure locales
locale-gen

时区

dpkg-reconfigure tzdata

升级

apt-get update
apt-get upgrade

添加新用户

adduser yewen

关闭不用的 getty

vi /etc/inittab

注释掉

#1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6

添加信任关系

vi ~/.ssh/authorized_keys

开 sudo 权限

apt-get install sudo
vi /etc/sudoers

sudoers (part):

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
yewen   ALL=(ALL:ALL) ALL

调整 PATH 一致

sudo vi /etc/profile

profile (part):

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
fi
export PATH

优化 bashrc

sudo vi ~/.bashrc

.bashrc (part)

# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

# more powerful grep
function search() {
    KEY_EXP="${1}"
    shift
    grep "${KEY_EXP}" --color="auto" --exclude-dir=".git" -Inr "${@:-.}" 2>"/dev/null"
    unset KEY_EXP
}

安装 vim 并修改 vimrc

sudo apt-get install vim
sudo vim /etc/vim/vimrc.local

vimrc.local (all):

set nocompatible " 非 vi 兼容模式
syntax on " 色彩高亮
set number " 显示行数
set ruler " 显示当前位置于右下角
set backspace=2 " 设置 backspace 模式为标准
set showmatch " 显示配对括号
set incsearch " 增量查找
set hlsearch
set ai " 智能缩进
set si " 智能缩进
set cindent " 智能缩进
set tabstop=4 " Tab 宽度
set softtabstop=4 " Tab 宽度
set shiftwidth=4 " Tab 宽度
set expandtab " 输入的 tab(\t) 均不保持为 tab 而转换为空格
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,sjis,euc-kr,ucs-2le,latin1 "字符编码
set encoding=utf-8
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] " 状态栏格式
set laststatus=2 " 一直显示状态栏
colorscheme torte " 256color-xterm 下的配色方案, 同 16 色下的 default

" 插入模式切换
map <F7> :set paste!<BAr>set paste?<CR>

" 多 Tab 时翻页
map <silent> <F6> :tabnext<CR>
imap <silent> <F6> <Esc>:tabnext<CR>gi

安装 markdown 语法高亮 http://www.vim.org/scripts/script.php?script_id=2882

vim markdown-<version>.vba.gz +":source % | quit"

python pip & virtualenv

install python-dev

sudo apt-get install python-dev

install

sudo apt-get install python-pip python-virtualenv

use virtualenv

virtualenv ve_ye
source ve_ye/bin/activate
deactivate

use pip

pip freeze > requirements.txt
pip install -r requirements.txt

svn & git

install:

sudo apt-get install subversion git

set vim as git editor

git config --global core.editor "vim"

git diff use vimdiff:

git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool

store git username/password

vim .git/config
url = https://username:password@gist.github.com/8437975.git

id_rsa.pub

ssh-keygen -t rsa -b 1024
cat ~/.ssh/id_rsa.pub

LEMP (nginx, mysql, php)

install

sudo apt-get install nginx php5 php5-fpm php5-curl php5-mysql mysql-server mysql-client

running

sudo nginx

reload config

sudo nginx -s reload

lrzsz

install

sudo apt-get install lrzsz

use

# upload from local to remote server
rz -bey

# download from remote server to local
sz -bey

sqlite

install

sudo apt-get install sqlite3

use

# open exists db or create a new db
sqlite3 local.db

# quit sqlite command line
sqlite> .q

screen

install

sudo apt-get install screen

config

vim ~/.screenrc

.screenrc

# see the startup message
startup_message off
term linux
# set a biger buffer
defscrollback 4096

# 设置状态栏
hardstatus alwayslastline
shelltitle "$|bash"

# a short version, can use C-a
hardstatus string '%{= kg}[%= %?%{kg}%-Lw%?%{Y}%n*%f %t%?(%u)%?%?%{kg}%+Lw%? %{kg} %=][%{kG} %Y/%m/%d %c %{g}]'

# shutdown the noise
vbell off

# w to show the window list
bind w windowlist -b
bind ^w windowlist -b

# initial apps to run
screen
screen
select 0

# 进行快捷键的绑定
bindkey -k k8 screen
bindkey -k k9 title
bindkey -k k; detach
bindkey -k F1 prev
bindkey -k F2 next

# unkonwn
attrcolor u "-u B"
autodetach on

use

# init a new screen session
screen -S scr_name

# use [^a] [Esc] to the copy mode
#    (as vim keys, h/j/k/l move, v select, y copy, q quit)

# use bindkey F8/F9 to new/rename a screen window
# use bindkey F10 to detach screen session
# use bindkey F11/F12 to switch screen windows

# restore an exists screen session
screen -r scr_name

# force detach a screen session and restore it
screen -r -D scr_name

# exit a screen session, repeat this to all screen windows
exit

tmux

install

sudo apt-get install tmux

config

vim ~/.tmux.conf

.tmux.conf

set -g default-terminal "screen-256color"

bind-key -n F8 new-window
bind-key -n F9 command-prompt 'rename-window %%'
bind-key -n F10 detach
bind-key -n F11 previous-window
bind-key -n F12 next-window

bind-key b send-prefix

set-window-option -g window-status-current-fg brightyellow
set -g status-right "#h %Y-%m-%d %H:%M"

use

# init a new tmux session
tmux new -s ss_name

# use "^b [" to the copy mode

# use bindkey F8/F9 to new/rename a tmux window
# use bindkey F10 to detach tmux session
# use bindkey F11/F12 to switch tmux windows

# restore an exists tmux session
tmux attach -t ss_name

# exit a tmux session, repeat this to all tmux windows
exit

技巧部分

shell 脚本里获取当前脚本所在绝对路径

script_dir="$(readlink -f $(dirname $0))"

Linux 下按时间查找并删除

sudo find . -mtime +7 -exec rm -f {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment