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 时间错误 默认启动项
sudo timedatectl set-local-rtc 1 #(或者可能是sudo hwclock --systohc --localtime)
ls -a /etc/grub.d/
sudo gedit /etc/default/grub
sudo update-grub
3. 电源优化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
官网下载.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
设置: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. 关闭购物建议
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)
“软件和更新”窗口,在其中点选“其他软件”选项卡,勾选其中的“Canonical 合作伙伴”选项
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,标记以便安装,应用。
然后搜索browser-plugin-freshplayer-pepperflash,标记以便安装,应用。
9. ubuntu如何安装下载工具uget+aria2
10. ubuntu下md5,SHA1校验
md5sum filename
sha1sum filena,e
11. 解决应用窗口工具菜单栏消失问题。
restart unity-panel-service
12. 安装常用软件
sudo apt-get install vim cmake git rar tmux mpv # (mpv 退出保存文档shift+Q)
13. 关闭开机自动打开蓝牙
- 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
## 创建共享目录:
mkdir /home/username/share
sudo chmod 777 /home/username/share
## 创建Samba配置文件:
# 保存现有的配置文件
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
# 修改现配置文件
sudo vi /etc/samba/smb.conf
# 在smb.conf最后添加
# [share]
# path = /home/username/share
# available = yes
# browseable = yes
# public = yes
# writable = yes
## 创建samba帐户
sudo touch /etc/samba/smbpasswd
sudo smbpasswd -a username
# 然后会要求你输入samba帐户的密码
## 重启samba服务器
sudo /etc/init.d/smbd restart
最后window我的电脑->右键->映射网络驱动器,在Folder处输入共享目录的路径,"\" + "Ubuntu机器的ip或主机名" + "\" + "share",点击完成,此时在就会在我的电脑里多出一个盘符。
19. 系统清理
sudo apt-get autoclean #(清理旧版本的软件缓存)
sudo apt-get clean #(清理所有软件缓存)
sudo apt-get autoremove #(删除系统不再使用的孤立软件)
20. Ubuntu 备份和恢复系统(!慎重)
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. 进入自己主目录,按ctrl+h.就能看见以点号开头的隐藏文件
25. ctrl+l 显示地址栏
gsettings set org.gnome.nautilus.preferences always-use-location-entry true
26. Matlab <wbr>不能保存修改的路径 <wbr>(Setpath)
一个解决办法是, 给 pathdef.m 文件读写的权限:
sudo chmod a+wr /opt/matlab/toolbox/local/pathdef.m
27. ~/.bash_history
28. 删除deinstall的内核,例如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三个文件夹即可恢复正常
31. &, ctrl+Z, bg, fg, jobs
- & 这个用在一个命令的最后,可以把这个命令放到后台执行
- ctrl+Z 可以将一个正在前台执行的命令放到后台,并且暂停
- jobs 查看当前有多少在后台运行的命令
- fg 将后台中的命令调至前台继续运行如果后台有多个命令,可以用fg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)
- bg 将一个在后台暂停的命令,变成继续执行如果后台有多个命令,可以用bg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)
32. linux中ctrl+z,ctrl+d和ctrl+c的区别
- ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程。常用于终止正在运行的程序。
- ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程。
- ctrl-d 不是发送信号,而是表示一个特殊的二进制值,表示 EOF。
- ctrl-\ 发送 SIGQUIT 信号给前台进程组中的所有进程,终止前台进程并生成 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中也没有相应设置选项,用ctrl-+和ctrl--可以实现放大和缩小,但重新打开help页面时字体又恢复了原来的大小。找到安装目录下相关配置文件即可更改页面比例的初始设置,D:\Program
Files\MATLAB\R2012b\help\includes\product\css\site5.css文件,更改文中的font-size后的62.5%为合适的数值即可。
/* 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,解压修改环境变量/etc/profile
- spark 2.2.0 -> scala 2.11.x (2.11.8)
- 启动spark-scala: spark-shell;启动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插件:注意点
- Project Structure: scala jdk spark
- pom.xml 修改scala版本
- Run -> Edit Configure -> VM options -> 加上参数 -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级别的日志打到控制台上。如果要显示全面的信息,则把INFO改为DEBUG。
如果希望一方面把代码中的println打印到控制台,另一方面又保留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的日志一方面打印到控制台,一方面写入到/home/Hadoop/spark.log中了,这是日志的继承特性,后面再来改进,目前把log4j.rootCategory=INFO, console,FILE改为log4j.rootCategory=INFO, FILE即可
36.2 第二种方法,通过log4j主动控制
可以通过log4j主动控制日志输出的级别。引入log4j.Logger和log4j.Level,并在对象中设置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. 开机自动挂载Windows分区
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 -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session
3. 进程 ps, kill
查看用户登录 who, w, last, last sc
当前系统资源查看 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
光标移动ctrl-o ctrl-i
撤销重做u ctrl-r
ctrl-g show location
[ctrl-s ctrl-q 流控制与恢复]
[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参数来垂直分屏。
vim -On file1 file2 ...
使用小写的o参数来水平分屏。
vim -on file1 file2 ...
:sp :vsp (ctrl-w hjkl)
5. GIT
GitHub, GitLab免密钥登录
生成公钥id_rsa.pub私钥id_rsa,粘贴公钥id_rsa.pub到GitHub或GitLab设置中
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对应与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
# 工作区与暂存区
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分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。)
git push origin master
git clone @github.com:yiglow/gitskills.git (for example)
6. touch
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。
7. postgresql + pgadmin
apt安装postgresql-9.5和图形管理工具pgadmin3
主程序
sudo apt install postgresql-9.5
数据库图形界面
sudo apt install pgadmin3
Ubuntu终端命令创建数据库
修改默认用户postgres的密码
postgres用户还没设置密码, 需要修改密码, 在终端输入
sudo -u postgres psql template1
继续输入
ALTER USER postgres with encrypted password 'your_password';
/q 退出
就修改好了, 重启postgresql
sudo systemctl restart postgresql.service
使用postgre官方的图形化管理工具pgadmin3
pgadmin3
点击左上角的插头图标(连接数据库)
输入如下参数:
属性 属性值
名称 随便
主机名 localhost
服务 空
维护数据库 postgres
用户 postgres
密码 你刚刚的密码
8. JDK
两种安装方式
- 直接到官网下载jdk解压然后设置环境变量
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,因为默认的JAVA_HOME为/usr/lib/jvm/default-java,执行
sudo R CMD javareconf JAVA_HOME=/usr/local/jdk1.8.0 // it depends
sudo su
install.packages(c('openssl',' Rmpfr','base64','Hmisc','HH'))