NoteBook
PART I. Tips
[TOC]
0. 修改hosts和源文件
sudo gedit /etc/hosts # change hosts
sudo /etc/init.d/networking restart
sudo cp /etc/apt/sources.list /etc/apt/sources.list.save
sudo gedit /etc/apt/sources.list # change source
sudo apt-get update
sudo apt-get upgrade
1. chrome (not chromium)
2. ubuntu16和windows10 時(shí)間錯(cuò)誤 默認(rèn)啟動(dòng)項(xiàng)
sudo timedatectl set-local-rtc 1 #(或者可能是sudo hwclock --systohc --localtime)
ls -a /etc/grub.d/
sudo gedit /etc/default/grub
sudo update-grub
3. 電源優(yōu)化tlp
sudo add-apt-repository ppa:linrunner/tlp
sudo apt-get update
sudo apt-get install tlp tlp-rdw
sudo tlp start
4. Enable ‘Minimise on Click’ (ubuntu 16.04)
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ launcher-minimize-window true
5. 安裝sogou for linux
需要fcitx框架
im-config
官網(wǎng)下載.deb包安裝,重啟
配置Input Method Configuration,添加Sogou Pinyin
fcitx-config-gtk3
6. 安裝sublime text3
http://www.cnblogs.com/unflynaomi/archive/2016/07/25/5704293.html
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
插件:alignment,convertTOutf8,sublimeLinter,markdown preview
設(shè)置:preference -> settings
{
"auto_complete": true,
"auto_match_enabled": true,
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"default_encoding": "UTF-8",
"font_size": 14,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage"
],
"tab_size": 4,
"trim_trailing_white_space_on_save": true
}
7. 關(guān)閉購物建議
gsettings set com.canonical.Unity.Lenses disabled-scopes "['more_suggestions-amazon.scope', 'more_suggestions-u1ms.scope', 'more_suggestions-populartracks.scope', 'music-musicstore.scope', 'more_suggestions-ebay.scope', 'more_suggestions-ubuntushop.scope', 'more_suggestions-skimlinks.scope']"
# 刪除基本不帶的自帶軟件,刪除Amazon鏈接
# sudo apt-get --purge remove <programname> # 卸載程序和所有配置文件
# sudo apt-get remove <programname> # 只卸載程序,保留配置文件
sudo apt-get --purge remove totem empathy brasero simple-scan gnome-mahjongg aisleriot cheese webbrowser-app landscape-client-ui-install onboard unity-webapps-common gnome-mines rhythmbox
8. 安裝flash player for chrome(to be improved)
“軟件和更新”窗口,在其中點(diǎn)選“其他軟件”選項(xiàng)卡,勾選其中的“Canonical 合作伙伴”選項(xiàng)
sudo apt install adobe-flashplugin
http://zh.wikihow.com/%E5%9C%A8Ubuntu%E7%B3%BB%E7%BB%9F%E4%B8%8A%E5%AE%89%E8%A3%85Flash-Player
sudo apt-get install pepperflashplugin-nonfree
sudo update-pepperflashplugin-nonfree --instal
新立得搜索pepperflashplugin-nonfree,標(biāo)記以便安裝,應(yīng)用。
然后搜索browser-plugin-freshplayer-pepperflash,標(biāo)記以便安裝,應(yīng)用。
9. ubuntu如何安裝下載工具uget+aria2
10. ubuntu下md5,SHA1校驗(yàn)
md5sum filename
sha1sum filena,e
11. 解決應(yīng)用窗口工具菜單欄消失問題。
restart unity-panel-service
12. 安裝常用軟件
sudo apt-get install vim cmake git rar tmux mpv # (mpv 退出保存文檔shift+Q)
13. 關(guān)閉開機(jī)自動(dòng)打開藍(lán)牙
- Ctrl+Alt+t 打開終端
- 輸入: sudo gedit /etc/rc.local
- 在打開的文件最后找到“exit 0”這一句,在前面加一句,如下:
rfkill block bluetooth
exit 0 - 保存,重啟
14. ubuntu 安裝texlive+texmaker+font manager
sudo apt-get install texlive-full
sudo apt-get install texmaker
sudo apt-get install font-manager
================problem=================
picins.sty not found
========================================
15. 安裝指紋識別軟件 fingerprint-gui
sudo add-apt-repository ppa:fingerprint/fingerprint-gui
sudo apt-get update
sudo apt-get install fingerprint-gui policykit-1-fingerprint-gui
注銷然后再重新登錄
在“Dash Home”里查找“fingerprint-gui”,打開軟件,然后按提示初始化指紋
16. Decide Where App Menus Show Up
Go to ‘System Settings > Appearance’
Select the ‘Behavior’ tab
Find the section headed: ‘Show the Menus for a Window’
Check (click) the circle next to ‘In the window’s title bar’
17. Move The Unity Launcher
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
gsettings set com.canonical.Unity.Launcher launcher-position Left
18. samba 共享目錄
## samba的安裝:
sudo apt-get install samba
sudo apt-get install cifs-utils
## 創(chuàng)建共享目錄:
mkdir /home/username/share
sudo chmod 777 /home/username/share
## 創(chuàng)建Samba配置文件:
# 保存現(xiàn)有的配置文件
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
# 修改現(xiàn)配置文件
sudo vi /etc/samba/smb.conf
# 在smb.conf最后添加
# [share]
# path = /home/username/share
# available = yes
# browseable = yes
# public = yes
# writable = yes
## 創(chuàng)建samba帳戶
sudo touch /etc/samba/smbpasswd
sudo smbpasswd -a username
# 然后會(huì)要求你輸入samba帳戶的密碼
## 重啟samba服務(wù)器
sudo /etc/init.d/smbd restart
最后window我的電腦->右鍵->映射網(wǎng)絡(luò)驅(qū)動(dòng)器,在Folder處輸入共享目錄的路徑,"\" + "Ubuntu機(jī)器的ip或主機(jī)名" + "\" + "share",點(diǎn)擊完成,此時(shí)在就會(huì)在我的電腦里多出一個(gè)盤符。
19. 系統(tǒng)清理
sudo apt-get autoclean #(清理舊版本的軟件緩存)
sudo apt-get clean #(清理所有軟件緩存)
sudo apt-get autoremove #(刪除系統(tǒng)不再使用的孤立軟件)
20. Ubuntu 備份和恢復(fù)系統(tǒng)(!慎重)
http://www.linuxidc.com/Linux/2014-01/94973.htm
http://wiki.ubuntu.org.cn/Ubuntu%E5%A4%87%E4%BB%BD%E4%B8%8E%E8%BF%98%E5%8E%9F#.E5.AE.8C.E5.85.A8.E5.A4.87.E4.BB.BD
sudo su
cd /
tar -czvPf /../backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/media / >/dev/null
(tar -czvPf /../backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/media / >/dev/null)
21. 安裝wine
22. 安裝Anaconda2
bash Anaconda-2.3.0-Linux-x86_64.sh
# 添加Anaconda Library Path
# 在/etc/ld.so.conf最后加入以下路徑
# /home/username/anaconda/lib
# 在~/.bashrc最后添加下邊路徑
# export LD_LIBRARY_PATH="/home/username/anaconda/lib:$LD_LIBRARY_PATH"
23. vim + gcc + gdb
24. 進(jìn)入自己主目錄,按ctrl+h.就能看見以點(diǎn)號開頭的隱藏文件
25. ctrl+l 顯示地址欄
gsettings set org.gnome.nautilus.preferences always-use-location-entry true
26. Matlab <wbr>不能保存修改的路徑 <wbr>(Setpath)
一個(gè)解決辦法是, 給 pathdef.m 文件讀寫的權(quán)限:
sudo chmod a+wr /opt/matlab/toolbox/local/pathdef.m
27. ~/.bash_history
28. 刪除deinstall的內(nèi)核,例如4.4.0-65
sudo dpkg -P linux-image-4.4.0-65-generic
sudo dpkg -P linux-image-extra-4.4.0-65-generic
29. ubuntuskills
http://wiki.ubuntu.org.cn/index.php?title=UbuntuSkills&variant=zh-cn
30. sogou for linux
sogou-qimpanel 崩潰
刪除~/.config目錄下的SogouPY、SogouPY.users、sogou-qimpanel三個(gè)文件夾即可恢復(fù)正常
31. &, ctrl+Z, bg, fg, jobs
- & 這個(gè)用在一個(gè)命令的最后,可以把這個(gè)命令放到后臺(tái)執(zhí)行
- ctrl+Z 可以將一個(gè)正在前臺(tái)執(zhí)行的命令放到后臺(tái),并且暫停
- jobs 查看當(dāng)前有多少在后臺(tái)運(yùn)行的命令
- fg 將后臺(tái)中的命令調(diào)至前臺(tái)繼續(xù)運(yùn)行如果后臺(tái)有多個(gè)命令,可以用fg %jobnumber將選中的命令調(diào)出,%jobnumber是通過jobs命令查到的后臺(tái)正在執(zhí)行的命令的序號(不是pid)
- bg 將一個(gè)在后臺(tái)暫停的命令,變成繼續(xù)執(zhí)行如果后臺(tái)有多個(gè)命令,可以用bg %jobnumber將選中的命令調(diào)出,%jobnumber是通過jobs命令查到的后臺(tái)正在執(zhí)行的命令的序號(不是pid)
32. linux中ctrl+z,ctrl+d和ctrl+c的區(qū)別
- ctrl-c 發(fā)送 SIGINT 信號給前臺(tái)進(jìn)程組中的所有進(jìn)程。常用于終止正在運(yùn)行的程序。
- ctrl-z 發(fā)送 SIGTSTP 信號給前臺(tái)進(jìn)程組中的所有進(jìn)程,常用于掛起一個(gè)進(jìn)程。
- ctrl-d 不是發(fā)送信號,而是表示一個(gè)特殊的二進(jìn)制值,表示 EOF。
- ctrl-\ 發(fā)送 SIGQUIT 信號給前臺(tái)進(jìn)程組中的所有進(jìn)程,終止前臺(tái)進(jìn)程并生成 core 文件。
Key Function - Ctrl-c Kill foreground process
- Ctrl-z Suspend foreground process
- Ctrl-d Terminate input, or exit shell
- Ctrl-s Suspend output
- Ctrl-q Resume output
- Ctrl-o Discard output
- Ctrl-l Clear screen
33. tmux KEY BINDINGS
tmux may be controlled from an attached client by using a key combination of a prefix key, ‘C-b’ (Ctrl-b) by default, followed by a command key.
C-b Send the prefix key (C-b) through to the application.
C-o Rotate the panes in the current window forwards.
C-z Suspend the tmux client.
! Break the current pane out of the window.
" Split the current pane into two, top and bottom.
## List all paste buffers
$ Rename the current session.
% Split the current pane into two, left and right.
& Kill the current window.
' Prompt for a window index to select.
( Switch the attached client to the previous session.
) Switch the attached client to the next session.
, Rename the current window.
- Delete the most recently copied buffer of text.
. Prompt for an index to move the current window.
0 to 9 Select windows 0 to 9.
: Enter the tmux command prompt.
; Move to the previously active pane.
= Choose which buffer to paste interactively from a list.
? List all key bindings.
D Choose a client to detach.
L Switch the attached client back to the last session.
[ Enter copy mode to copy text or view the history.
] Paste the most recently copied buffer of text.
c Create a new window.
d Detach the current client.
f Prompt to search for text in open windows.
i Display some information about the current window.
l Move to the previously selected window.
n Change to the next window.
o Select the next pane in the current window.
p Change to the previous window.
q Briefly display pane indexes.
r Force redraw of the attached client.
m Mark the current pane (see select-pane -m).
M Clear the marked pane.
s Select a new session for the attached client interactively.
t Show the time.
w Choose the current window interactively.
x Kill the current pane.
z Toggle zoom state of the current pane.
{ Swap the current pane with the previous pane.
} Swap the current pane with the next pane.
~ Show previous messages from tmux, if any.
Page Up Enter copy mode and scroll one page up.
Up, Down Left, Right
Change to the pane above, below, to the left, or to the right of the current pane.
M-1 to M-5
Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled.
Space Arrange the current window in the next preset layout.
M-n Move to the next window with a bell or activity marker.
M-o Rotate the panes in the current window backwards.
M-p Move to the previous window with a bell or activity marker.
C-Up, C-Down C-Left, C-Right
Resize the current pane in steps of one cell.
M-Up, M-Down M-Left, M-Right
Resize the current pane in steps of five cells.
34. Matlab help browser fonts
help中字體太小,不方便查閱,而preference>>font中也沒有相應(yīng)設(shè)置選項(xiàng),用ctrl-+和ctrl--可以實(shí)現(xiàn)放大和縮小,但重新打開help頁面時(shí)字體又恢復(fù)了原來的大小。找到安裝目錄下相關(guān)配置文件即可更改頁面比例的初始設(shè)置,D:\Program
Files\MATLAB\R2012b\help\includes\product\css\site5.css文件,更改文中的font-size后的62.5%為合適的數(shù)值即可。
/* Page Globals */
html { min-height:100%; margin-bottom:1px; }
html body { height:100%; padding:0px; margin:0px;
font-family:Arial, Helvetica, sans-serif;font-size:62.5%; color:#000; line-height:140%; background:#fff; overflow-y:scroll; }
html body td { vertical-align:top; text-align:left; }
img { border:none }
35. 本地模式 spark + scala + python + IntelliJ IDEA + maven
安裝jdk,scala,spark,解壓修改環(huán)境變量/etc/profile
- spark 2.2.0 -> scala 2.11.x (2.11.8)
- 啟動(dòng)spark-scala: spark-shell;啟動(dòng)spark-python: pyspark
- import pyspak 需要安裝py4j 或者把/usr/lib/spark/spark-2.2.0-bin-hadoop2.7/python/lib下的py4j-0.10.4-src.zip解壓到/usr/lib/spark/spark-2.2.0-bin-hadoop2.7/python
- IntelliJ IDEA + scala插件:注意點(diǎn)
- Project Structure: scala jdk spark
- pom.xml 修改scala版本
- Run -> Edit Configure -> VM options -> 加上參數(shù) -Dspark.master=local[4]
36. Spark的日志輸出
36.1 第一種方法,修改log4j.properties
# cd 到Spark的conf目錄下
sudo cp log4j.properties.template log4j.properties
sudo vim log4j.properties
把log4j.rootCategory=INFO, console改為log4j.rootCategory=WARN, console即可抑制Spark把INFO級別的日志打到控制臺(tái)上。如果要顯示全面的信息,則把INFO改為DEBUG。
如果希望一方面把代碼中的println打印到控制臺(tái),另一方面又保留spark 本身輸出的日志,可以將它輸出到日志文件中
log4j.rootCategory=INFO, console,FILE
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
# Settings to quiet third party logs that are too verbose
log4j.logger.org.eclipse.jetty=WARN
log4j.logger.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.Threshold=DEBUG
log4j.appender.FILE.file=/home/hadoop/spark.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%-5p] [%d{yyyy-MM-dd HH:mm:ss}] [%C{1}:%M:%L] %m%n
# spark
log4j.logger.org.apache.spark=INFO
上面的操作,spark的日志一方面打印到控制臺(tái),一方面寫入到/home/Hadoop/spark.log中了,這是日志的繼承特性,后面再來改進(jìn),目前把log4j.rootCategory=INFO, console,F(xiàn)ILE改為log4j.rootCategory=INFO, FILE即可
36.2 第二種方法,通過log4j主動(dòng)控制
可以通過log4j主動(dòng)控制日志輸出的級別。引入log4j.Logger和log4j.Level,并在對象中設(shè)置Logger.getLogger("org").setLevel(Level.ERROR)
import org.apache.log4j.{Level, Logger}
object Example {
Logger.getLogger("org").setLevel(Level.ERROR)
def main(args: Array[String]) {
......
}
}
37. 開機(jī)自動(dòng)掛載Windows分區(qū)
http://blog.csdn.net/GoDevelop/article/details/52314501?locationNum=2
PART II. Note
1. SSH login
ssh -p port username@ip
2. screen
screen -S yourname -> 新建一個(gè)叫yourname的session
screen -ls -> 列出當(dāng)前所有的session
screen -r yourname -> 回到y(tǒng)ourname這個(gè)session
screen -d yourname -> 遠(yuǎn)程detach某個(gè)session
screen -d -r yourname -> 結(jié)束當(dāng)前session并回到y(tǒng)ourname這個(gè)session
3. 進(jìn)程 ps, kill
查看用戶登錄 who, w, last, last sc
當(dāng)前系統(tǒng)資源查看 top
4. VIM
vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
修改配置文件 vim /etc/vim/vimrc # or ~/.vimrc
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)
set nu
set ai
set smartindent
set tabstop=4
set hlsearch
set incsearch
vimtutor
gg G 0
光標(biāo)移動(dòng)ctrl-o ctrl-i
撤銷重做u ctrl-r
ctrl-g show location
[ctrl-s ctrl-q 流控制與恢復(fù)]
[ctrl-z fg]
h kj lj
x delete the character
i insert
o open a line below the cursor and insert
a insert text after the cursor
A append
s delete a character and insertth
S delete a line and insert
w go to the start of the following [w]ord
b go to the [b]eginning of this word
e go to the [e]nd of this word
$ go to the [e]nd of this line
d delete
y copy
p paste
r replace
R replace more than one character
ce cw cb c$ change
/ ? search (n N)
Type % to find a matching ),], or }
Type :s/old/new/g to substitute 'new' for 'old'.
:%s/old/new/gc
:! execute the external command
使用大寫的O參數(shù)來垂直分屏。
vim -On file1 file2 ...
使用小寫的o參數(shù)來水平分屏。
vim -on file1 file2 ...
:sp :vsp (ctrl-w hjkl)
5. GIT
GitHub, GitLab免密鑰登錄
生成公鑰id_rsa.pub私鑰id_rsa,粘貼公鑰id_rsa.pub到GitHub或GitLab設(shè)置中
ssh-keygen -t rsa -C "youremail@example.com"
測試
ssh -T git@github.com
ssh -T git@gitlab.com
mkdir learngit
cd learngit
git init
git add readme.md
git rm readme.md (rm對應(yīng)與add)
git commit -m "wrote a readme file"
git status
git diff readme.md
git log (git log --pretty=oneline)
git reset --hard HEAD^
git reflog
git reset --hard b3705e8a93860146ca2cea1ff5e31405b8750637
# 工作區(qū)與暫存區(qū)
git checkout -- readme.md
echo "# learngit" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/yiflow/learngit.git
git push -u origin master #(第一次推送master分支時(shí),加上了-u參數(shù),Git不但會(huì)把本地的master分支內(nèi)容推送的遠(yuǎn)程新的master分支,還會(huì)把本地的master分支和遠(yuǎn)程的master分支關(guān)聯(lián)起來,在以后的推送或者拉取時(shí)就可以簡化命令。)
git push origin master
git clone @github.com:yiglow/gitskills.git (for example)
6. touch
linux的touch命令不常用,一般在使用make的時(shí)候可能會(huì)用到,用來修改文件時(shí)間戳,或者新建一個(gè)不存在的文件。
7. postgresql + pgadmin
apt安裝postgresql-9.5和圖形管理工具pgadmin3
主程序
sudo apt install postgresql-9.5
數(shù)據(jù)庫圖形界面
sudo apt install pgadmin3
Ubuntu終端命令創(chuàng)建數(shù)據(jù)庫
修改默認(rèn)用戶postgres的密碼
postgres用戶還沒設(shè)置密碼, 需要修改密碼, 在終端輸入
sudo -u postgres psql template1
繼續(xù)輸入
ALTER USER postgres with encrypted password 'your_password';
/q 退出
就修改好了, 重啟postgresql
sudo systemctl restart postgresql.service
使用postgre官方的圖形化管理工具pgadmin3
pgadmin3
點(diǎn)擊左上角的插頭圖標(biāo)(連接數(shù)據(jù)庫)
輸入如下參數(shù):
屬性 屬性值
名稱 隨便
主機(jī)名 localhost
服務(wù) 空
維護(hù)數(shù)據(jù)庫 postgres
用戶 postgres
密碼 你剛剛的密碼
8. JDK
兩種安裝方式
- 直接到官網(wǎng)下載jdk解壓然后設(shè)置環(huán)境變量
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- 添加PPA源 webupd8team/java(最好不要用如下的方式安裝)
# == oracle java jdk ppa source
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
# == JDK 8:
sudo apt-get install oracle-java8-installer
卸載第二種方法
sudo apt-get purge oracle-java8-installer
9. R + Rstudio
# == R
sudo gedit /etc/apt/sources.list
> deb http://cran.rstudio.com/bin/linux/ubuntu xenial/
# 下載公鑰
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9
# 然后更新一下
sudo apt-get update
sudo apt-get install r-base r-base-dev
# install.package('rJava')
找不到JAVA_HOME,因?yàn)槟J(rèn)的JAVA_HOME為/usr/lib/jvm/default-java,執(zhí)行
sudo R CMD javareconf JAVA_HOME=/usr/local/jdk1.8.0 // it depends
sudo su
install.packages(c('openssl',' Rmpfr','base64','Hmisc','HH'))