ubuntu setup

init Ubuntu OS
zh#选择最好的源
#add source list
#sudo gedit /etc/apt/sources.list
#ibus 源
#deb http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main
#deb-src http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main

#sudo apt-get install perl

#install openwebmail
#gedit /etc/apt/sources.list
#deb ftp://debian.tnc.edu.tw/pub1 b2d/
#sudo apt-get update
#sudo apt-get install openwebmail

#vnc
sudo apt-get install vnc-common vnc4server xvnc4viewer
#设置系统-》首选项-》安全-》允许远程&不需要确认
.vnc/xstartup 最后一行替换为 “gnome-session &”

sudo apt-get install openssh-server

#各种解码器,汉化包
#之前一定要在#System->Language Support->Chinese选上

#给apt设置代料 – In Tsinghua
#export http_proxy=http://netarch246:netarch@202.112.49.246:8080

#禁用pango
#sudo gedit /etc/environment
#MOZ_DISABLE_PANGO=”1″

#新建用户
#sudo adduser test1
#添加到某个组
#sudo gpasswd -a <账号> <组名>
#eg: sudo gpaswd -a admin test1

#要加入这几个组:adm (使用sudo) dialout (拨号) cdrom (使用光驱) plugdev (使用U盘等) lpadmin (使用打印机) admin (使用sudo) sambashare (使用samba共享) users (默认组)

#sudo gpasswd -a test1 adm

# 添加sudo用户
#还不属于别的组
#sudo usermod -G admin username
#已经属于别的组
#sudo usermod -a -G admin username

#安装ns2&nam 所需的软件包,需要重新编译nam,并将其nam执行文件移到bin目录下,并且需要安装g++

sudo apt-get install -f libxt-dev libxt6 libsm-dev libsm6 libice-dev libice6 libxmu-dev
#sudo apt-get install g++

#Trash place
$HOME/.local/share/Trash/

#firefox flash plugin
#http://get.adobe.com/flashplayer/thankyou/?installer=Flash_Player_10_for_Linux_(.deb)

#ibus
#sudo aptitude install ibus ibus-gtk
#在Ubuntu Tweak中启用iBus 1.2的源。
#在Ubuntu Tweak中安装ibus-pinyin。
#im-switch -c

#sudo aptitude remove ttf-mscorefonts-installer

#downthemAll, GooglePreview

#gftp 乱码
#sudo locale-gen zh_CN.GBK
#sudo gedit /usr/bin/gftp在#!/bin/sh之后加上export LANG=zh_CN.GBK
#在系统——首选项——主菜单里面找到gftp的菜单项,右键属性后发现其启动命令是gftp-gtk %u,果然与终端启动的命令不同
#于是我把这个启动命令改成gftp。然后重新从应用程序——互联网——gftp启动,果然问题解决了。

#让gedit默认打开编码为2312
#gconf-editor–>app–>gedit2–>preferences–>encodings 记入编码GB2312,
################################before install################################

#flash:
#sudo wget http://ubuntu:ubuntuftp@ftp.ubuntu.org.cn/home/dbzhang800/wiki/install_flash_player_10_linux.deb

#music player
sudo apt-get install audacious

#BT down software
#deluge

#LAMP: apache2 mysql php
sudo apt-get install apache2 mysql-server php5 php5-mysql php5-gd phpmyadmin
#php5-gd:phpmyadim

#tweak tool
sudo aptitude ubuntu-tweak

sudo apt-get install amule
sudo apt-get install vim

sudo apt-get install sqlite3

sudo apt-get install chmsee

sudo apt-get install wireshark

sudo apt-get install emacs

#文档生成工具
#sudo apt-get install doxygen

#sudo apt-get install qterm

#decoder
#sudo apt-get install ubuntu-restricted-extras

#压缩,解压
sudo apt-get install rar unrar
#解压缩
#tar -zxvf xxx.tar.gz
#压缩 tar -zcvf xxx.tar.gz aaa

#QQ
#sudo apt-get install eva
#sudo apt-get install scim-qtimm

#beryl,桌面效果软件
#sudo apt-get install beryl-core beryl-plugins beryl-plugins-data emerald beryl-settings beryl-manager beryl beryl-dev emerald-themes

sudo apt-get install conky
#这个软件有点高深~它的用途是,在桌面上显示自己配置好的一些系统信息,比如时间日期,IP,网络状况,内存和CPU的使用情况,硬盘容量这些内容,进行监控,查看。
#软件配置好,运行后,会定时的自动更新系统信息,让你第一时间更加了解系统当前的工作状态。

#安装pdf阅读,并解决中文乱码乱码问题
sudo ap-get
install xpdf
sudo apt-get install xpdf-chinese-simplified xpdf-chinese-traditional poppler-data

sudo apt-get install subversion

#选择java
#sudo apt-get install sun-java6-jre
#sudo apt-get install sun-java6-jdk

#安装python和django
sudo apt-get install python
sudo apt-cache search django
sudo apt-get install python-django
wget -q http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install mysql-python

#安装vnc
#sudo apt-get install vnc4server
#sudo apt-get install vnc4-common xvnc4viewer

#主题美化 gcursor:鼠标主题管理 gnome-art:gnome主题,需要联网 drapes:自动更换壁纸 screenlets:桌面小面板程序
sudo apt-get install gcursor gnome-art drapes ubuntustudio-look screenlets

#右键菜单
sudo apt-get install nautilus-open-terminal
#root权限打开文件夹
sudo apt-get install nautilus-gksu

sudo apt-get install eclipse-cdt eclipse eclipse-pydev

#c文档
sudo apt-get install manpages-dev
sudo apt-get install manpages-posix-dev
sudo apt-get install binutils-doc cpp-doc gcc-4.1-doc gcc-doc glibc-doc libstdc++6-4.1-doc stl-manual cpp-4.1-doc manpages manpages-dev

#vbox安装
sudo apt-get install virtualbox
#sudo mount -t vboxsf Documents /mnt/Documents

#sudo apt-get install sourcenav
#./snavigator
###################################after install###################################

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get remove
sudo apt-get autoremove

#set java config
#sudo update-alternatives-config java

linux

Diff:
echo “side-by-side display”
diff -y a.txt b.txt

echo “ignore case”
diff -yi a.txt b.txt

echo “ignore whitespace”
diff -yiw a.txt b.txt

echo “supress same line”
diff -yiw –suppress-common-line a.txt b.txt

内核版本
uname -r

ubuntu 版本号与名字
cat /etc/issue

 

useradd -m -G adm,root shock
-m 创建主目录
adduser shock sudo
把用户shock添加到sudo组
or visudo
add: shock ALL=(ALL) ALL (after root ALL=(ALL) ALL)

rsync -aXS /var/lib/docker/. /data/docker/ 同步文件

#! /bin/sh
get file dir:
sh file: LOCAL_DIR=$(cd $(dirname $0); pwd) (这个值不因为当前执行目录的改变而改变)
conf file: set $LOCAL_DIR = $(cd $(dirname $0); pwd)
rsync -e ‘ssh -p 30000’ -avl –delete –stats –progress –exclude ‘sources’ –exclude ‘public_html/database.txt’ demo@123.45.67.890:/home/demo /backup/

 

find . -type f -exec sed -i.orig ‘s/\t/ /g’ {} +

KEYWORD=iperf3
CMD=”iperf3 -s -p 5201 -d >> iperf3daemon.log 2>&1″
CMD2=”echo more than 1 ${KEYWORD} found”
/bin/sleep 10
/usr/bin/killall ${KEYWORD}
/bin/sleep 1
/usr/bin/killall -9 ${KEYWORD}
/bin/sleep 1
if [ `ps -C ${KEYWORD} | wc -l` -ge “1” ] ; then
if [ `ps -C ${KEYWORD} | wc -l` -gt “1” ] ; then
if [ `ps -C ${KEYWORD} | wc -l` = “1” ] ; then
${CMD}
else
${CMD2}
fi

 

pkill -f xxx.py

find . -type f -exec ls -l {} \;
find ./ -name “*.mp4” -exec ffprobe {} 2>&1 \;|grep h264|wc -l

ps aux | grep ffmpeg | awk ‘{print $2}’ | xargs kill -9

 

last command:
arrow up
!!
!-1
Ctrl-P

history to list all histor comands, then “!10” to execute the command with index 10
!ps to run the history command starting with “ps”

inherit the last parameters from last command:
vim !!:$
or specify the index (from 1) of parameter
vim !!:1

 

make with 8 threads:
make -j8

#auto-start app for ubuntu
sudo update-rc.d -f slapd remove

#check file size
du -sh FILE

# check the status of specific port, lsof stands for ls open files
sudo lsof -i:80
lsof -u shock
lsof -c /bin/vim # show all files opened by vim

# check status of all port
sudo lsof -Pn

# check all the connection
netstat -an

# check connection to specific IP
sudo lsof -Pn|grep IP
netstat -P (linux) or netstat -o (windows)

# copy
cp tmp.txt{,.bak}

# set hidden flag
chflags hidden FILE
chflags nohidden FILE

 

清单 7. 查找大于 10MB 的所有文件

$ find / -size +10000k –xdev –exec ls –lh {}\;

 

# find file with name
find ./ -name “*.cc”
find ./ -name “*.cc” -exec ls {} \; (\; is required at the end of the command line)

 

# grep recursively
grep “WORD” -r ./

grep -c “John” ./ (count number)
grep -v “John” ./ (does not contain John)

“:” as delimiter, keyword is the colum 3 as a integer (index start from 0)
sort -t: -u -k 3n /etc/passwrd
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts
# rank the output from shell
cat t.tmp | grep “^17” | sort -k 3 (ordered by colum 3) -n (odered by numberic) -u (no duplicate)

 

ls -l | awk ‘$6 == “Dec”‘
ls -l | awk ‘$5 = 686′

cut -d: -f 1,3 /etc/passwd
cut -d: -f 1-3 /etc/passwd (first 1-8 chars)

sed -i -e “s;/mysite/v2/user/;/user/;g” *.html

 

echo “side-by-side display”
diff -y a.txt b.txt

echo “ignore case”
diff -yi a.txt b.txt

echo “ignore whitespace”
diff -yiw a.txt b.txt

echo “supress same line”
diff -yiw –suppress-common-line a.txt b.txt

 

tar cvf a.tar ./a/
tar xvf a.tar
zip a.zip ./a/
unzip a.zip

# set python with port
port select –list python
port select -set python python 27

# shell hint message, in /etc/bashrc
PS1=’\h:\W \u\$’
PS2=”continue-> ”

#check the user of the directory or file
fuser -v .
fuser -vm tunnel.sh
ps auxf # show the process tree
ps U shock uxf

 

vmstat 1 100 #show system performance

nohup CMD & #run the command after logout
or nohup sh CMD > custom-out.log &

uname -a #show system info
df
du
# create account
sudo useradd -s /bin/bash -mr <USERNAME>
sudo adduser <USERNAME> sudo

type which whereis locate

 

grep -E ‘aaa|bbbb’

crontab时间格式范例
1-3表示123
1-9/2表示13579
crontab范例
每五分钟执行 */5 * * * *

每小时执行 0 * * * *

每天执行 0 0 * * *

每周执行 0 0 * * 0

每月执行 0 0 1 * *

每年执行 0 0 1 1 *SRC=/data/wwwroot/web/ #代码发布服务器目录

DST=/data/wwwroot/web/ #目标服务器目录
IP=”192.168.20.7″ #目标服务器IP,多个以空格隔开
USER=www
INOTIFY_EXCLUDE=”–fromfile /data/conf/shell/inotify_exclude.list”
RSYNC_EXCLUDE=”–include-from=/data/conf/shell/rsync_include.list –exclude-from=/data/conf/shell/rsync_exclude.list”

#su – $USER
inotifywait -mrq –exclude “(.swp|.inc|.svn|.rar|.tar.gz|.gz|.txt|.zip|.bak)” -e modify,delete,create,close_write,attrib $INOTIFY_EXCLUDE | while read D E F
do
for i in $IP
do
/usr/bin/rsync -e ‘ssh -p 5000’ -ahqzt $RSYNC_EXCLUDE –delete $SRC $USER@$i:$DST
done
done

 

inotify_exclude.list:
/tmp/inotify-test-dir
@/tmp/inotify-test-dir/cache

 

shell command:
#! /bin/sh
FILE_PATH=file.txt
DIR_PATH=dir
STR=0

if type python 2>/dev/null;
then
echo “yes”
else
echo “no”
fi

if [ -a ${FILE_PATH} ] ; then
echo “file: ${FILE_PATH} exists”
else
echo “file: ${FILE_PATH} does not exist”
fi

if [ -d ${DIR_PATH} ] ; then
echo “file: ${DIR_PATH} exists”
else
echo “file: ${DIR_PATH} does not exist”
fi

 

if [ “${STR}”x != “0”x ] ;
then
echo “not 0”
else
echo “be 0”
fi

 

ls

if [ ! $? -eq 0 ]; then
echo “last command executed successfully”
fi

function func_cmp() {
if [ $1 -eq 0 ] ; then
echo “equal 0”
else
echo “not equal 0″
fi
}

function func_add() {
a1=1
a2=10
a3=100
a4=-1
r1=$[$a1+-1]
r2=$[$a2+$a2]
r3=$[$a3+$a4]

echo $r1, $r2, $r3
}

function split_str() {
echo $1
tail -n 2 $1 | while read LINE
do
echo $LINE
done

OLD_IFS=”$IFS”
IFS=” ”
arr=($LINE)
IFS=”$OLD_IFS”
}